[wdmaudiodev] Re: Can number of valid frames in connection buffer be changed from 480 to any other Number when the Sample rate is selected to 48Khz

  • From: Rajendra Sethi <rajendra.sethi11@xxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Thu, 20 Dec 2018 15:55:49 +0530

Hi Mathew,
   Thank you for your reply.
I have one more question regarding the APO
Why Initialize, LockForProcess is getting called by multiple threads i.e
from Ntdll and different threads (I got this when I debugged the SwapAPO
smaple). Is there any way to limit the call to only once.

Regards,
Rajendra

On Thu, Dec 20, 2018 at 1:00 PM Matthew van Eerde <
dmarc-noreply@xxxxxxxxxxxxx> wrote:

It’s much worse than you think.



The APO contract is that the caller of APOProcess can give you any size
buffer it likes, even all the way down to a single sample! You are expected
to fill the output buffer with exactly the same number of samples.



In particular you cannot rely on the engine following any predetermined
pattern of buffer sizes.



If you have internal packet size requirements, then you need to thunk
between the completely free world of IAudioProcessingObject and the
constrained world of your processing algorithm. For example, you could
allocate an internal nonpaged pool of 63 samples in LockForProcess, and
prefill it with 63 samples of silence. Consider this “leftover input” from
an imaginary zeroth processing pass.



Whenever the audio engine hands you data, add it to the “leftover input”
from the previous processing pass. If you have at least 64 samples, process
data until you have less than 64 samples.



Write as much of the resulting output data as will fit into the output
buffer. Consider the rest “leftover output.” Save it until the next
processing pass.



The amount of “leftover input” and “leftover output” will vary, but the
sum will always be 63 samples.



Example 1: the audio engine always uses 480 samples

Pass 0: “Leftover input” starts at 63 samples. “Leftover output” starts at
0.



Pass 1: 480 samples. Input is now 480 + 63 = 543 samples.

Process 512 samples; leftover input is now 543 – 512 = 31 samples.

Write 480 of these processed samples to output; leftover output is 512 –
480 = 32 samples.



Pass 2: 480 samples. Input is now 31 + 480 = 511 samples.

Process 448 samples; leftover input is now 511 – 448 = 63 samples.

Write the 32 samples that were leftover from pass 1, plus all 448 samples.
Leftover output is now 0.



Pass 3: same as pass 1.



Pass 4: same as pass 2.



… and so on.



Example 2: the audio engine uses a different number of samples on every
pass (which it is entirely free to do.)



Pass 0: “Leftover input” starts at 63 samples. “Leftover output” starts at
0.



Pass 1: 117 samples. Input is now 117 + 63 = 180 samples.

Process 128 samples; leftover input is now 180 – 128 = 52 samples.

Write 117 of these processed samples to output; leftover output is 128 –
117 = 11 samples.



Pass 2: 1 sample. Input is now 52 + 1 sample.

Don’t process anything. Leftover input is now 53 samples.

Write one of the leftover output samples from pass 1. Leftover output is
now 10 samples.



Pass 3: 9 samples. Input is now 53 + 9 = 62 samples.

Don’t process anything. Leftover input is now 62 samples.

Write 9 of the leftover output samples from pass 2. Leftover output is now
1 sample.



Pass 4: 3 samples. Input is now 62 + 3 = 65 samples.

Process 64 samples; leftover input is now 65 – 64 = 1 sample.

Write the last leftover sample from pass 3 and 2 of the just-processed
samples. Leftover output is now 62 samples.



… etc.


------------------------------
*From:* wdmaudiodev-bounce@xxxxxxxxxxxxx <wdmaudiodev-bounce@xxxxxxxxxxxxx>
on behalf of Rajendra Sethi <rajendra.sethi11@xxxxxxxxx>
*Sent:* Wednesday, December 19, 2018 10:36:50 PM
*To:* wdmaudiodev@xxxxxxxxxxxxx
*Subject:* [wdmaudiodev] Can number of valid frames in connection buffer
be changed from 480 to any other Number when the Sample rate is selected to
48Khz

Hi All,

   We find that APOProcess receives 480 valid frames or samples when the
selected render mode under Sounds->Playback->Speaker properties->Advanced
is 48Khz Sample rate and 960 when render mode is 96Khz.  It appears that
the number of samples per call to APOProcess is about 10ms worth of
selected audio render mode
   However, an algorithm that processes 64 samples per call cannot work
well with 480 samples (works fine with 960 samples) because 480 is not a
multiple of 64.  Padding the last 32 samples is not an option due to
handling overhead and audio distortion issues.  Given that the number of
samples passed to the algorithm cannot be anything other than 64 at the
moment, is there any way I can change the number of valid frames from 480
(10ms) to a number which can be multiple of 64 in APOProcess or any other
place (registry perhaps) ?


--
*Regards*
*Rajendra Sethi*



-- 
*Thanks And Regards*
* Rajendra Sethi*

Other related posts: