mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Do not directly store input sample rate, rather just store a divisor for that sample rate, with it using a fixed dividend of 54000000 * 2.
This should reduce (but not completely eliminate) gradual audio desyncs in dumps. This also allows for accurate sample rates for the GameCube. Completely eliminating gradual audio desyncs will require resampling to an integer sample rate, as nothing seems to support a non-integer sample rate.
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "AudioCommon/WaveFile.h"
|
||||
#include "AudioCommon/Mixer.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -26,7 +27,7 @@ WaveFileWriter::~WaveFileWriter()
|
||||
Stop();
|
||||
}
|
||||
|
||||
bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRate)
|
||||
bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
|
||||
{
|
||||
// Ask to delete file
|
||||
if (File::Exists(filename))
|
||||
@ -65,7 +66,7 @@ bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRa
|
||||
if (basename.empty())
|
||||
SplitPath(filename, nullptr, &basename, nullptr);
|
||||
|
||||
current_sample_rate = HLESampleRate;
|
||||
current_sample_rate_divisor = sample_rate_divisor;
|
||||
|
||||
// -----------------
|
||||
// Write file header
|
||||
@ -78,7 +79,7 @@ bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRa
|
||||
Write(16); // size of fmt block
|
||||
Write(0x00020001); // two channels, uncompressed
|
||||
|
||||
const u32 sample_rate = HLESampleRate;
|
||||
const u32 sample_rate = Mixer::FIXED_SAMPLE_RATE_DIVIDEND / sample_rate_divisor;
|
||||
Write(sample_rate);
|
||||
Write(sample_rate * 2 * 2); // two channels, 16bit
|
||||
|
||||
@ -114,8 +115,8 @@ void WaveFileWriter::Write4(const char* ptr)
|
||||
file.WriteBytes(ptr, 4);
|
||||
}
|
||||
|
||||
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate,
|
||||
int l_volume, int r_volume)
|
||||
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
|
||||
u32 sample_rate_divisor, int l_volume, int r_volume)
|
||||
{
|
||||
if (!file)
|
||||
ERROR_LOG_FMT(AUDIO, "WaveFileWriter - file not open.");
|
||||
@ -148,14 +149,14 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int
|
||||
conv_buffer[2 * i + 1] = conv_buffer[2 * i + 1] * r_volume / 256;
|
||||
}
|
||||
|
||||
if (sample_rate != current_sample_rate)
|
||||
if (sample_rate_divisor != current_sample_rate_divisor)
|
||||
{
|
||||
Stop();
|
||||
file_index++;
|
||||
std::ostringstream filename;
|
||||
filename << File::GetUserPath(D_DUMPAUDIO_IDX) << basename << file_index << ".wav";
|
||||
Start(filename.str(), sample_rate);
|
||||
current_sample_rate = sample_rate;
|
||||
Start(filename.str(), sample_rate_divisor);
|
||||
current_sample_rate_divisor = sample_rate_divisor;
|
||||
}
|
||||
|
||||
file.WriteBytes(conv_buffer.data(), count * 4);
|
||||
|
Reference in New Issue
Block a user