1

I am confused on these three concepts

I am working on audio project on ios eventhough I am newbee on objective c and c. I am trying to get realtime fft of the audio data .

During the process I have come to the point where I am very confused on these three concepts. -maximumFramesPerSlice, -inNumberFrames variable on rendering function -preferred I/O hardware buffer duration which is set on AVAudioSession

I set buffer duration to 100 ms. while I expect InNumberFrames to come 4410 samples/frames on 44.1khz sampling rate, it always brings 470-471 frames on each render(callback) . while I am confused on both of these, now another variable comes out. maximumFramesPerSlice ?

it's default value is 4096. in coreAudio glossary it says "slice: The number of frames requested and processed during one rendering cycle of an audio unit"

so why it comes 470 frames in each render.

I will be very thankful for any help

smoothumut
  • 3,423
  • 1
  • 25
  • 35

1 Answers1

4

Buffer duration in iOS is only a preferred duration. The OS may try to use a value close to this configured preference, but is free to use a different duration (based on the current device hardware capabilities, the state of the device, other running audio apps, and the OS version, etc.), and even change this duration while the app is running (such as increasing it when the display "locks").

So iNumberOfFrames divided by the sample rate is the actual duration of the audio data rendered in the current callback. This duration can change between successive callbacks. The OS chooses this duration, not the app. The app only suggests a preference.

If the actual buffer size is greater than maximumFramesPerSlice, the Audio Unit will return an error, so maximumFramesPerSlice is best left at 4096 to prevent your app from crashing when the display is locked and/or other things happen involving the OS outside your app.

470 to 471 samples per frame suggests that the actual hardware ADC chip is running at 48000 sps and DMAing buffers of 512 samples to the processor, which the OS is resampling to 470.x samples at 44100 before handing the result to your app.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • thank you very very much! I am really appreciated for your answer and it helps me understand the concept far more now. But I have another questions. I got some points very well and some points not. here is my first question : for maximumframesPerSlice, my understanding is that it is the max inNumberOfFrames for different circumstances(like locked screen or sleep or so). so after I set it to 4096 then I have nothing to do with it! am I correct? – smoothumut Oct 25 '14 at 12:36
  • and here is my second question : so if I collect all 470 or 471 samples in float array untill I have total 44100 samples, does this mean I got perfect (or almost perfect) 1 second data of recording? and then can I apply DSP algorithms to these 44100 samples ? like filtering and fft... – smoothumut Oct 25 '14 at 12:39