From ca2eaac704ba223c5d38bd0e2511e892d7db302a Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Sat, 11 Jun 2016 18:52:45 -0400 Subject: Split Audio Dumps on Sample Rate Changes --- Source/Core/AudioCommon/WaveFile.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Source/Core/AudioCommon/WaveFile.cpp') diff --git a/Source/Core/AudioCommon/WaveFile.cpp b/Source/Core/AudioCommon/WaveFile.cpp index 96463158b7..3fb073f777 100644 --- a/Source/Core/AudioCommon/WaveFile.cpp +++ b/Source/Core/AudioCommon/WaveFile.cpp @@ -41,6 +41,11 @@ bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRa audio_size = 0; + if (basename.empty()) + SplitPath(filename, nullptr, &basename, nullptr); + + current_sample_rate = HLESampleRate; + // ----------------- // Write file header // ----------------- @@ -89,7 +94,7 @@ void WaveFileWriter::Write4(const char* ptr) file.WriteBytes(ptr, 4); } -void WaveFileWriter::AddStereoSamples(const short* sample_data, u32 count) +void WaveFileWriter::AddStereoSamples(const short* sample_data, u32 count, int sample_rate) { if (!file) PanicAlertT("WaveFileWriter - file not open."); @@ -108,11 +113,13 @@ void WaveFileWriter::AddStereoSamples(const short* sample_data, u32 count) return; } + CheckSampleRate(sample_rate); + file.WriteBytes(sample_data, count * 4); audio_size += count * 4; } -void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count) +void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate) { if (!file) PanicAlertT("WaveFileWriter - file not open."); @@ -141,6 +148,21 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count) conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]); } + CheckSampleRate(sample_rate); + file.WriteBytes(conv_buffer.data(), count * 4); audio_size += count * 4; } + +void WaveFileWriter::CheckSampleRate(int sample_rate) +{ + if (sample_rate != current_sample_rate) + { + Stop(); + file_index++; + std::stringstream filename; + filename << File::GetUserPath(D_DUMPAUDIO_IDX) << basename << file_index << ".wav"; + Start(filename.str(), sample_rate); + current_sample_rate = sample_rate; + } +} -- cgit v1.2.3