0
0

Hi, I am developing an app for IPhone and I’m sequencing a series of sounds that are equally long. Each one makes up a music bar and the sequence sounds without any gap. I am handling touch events and when I try to tap in the screen I get the value of the channel’s position about 9000 samples ahead than expected. For example when I play around and try to tap at the beginning of every bar I would expect that the channel’s position is close to 0 with an average error of no more that around 1000 samples (~20 ms), however when I test the app I get the average of 9000 samples ahead which is about 204 ms. This is a lot!.

I’ve read some posts that say something like the master mixer works with 4 buffers of 1024 each one. So the position of the sound we are actually listening is getPosition() – 1024 * 4?. I’m kind of lost here and really need help. I have worked a lot in this project and got so far in synchronization matter (I hope) but I really think I am missing something here. Please, if someone can explain me this getPosition() in regard of the buffering mechanics, it would be very valuable for me. Considering I am not an expert in sound programming.

PLEASE, HELP!

Juan P. Reyes

  • You must to post comments
0
0

Thank you very much Mathew, it all make sense now!

  • You must to post comments
0
0

When you call getPosition you get the number of samples mixed for the output stream. However this doesn’t mean the number of samples you have actually heard yet as we mix in advance to avoid playback buffer issues. The "buffer ahead" length is dspbufferlength * dspnumbuffers, which defaults to 1024 * 4, hence 4096 samples. On iPhone the default sample rate is 24KHz, this means when you translate 4096 samples into time, you get 4096 / 24000 = 0.170 seconds latency. That default latency is quite long, you can adjust it lower if you like via System::setDSPBufferSize (perhaps 512 * 4 instead) but you will need to test to ensure there are no stability issues.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.