Add `slew` option to pitch-update function

This commit is contained in:
Jack Andersen 2016-05-16 17:46:03 -10:00
parent eea45ebcbe
commit ceff1934c1
3 changed files with 11 additions and 9 deletions

View File

@ -69,7 +69,7 @@ struct IAudioVoice
virtual void setStereoMatrixCoefficients(const float coefs[8][2])=0;
/** Called by client to dynamically adjust the pitch of voices with dynamic pitch enabled */
virtual void setPitchRatio(double ratio)=0;
virtual void setPitchRatio(double ratio, bool slew)=0;
/** Instructs platform to begin consuming sample data; invoking callback as needed */
virtual void start()=0;

View File

@ -16,11 +16,11 @@ AudioVoice::~AudioVoice()
soxr_delete(m_src);
}
void AudioVoice::_setPitchRatio(double ratio)
void AudioVoice::_setPitchRatio(double ratio, bool slew)
{
if (m_dynamicRate)
{
soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, 0);
soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, slew ? m_5msFrames : 0);
if (err)
{
Log.report(logvisor::Fatal, "unable to set resampler rate: %s", soxr_strerror(err));
@ -36,13 +36,14 @@ void AudioVoice::_midUpdate()
if (m_resetSampleRate)
_resetSampleRate(m_deferredSampleRate);
if (m_setPitchRatio)
_setPitchRatio(m_pitchRatio);
_setPitchRatio(m_pitchRatio, m_slew);
}
void AudioVoice::setPitchRatio(double ratio)
void AudioVoice::setPitchRatio(double ratio, bool slew)
{
m_setPitchRatio = true;
m_pitchRatio = ratio;
m_slew = slew;
}
void AudioVoice::resetSampleRate(double sampleRate)
@ -100,7 +101,7 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate)
m_sampleRateOut = rateOut;
m_5msFrames = rateOut * 5 / 1000;
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
_setPitchRatio(m_pitchRatio);
_setPitchRatio(m_pitchRatio, false);
m_resetSampleRate = false;
}
@ -240,7 +241,7 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate)
m_sampleRateIn = sampleRate;
m_sampleRateOut = rateOut;
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
_setPitchRatio(m_pitchRatio);
_setPitchRatio(m_pitchRatio, false);
m_resetSampleRate = false;
}

View File

@ -50,7 +50,8 @@ protected:
/* Deferred pitch ratio set */
bool m_setPitchRatio = false;
double m_pitchRatio = 1.0;
void _setPitchRatio(double ratio);
bool m_slew = false;
void _setPitchRatio(double ratio, bool slew);
/* Mid-pump update */
void _midUpdate();
@ -63,7 +64,7 @@ protected:
public:
~AudioVoice();
void resetSampleRate(double sampleRate);
void setPitchRatio(double ratio);
void setPitchRatio(double ratio, bool slew);
void start();
void stop();
void unbindVoice();