We are currently implementing some custom audio processing via an SFX APO
and an EFX APO. Some of our algorithms require a power-of-two or
multiple-of-two buffer size in order to meaningfully process audio. Our
current implementation currently gets around this by using a ring-buffer.
However, we noticed that the IAudioProcessingObjectRT interface provides
the following two methods via baseaudioprocessing object
the swap APO sample.
STDMETHOD_(UINT32, CalcInputFrames)(_In_ UINT32 u32OutputFrameCount);
STDMETHOD_(UINT32, CalcOutputFrames)(_In_ UINT32 u32InputFrameCount);
Playing around with the debugger we found that CalcInputFrames gets called
with 480 being the output frame count. Given the 10ms latency requirement
in the windows audio engine, this makes sense for a sample rate of 48kHz.
If we override this function to return 480*2 then we notice that APOProcess
gets called with double the number of input frames (as expected).
We also noticed that CalcOutputFrames never gets called.
We are considering using this mechanism as a way to obtain the appropriate
number of frames that our algorithm requires and removing the need to use
ring buffers in our implementation.
We have the following questions:
1. When does CalcOutputFrames get called?
2. Is there any documentation that you can point us to in order to
ensure that we are implementing these correctly?
3. What is the behavior when these functions are overridden?
4. What if we return a non-integer multiple of the input argument in
CalcInputFrames: for example, if we receive 480 --- and we return 512 (next
power of two).
5. Other than the fact that it is called by the real-time thread, are
there any other gotchas that we should be aware of with using these
Apologies for the lack of specificity. We are merely trying to understand
the appropriate use cases for those two methods, and what the behavior of
the audio engine is, before moving forward with a solution.
Any help or documentation would be appreciated. Thanks in advance for your
time and energy!