Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mixer performance when gain is 0.0 #466

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
30 changes: 23 additions & 7 deletions mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,33 @@ void AudioMixer4::update(void)
audio_block_t *in, *out=NULL;
unsigned int channel;

for (channel=0; channel < 4; channel++) {
if (!out) {
for (channel=0; channel < 4; channel++)
{
if (nullptr == out) // no audio so far
{
out = receiveWritable(channel);
if (out) {
if (out) // first audio received
{
int32_t mult = multiplier[channel];
if (mult != MULTI_UNITYGAIN) applyGain(out->data, mult);
if (0 == mult) // would be zeroed, just ignore it
{
release(out);
out = nullptr;
}
else
{
if (mult != MULTI_UNITYGAIN)
applyGain(out->data, mult);
}
}
} else {
}
else // we have something to transmit already: add to it
{
in = receiveReadOnly(channel);
if (in) {
applyGainThenAdd(out->data, in->data, multiplier[channel]);
if (in)
{
if (0 != multiplier[channel]) // only apply non-zero gain!
applyGainThenAdd(out->data, in->data, multiplier[channel]);
release(in);
}
}
Expand Down