mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-18 17:35:44 +00:00
Huge quaility improvement with soxr by priming with 5ms of silence
This commit is contained in:
@@ -83,7 +83,8 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate)
|
||||
soxr_delete(m_src);
|
||||
|
||||
double rateOut = m_parent.mixInfo().m_sampleRate;
|
||||
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, m_parent.mixInfo().m_sampleFormat);
|
||||
soxr_datatype_t formatOut = m_parent.mixInfo().m_sampleFormat;
|
||||
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, formatOut);
|
||||
soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0);
|
||||
|
||||
soxr_error_t err;
|
||||
@@ -102,6 +103,37 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate)
|
||||
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
|
||||
_setPitchRatio(m_pitchRatio, false);
|
||||
m_resetSampleRate = false;
|
||||
|
||||
m_silentOut = true;
|
||||
switch (formatOut)
|
||||
{
|
||||
case SOXR_INT16_I:
|
||||
{
|
||||
std::vector<int16_t>& scratch16 = m_root.m_scratch16;
|
||||
if (scratch16.size() < m_root.m_5msFrames)
|
||||
scratch16.resize(m_root.m_5msFrames);
|
||||
soxr_output(m_src, scratch16.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
case SOXR_INT32_I:
|
||||
{
|
||||
std::vector<int32_t>& scratch32 = m_root.m_scratch32;
|
||||
if (scratch32.size() < m_root.m_5msFrames)
|
||||
scratch32.resize(m_root.m_5msFrames);
|
||||
soxr_output(m_src, scratch32.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
case SOXR_FLOAT32_I:
|
||||
{
|
||||
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
|
||||
if (scratchFlt.size() < m_root.m_5msFrames)
|
||||
scratchFlt.resize(m_root.m_5msFrames);
|
||||
soxr_output(m_src, scratchFlt.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
m_silentOut = false;
|
||||
}
|
||||
|
||||
size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t frames)
|
||||
@@ -110,7 +142,13 @@ size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t f
|
||||
if (scratchIn.size() < frames)
|
||||
scratchIn.resize(frames);
|
||||
*data = scratchIn.data();
|
||||
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
||||
if (ctx->m_silentOut)
|
||||
{
|
||||
memset(*data, 0, frames * 2);
|
||||
return frames;
|
||||
}
|
||||
else
|
||||
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
||||
}
|
||||
|
||||
size_t AudioVoiceMono::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
||||
@@ -234,7 +272,8 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate)
|
||||
soxr_delete(m_src);
|
||||
|
||||
double rateOut = m_parent.mixInfo().m_sampleRate;
|
||||
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, m_parent.mixInfo().m_sampleFormat);
|
||||
soxr_datatype_t formatOut = m_parent.mixInfo().m_sampleFormat;
|
||||
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, formatOut);
|
||||
soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0);
|
||||
|
||||
soxr_error_t err;
|
||||
@@ -253,6 +292,37 @@ void AudioVoiceStereo::_resetSampleRate(double sampleRate)
|
||||
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
|
||||
_setPitchRatio(m_pitchRatio, false);
|
||||
m_resetSampleRate = false;
|
||||
|
||||
m_silentOut = true;
|
||||
switch (formatOut)
|
||||
{
|
||||
case SOXR_INT16_I:
|
||||
{
|
||||
std::vector<int16_t>& scratch16 = m_root.m_scratch16;
|
||||
if (scratch16.size() < m_root.m_5msFrames * 2)
|
||||
scratch16.resize(m_root.m_5msFrames * 2);
|
||||
soxr_output(m_src, scratch16.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
case SOXR_INT32_I:
|
||||
{
|
||||
std::vector<int32_t>& scratch32 = m_root.m_scratch32;
|
||||
if (scratch32.size() < m_root.m_5msFrames * 2)
|
||||
scratch32.resize(m_root.m_5msFrames * 2);
|
||||
soxr_output(m_src, scratch32.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
case SOXR_FLOAT32_I:
|
||||
{
|
||||
std::vector<float>& scratchFlt = m_root.m_scratchFlt;
|
||||
if (scratchFlt.size() < m_root.m_5msFrames * 2)
|
||||
scratchFlt.resize(m_root.m_5msFrames * 2);
|
||||
soxr_output(m_src, scratchFlt.data(), m_root.m_5msFrames);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
m_silentOut = false;
|
||||
}
|
||||
|
||||
size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size_t frames)
|
||||
@@ -262,7 +332,13 @@ size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size
|
||||
if (scratchIn.size() < samples)
|
||||
scratchIn.resize(samples);
|
||||
*data = scratchIn.data();
|
||||
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
||||
if (ctx->m_silentOut)
|
||||
{
|
||||
memset(*data, 0, samples * 2);
|
||||
return frames;
|
||||
}
|
||||
else
|
||||
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
||||
}
|
||||
|
||||
size_t AudioVoiceStereo::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
||||
|
||||
Reference in New Issue
Block a user