0

After reading so much on the remoteIO for the iphone ,and the buffers, i wrote a code and i get the audio samples.

but , i cant understand something about the buffer size.

i know every time the buffer is full, the callback function is being called. the buffer size is 2 byts, 16 bits. what i dont know is, the frequency which the callback is called to get this 16bits.

somehow when i log the buffer out, i have got only 2500 samples per 7 second, which means about 400 samples a second. which is too BAD ! .

what am i doing wrong ? OR what i dont understand here ?

my code is here from another post of me : error in audio Unit code -remoteIO for iphone

Community
  • 1
  • 1
Curnelious
  • 1
  • 16
  • 76
  • 150

3 Answers3

2

The problem is that NSLog is way too slow compared to the audio samplerate, and thus blocks yor audio callback from getting called often enough. So you are losing almost all of the samples. Take all of the NSLogs out of the audio callback, and just increment a counter to count your samples.

If you want to NSLog something, figure out how to do that outside the audio callback.

Your code sample seems to be requesting 44100 samples per second from the audio unit. Check the error return value to make sure.

Also, the number of samples in a buffer does not involve a strlen().

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

Maybe it's just the logging that is 400Hz, and the audio is fine?

If I understand correctly you have no problem hearing the audio, that means that the audio frequency is sufficient. At 400Hz, you'll have aliasing for all bands over 200Hz, which is very low (we can hear up to 20 kHz), meaning your audio will be strongly distorted. See nyquist theorem.

Jay
  • 452
  • 4
  • 15
  • i know nyquist i am hardware engineer. i cant hear anything because it is an mic input, hence cant know if i am having an aliasing. just got the log. but thanks anyway. – Curnelious Jan 03 '12 at 10:31
0

Maybe what you get is not a single sample but an array of samples, i.e. an audio buffer, containing maybe 128 samples (~400*128 = 44100), and maybe multiple channels (depending on your configuration).

moala
  • 5,094
  • 9
  • 45
  • 66
  • thanks a lot. what does audioFormat.mFramesPerPacket means ? how many samples i get for 1 packet? why everybody set it to 1 including apple samples ? – Curnelious Jan 03 '12 at 10:44
  • Sorry, i've been mistaken, let it stay to 1, but you have to find out how many samples you have in your buffer (maybe it's constant, maybe it's configurable, I don't know). Look at the official documentation for more info. – moala Jan 03 '12 at 10:50
  • maybe your sample count is inNumberFrames. – moala Jan 03 '12 at 10:54
  • i could see that sometimes my callBack is having 168 samples, and sometimes it has 2 or 1 or 10 . how is that buffer works anyway? apple docs are so lack in this ! – Curnelious Jan 03 '12 at 11:55