Fix silence test logic

This commit is contained in:
Jack Andersen 2017-11-27 18:09:23 -10:00
parent b995be262b
commit ce80446e8b
2 changed files with 34 additions and 54 deletions

View File

@ -123,19 +123,25 @@ size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t f
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data()); return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
} }
size_t AudioVoiceMono::pumpAndMix16(size_t frames) bool AudioVoiceMono::isSilent() const
{ {
if (m_sendMatrices.size()) if (m_sendMatrices.size())
{ {
for (auto& mtx : m_sendMatrices) for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent()) if (!mtx.second.isSilent())
return 0; return false;
return true;
} }
else else
{ {
if (DefaultMonoMtx.isSilent()) return DefaultMonoMtx.isSilent();
return 0;
} }
}
size_t AudioVoiceMono::pumpAndMix16(size_t frames)
{
if (isSilent())
return 0;
std::vector<int16_t>& scratch16Pre = m_root.m_scratch16Pre; std::vector<int16_t>& scratch16Pre = m_root.m_scratch16Pre;
if (scratch16Pre.size() < frames) if (scratch16Pre.size() < frames)
@ -174,17 +180,8 @@ size_t AudioVoiceMono::pumpAndMix16(size_t frames)
size_t AudioVoiceMono::pumpAndMix32(size_t frames) size_t AudioVoiceMono::pumpAndMix32(size_t frames)
{ {
if (m_sendMatrices.size()) if (isSilent())
{
for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent())
return 0; return 0;
}
else
{
if (DefaultMonoMtx.isSilent())
return 0;
}
std::vector<int32_t>& scratch32Pre = m_root.m_scratch32Pre; std::vector<int32_t>& scratch32Pre = m_root.m_scratch32Pre;
if (scratch32Pre.size() < frames) if (scratch32Pre.size() < frames)
@ -223,17 +220,8 @@ size_t AudioVoiceMono::pumpAndMix32(size_t frames)
size_t AudioVoiceMono::pumpAndMixFlt(size_t frames) size_t AudioVoiceMono::pumpAndMixFlt(size_t frames)
{ {
if (m_sendMatrices.size()) if (isSilent())
{
for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent())
return 0; return 0;
}
else
{
if (DefaultMonoMtx.isSilent())
return 0;
}
std::vector<float>& scratchFltPre = m_root.m_scratchFltPre; std::vector<float>& scratchFltPre = m_root.m_scratchFltPre;
if (scratchFltPre.size() < frames) if (scratchFltPre.size() < frames)
@ -360,19 +348,25 @@ size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data()); return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
} }
size_t AudioVoiceStereo::pumpAndMix16(size_t frames) bool AudioVoiceStereo::isSilent() const
{ {
if (m_sendMatrices.size()) if (m_sendMatrices.size())
{ {
for (auto& mtx : m_sendMatrices) for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent()) if (!mtx.second.isSilent())
return 0; return false;
return true;
} }
else else
{ {
if (DefaultMonoMtx.isSilent()) return DefaultStereoMtx.isSilent();
return 0;
} }
}
size_t AudioVoiceStereo::pumpAndMix16(size_t frames)
{
if (isSilent())
return 0;
size_t samples = frames * 2; size_t samples = frames * 2;
@ -413,17 +407,8 @@ size_t AudioVoiceStereo::pumpAndMix16(size_t frames)
size_t AudioVoiceStereo::pumpAndMix32(size_t frames) size_t AudioVoiceStereo::pumpAndMix32(size_t frames)
{ {
if (m_sendMatrices.size()) if (isSilent())
{
for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent())
return 0; return 0;
}
else
{
if (DefaultMonoMtx.isSilent())
return 0;
}
size_t samples = frames * 2; size_t samples = frames * 2;
@ -464,17 +449,8 @@ size_t AudioVoiceStereo::pumpAndMix32(size_t frames)
size_t AudioVoiceStereo::pumpAndMixFlt(size_t frames) size_t AudioVoiceStereo::pumpAndMixFlt(size_t frames)
{ {
if (m_sendMatrices.size()) if (isSilent())
{
for (auto& mtx : m_sendMatrices)
if (mtx.second.isSilent())
return 0; return 0;
}
else
{
if (DefaultMonoMtx.isSilent())
return 0;
}
size_t samples = frames * 2; size_t samples = frames * 2;

View File

@ -89,6 +89,8 @@ class AudioVoiceMono : public AudioVoice
static size_t SRCCallback(AudioVoiceMono* ctx, static size_t SRCCallback(AudioVoiceMono* ctx,
int16_t** data, size_t requestedLen); int16_t** data, size_t requestedLen);
bool isSilent() const;
size_t pumpAndMix16(size_t frames); size_t pumpAndMix16(size_t frames);
size_t pumpAndMix32(size_t frames); size_t pumpAndMix32(size_t frames);
size_t pumpAndMixFlt(size_t frames); size_t pumpAndMixFlt(size_t frames);
@ -110,6 +112,8 @@ class AudioVoiceStereo : public AudioVoice
static size_t SRCCallback(AudioVoiceStereo* ctx, static size_t SRCCallback(AudioVoiceStereo* ctx,
int16_t** data, size_t requestedLen); int16_t** data, size_t requestedLen);
bool isSilent() const;
size_t pumpAndMix16(size_t frames); size_t pumpAndMix16(size_t frames);
size_t pumpAndMix32(size_t frames); size_t pumpAndMix32(size_t frames);
size_t pumpAndMixFlt(size_t frames); size_t pumpAndMixFlt(size_t frames);