Merge pull request #10735 from CasualPokePlayer/audio_dump_volume_fix

Have audio dumps apply volume
This commit is contained in:
JMC47 2022-06-13 17:09:58 -04:00 committed by GitHub
commit f96e91119a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 6 deletions

View File

@ -256,17 +256,25 @@ void Mixer::MixerFifo::PushSamples(const short* samples, unsigned int num_sample
void Mixer::PushSamples(const short* samples, unsigned int num_samples)
{
m_dma_mixer.PushSamples(samples, num_samples);
int sample_rate = m_dma_mixer.GetInputSampleRate();
if (m_log_dsp_audio)
m_wave_writer_dsp.AddStereoSamplesBE(samples, num_samples, sample_rate);
{
int sample_rate = m_dma_mixer.GetInputSampleRate();
auto volume = m_dma_mixer.GetVolume();
m_wave_writer_dsp.AddStereoSamplesBE(samples, num_samples, sample_rate, volume.first,
volume.second);
}
}
void Mixer::PushStreamingSamples(const short* samples, unsigned int num_samples)
{
m_streaming_mixer.PushSamples(samples, num_samples);
int sample_rate = m_streaming_mixer.GetInputSampleRate();
if (m_log_dtk_audio)
m_wave_writer_dtk.AddStereoSamplesBE(samples, num_samples, sample_rate);
{
int sample_rate = m_streaming_mixer.GetInputSampleRate();
auto volume = m_streaming_mixer.GetVolume();
m_wave_writer_dtk.AddStereoSamplesBE(samples, num_samples, sample_rate, volume.first,
volume.second);
}
}
void Mixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_samples,
@ -427,6 +435,11 @@ void Mixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume)
m_RVolume.store(rvolume + (rvolume >> 7));
}
std::pair<s32, s32> Mixer::MixerFifo::GetVolume() const
{
return std::make_pair(m_LVolume.load(), m_RVolume.load());
}
unsigned int Mixer::MixerFifo::AvailableSamples() const
{
unsigned int samples_in_fifo = ((m_indexW.load() - m_indexR.load()) & INDEX_MASK) / 2;

View File

@ -74,6 +74,7 @@ private:
void SetInputSampleRate(unsigned int rate);
unsigned int GetInputSampleRate() const;
void SetVolume(unsigned int lvolume, unsigned int rvolume);
std::pair<s32, s32> GetVolume() const;
unsigned int AvailableSamples() const;
private:

View File

@ -114,7 +114,8 @@ void WaveFileWriter::Write4(const char* ptr)
file.WriteBytes(ptr, 4);
}
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate)
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate,
int l_volume, int r_volume)
{
if (!file)
ERROR_LOG_FMT(AUDIO, "WaveFileWriter - file not open.");
@ -141,6 +142,10 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, int
// Flip the audio channels from RL to LR
conv_buffer[2 * i] = Common::swap16((u16)sample_data[2 * i + 1]);
conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]);
// Apply volume (volume ranges from 0 to 256)
conv_buffer[2 * i] = conv_buffer[2 * i] * l_volume / 256;
conv_buffer[2 * i + 1] = conv_buffer[2 * i + 1] * r_volume / 256;
}
if (sample_rate != current_sample_rate)

View File

@ -34,7 +34,8 @@ public:
void Stop();
void SetSkipSilence(bool skip) { skip_silence = skip; }
void AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate); // big endian
void AddStereoSamplesBE(const short* sample_data, u32 count, int sample_rate, int l_volume,
int r_volume); // big endian
u32 GetAudioSize() const { return audio_size; }
private: