diff options
| author | Chris Burgener <christhecoolist@gmail.com> | 2016-06-28 11:52:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-28 11:52:40 -0400 |
| commit | 41335752e57fbf18ec2339a84ce5080b2c5fe654 (patch) | |
| tree | 094b9f96af0abcdf67fcf929b6292e2b49d09c63 /Source/Core/AudioCommon/WaveFile.cpp | |
| parent | 28a3691e70ba2a1b37dbb58b22dfd35336c99a80 (diff) | |
| parent | ca2eaac704ba223c5d38bd0e2511e892d7db302a (diff) | |
Merge pull request #3891 from RisingFog/split_audio_dump_sample_rate
Split Audio Dumps on Sample Rate Changes
Diffstat (limited to 'Source/Core/AudioCommon/WaveFile.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/WaveFile.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
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; + } +} |
