mirror of https://github.com/AxioDL/boo.git
Better buffer handling for audio mixing
This commit is contained in:
parent
6d65216dd6
commit
80026d7fe6
|
@ -23,8 +23,8 @@ void AudioMatrixMono::setDefaultMatrixCoefficients(AudioChannelSet acSet)
|
|||
}
|
||||
}
|
||||
|
||||
void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t samples) const
|
||||
int16_t* AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t samples) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t s=0 ; s<samples ; ++s, ++dataIn)
|
||||
|
@ -37,10 +37,11 @@ void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t samples) const
|
||||
int32_t* AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t samples) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t s=0 ; s<samples ; ++s, ++dataIn)
|
||||
|
@ -53,10 +54,11 @@ void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t samples) const
|
||||
float* AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t samples) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t s=0 ; s<samples ; ++s, ++dataIn)
|
||||
|
@ -69,6 +71,7 @@ void AudioMatrixMono::mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
void AudioMatrixStereo::setDefaultMatrixCoefficients(AudioChannelSet acSet)
|
||||
|
@ -90,8 +93,8 @@ void AudioMatrixStereo::setDefaultMatrixCoefficients(AudioChannelSet acSet)
|
|||
}
|
||||
}
|
||||
|
||||
void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t frames) const
|
||||
int16_t* AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t frames) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t f=0 ; f<frames ; ++f, dataIn += 2)
|
||||
|
@ -106,10 +109,11 @@ void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t frames) const
|
||||
int32_t* AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t frames) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t f=0 ; f<frames ; ++f, dataIn += 2)
|
||||
|
@ -124,10 +128,11 @@ void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t frames) const
|
||||
float* AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t frames) const
|
||||
{
|
||||
const ChannelMap& chmap = info.m_channelMap;
|
||||
for (size_t f=0 ; f<frames ; ++f, dataIn += 2)
|
||||
|
@ -142,6 +147,7 @@ void AudioMatrixStereo::mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
|||
++dataOut;
|
||||
}
|
||||
}
|
||||
return dataOut;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,12 +50,12 @@ public:
|
|||
m_coefs[i] = coefs[i];
|
||||
}
|
||||
|
||||
void mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t samples) const;
|
||||
void mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t samples) const;
|
||||
void mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t samples) const;
|
||||
int16_t* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t samples) const;
|
||||
int32_t* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t samples) const;
|
||||
float* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t samples) const;
|
||||
};
|
||||
|
||||
class AudioMatrixStereo
|
||||
|
@ -74,12 +74,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t frames) const;
|
||||
void mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t frames) const;
|
||||
void mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t frames) const;
|
||||
int16_t* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int16_t* dataIn, int16_t* dataOut, size_t frames) const;
|
||||
int32_t* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const int32_t* dataIn, int32_t* dataOut, size_t frames) const;
|
||||
float* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
||||
const float* dataIn, float* dataOut, size_t frames) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ void AudioVoice::_setPitchRatio(double ratio)
|
|||
{
|
||||
if (m_dynamicRate)
|
||||
{
|
||||
soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, 0 /*m_parent.mixInfo().m_periodFrames*/);
|
||||
soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, 0);
|
||||
if (err)
|
||||
{
|
||||
Log.report(logvisor::Fatal, "unable to set resampler rate: %s", soxr_strerror(err));
|
||||
|
@ -98,6 +98,7 @@ void AudioVoiceMono::_resetSampleRate(double sampleRate)
|
|||
|
||||
m_sampleRateIn = 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);
|
||||
m_resetSampleRate = false;
|
||||
|
@ -123,14 +124,13 @@ size_t AudioVoiceMono::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratch16.data(), frames);
|
||||
oDone = soxr_output(m_src, scratch16.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixMonoSampleData(mixInfo, scratch16.data(), buf, oDone);
|
||||
buf = m_matrix.mixMonoSampleData(mixInfo, scratch16.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,14 +148,13 @@ size_t AudioVoiceMono::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratch32.data(), frames);
|
||||
oDone = soxr_output(m_src, scratch32.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixMonoSampleData(mixInfo, scratch32.data(), buf, oDone);
|
||||
buf = m_matrix.mixMonoSampleData(mixInfo, scratch32.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,14 +172,13 @@ size_t AudioVoiceMono::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratchFlt.data(), frames);
|
||||
oDone = soxr_output(m_src, scratchFlt.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixMonoSampleData(mixInfo, scratchFlt.data(), buf, oDone);
|
||||
buf = m_matrix.mixMonoSampleData(mixInfo, scratchFlt.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,14 +266,13 @@ size_t AudioVoiceStereo::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratch16.data(), frames);
|
||||
oDone = soxr_output(m_src, scratch16.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixStereoSampleData(mixInfo, scratch16.data(), buf, oDone);
|
||||
buf = m_matrix.mixStereoSampleData(mixInfo, scratch16.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,14 +291,13 @@ size_t AudioVoiceStereo::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratch32.data(), frames);
|
||||
oDone = soxr_output(m_src, scratch32.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixStereoSampleData(mixInfo, scratch32.data(), buf, oDone);
|
||||
buf = m_matrix.mixStereoSampleData(mixInfo, scratch32.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,14 +316,13 @@ size_t AudioVoiceStereo::pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo,
|
|||
size_t totalDone = 0;
|
||||
while (frames)
|
||||
{
|
||||
oDone = soxr_output(m_src, scratchFlt.data(), frames);
|
||||
oDone = soxr_output(m_src, scratchFlt.data(), m_5msFrames);
|
||||
_midUpdate();
|
||||
if (oDone)
|
||||
{
|
||||
m_matrix.mixStereoSampleData(mixInfo, scratchFlt.data(), buf, oDone);
|
||||
buf = m_matrix.mixStereoSampleData(mixInfo, scratchFlt.data(), buf, oDone);
|
||||
totalDone += oDone;
|
||||
frames -= oDone;
|
||||
buf += oDone;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ protected:
|
|||
soxr_t m_src = nullptr;
|
||||
double m_sampleRateIn;
|
||||
double m_sampleRateOut;
|
||||
size_t m_5msFrames;
|
||||
bool m_dynamicRate;
|
||||
|
||||
/* Running bool */
|
||||
|
|
Loading…
Reference in New Issue