diff --git a/research/miniaudio_engine.h b/research/miniaudio_engine.h index 760689d5..bedce953 100644 --- a/research/miniaudio_engine.h +++ b/research/miniaudio_engine.h @@ -2015,6 +2015,30 @@ MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesO } } else { /* Slow path. Need to interpolate the gain for each channel individually. */ + + /* We can allow the input and output buffers to be null in which case we'll just update the internal timer. */ + if (pFramesOut == NULL || pFramesIn == NULL) { + /* Fast path. Just update the internal timer. */ + } else { + /* Slow path. Need to interpolate the gain for each channel individually. */ + float a = (float)pGainer->t / pGainer->config.smoothTimeInFrames; + float d = 1.0f / pGainer->config.smoothTimeInFrames; + + for (iFrame = 0; iFrame < frameCount; iFrame += 1) { + for (iChannel = 0; iChannel < pGainer->config.channels; iChannel += 1) { + pFramesOutF32[iFrame*pGainer->config.channels + iChannel] = pFramesInF32[iFrame*pGainer->config.channels + iChannel] * ma_mix_f32_fast(pGainer->oldGains[iChannel], pGainer->newGains[iChannel], a); + } + + a += d; + if (a > 1) { + a = 1; + } + } + + pGainer->t = ma_min(pGainer->t + frameCount, pGainer->config.smoothTimeInFrames); + } + + #if 0 for (iFrame = 0; iFrame < frameCount; iFrame += 1) { /* We can allow the input and output buffers to be null in which case we'll just update the internal timer. */ if (pFramesOut != NULL && pFramesIn != NULL) { @@ -2026,6 +2050,7 @@ MA_API ma_result ma_gainer_process_pcm_frames(ma_gainer* pGainer, void* pFramesO /* Move interpolation time forward, but don't go beyond our smoothing time. */ pGainer->t = ma_min(pGainer->t + 1, pGainer->config.smoothTimeInFrames); } + #endif } return MA_SUCCESS;