diff options
| author | CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> | 2022-07-03 15:07:06 -0700 |
|---|---|---|
| committer | CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> | 2022-07-03 15:07:06 -0700 |
| commit | 4234b25682ddfab6018c3c7bf410e568f527b1cd (patch) | |
| tree | ec9ee78467f670aae32ef740deefb7b9957857f6 /Source/Core/AudioCommon/WaveFile.cpp | |
| parent | edd89e343ca3a1ca8603af2b371d2767caa547b5 (diff) | |
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.
Diffstat (limited to 'Source/Core/AudioCommon/WaveFile.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/WaveFile.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Source/Core/AudioCommon/WaveFile.cpp b/Source/Core/AudioCommon/WaveFile.cpp index befcf6bfbd..dc689e74dd 100644 --- a/Source/Core/AudioCommon/WaveFile.cpp +++ b/Source/Core/AudioCommon/WaveFile.cpp @@ -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); |
