mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 07:21:14 +01:00
AudioStretcher: split StretchAudio into ProcessSamples / GetStretchedSamples
This commit is contained in:
parent
87a467fe42
commit
14c3d4716f
@ -2,7 +2,9 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include "AudioCommon/AudioStretcher.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
@ -27,8 +29,7 @@ void AudioStretcher::Clear()
|
||||
m_sound_touch.clear();
|
||||
}
|
||||
|
||||
void AudioStretcher::StretchAudio(const short* in, unsigned int num_in, short* out,
|
||||
unsigned int num_out)
|
||||
void AudioStretcher::ProcessSamples(const short* in, unsigned int num_in, unsigned int num_out)
|
||||
{
|
||||
const double time_delta = static_cast<double>(num_out) / m_sample_rate; // seconds
|
||||
|
||||
@ -65,7 +66,10 @@ void AudioStretcher::StretchAudio(const short* in, unsigned int num_in, short* o
|
||||
m_stretch_ratio, backlog_fullness, lpf_gain);
|
||||
|
||||
m_sound_touch.putSamples(in, num_in);
|
||||
}
|
||||
|
||||
void AudioStretcher::GetStretchedSamples(short* out, unsigned int num_out)
|
||||
{
|
||||
const size_t samples_received = m_sound_touch.receiveSamples(out, num_out);
|
||||
|
||||
if (samples_received != 0)
|
||||
|
@ -13,8 +13,9 @@ namespace AudioCommon
|
||||
class AudioStretcher
|
||||
{
|
||||
public:
|
||||
AudioStretcher(unsigned int sample_rate);
|
||||
void StretchAudio(const short* in, unsigned int num_in, short* out, unsigned int num_out);
|
||||
explicit AudioStretcher(unsigned int sample_rate);
|
||||
void ProcessSamples(const short* in, unsigned int num_in, unsigned int num_out);
|
||||
void GetStretchedSamples(short* out, unsigned int num_out);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
|
@ -129,18 +129,19 @@ unsigned int CMixer::Mix(short* samples, unsigned int num_samples)
|
||||
unsigned int available_samples =
|
||||
std::min(m_dma_mixer.AvailableSamples(), m_streaming_mixer.AvailableSamples());
|
||||
|
||||
m_stretch_buffer.fill(0);
|
||||
m_scratch_buffer.fill(0);
|
||||
|
||||
m_dma_mixer.Mix(m_stretch_buffer.data(), available_samples, false);
|
||||
m_streaming_mixer.Mix(m_stretch_buffer.data(), available_samples, false);
|
||||
m_wiimote_speaker_mixer.Mix(m_stretch_buffer.data(), available_samples, false);
|
||||
m_dma_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
||||
m_streaming_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
||||
m_wiimote_speaker_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
||||
|
||||
if (!m_is_stretching)
|
||||
{
|
||||
m_stretcher.Clear();
|
||||
m_is_stretching = true;
|
||||
}
|
||||
m_stretcher.StretchAudio(m_stretch_buffer.data(), available_samples, samples, num_samples);
|
||||
m_stretcher.ProcessSamples(m_scratch_buffer.data(), available_samples, num_samples);
|
||||
m_stretcher.GetStretchedSamples(samples, num_samples);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -160,11 +161,13 @@ unsigned int CMixer::MixSurround(float* samples, unsigned int num_samples)
|
||||
|
||||
memset(samples, 0, num_samples * 6 * sizeof(float));
|
||||
|
||||
unsigned int available_samples = Mix(m_stretch_buffer.data(), num_samples);
|
||||
// Mix() may also use m_scratch_buffer internally, but is safe because it alternates reads and
|
||||
// writes.
|
||||
unsigned int available_samples = Mix(m_scratch_buffer.data(), num_samples);
|
||||
for (size_t i = 0; i < static_cast<size_t>(available_samples) * 2; ++i)
|
||||
{
|
||||
m_float_conversion_buffer[i] =
|
||||
m_stretch_buffer[i] / static_cast<float>(std::numeric_limits<short>::max());
|
||||
m_scratch_buffer[i] / static_cast<float>(std::numeric_limits<short>::max());
|
||||
}
|
||||
|
||||
DPL2Decode(m_float_conversion_buffer.data(), available_samples, samples);
|
||||
|
@ -81,7 +81,7 @@ private:
|
||||
|
||||
bool m_is_stretching = false;
|
||||
AudioCommon::AudioStretcher m_stretcher;
|
||||
std::array<short, MAX_SAMPLES * 2> m_stretch_buffer;
|
||||
std::array<short, MAX_SAMPLES * 2> m_scratch_buffer;
|
||||
std::array<float, MAX_SAMPLES * 2> m_float_conversion_buffer;
|
||||
|
||||
WaveFileWriter m_wave_writer_dtk;
|
||||
|
Loading…
x
Reference in New Issue
Block a user