3

I've implemented an AUGraph similar to the one on the iOS Developer's Library. In my App, however, I need to be able to playback sound at different sample rates (probably two different ones).

I've been looking around Apple's documentation and haven't found a way to set the sample rate at runtime. I've been thinking of three possible work-arounds:

  1. Re-initialize the AUGraph every time I need to change the sample rate;
  2. Initialize a different AUGraph for each different sample rate;
  3. Convert the sample rate of every sound before playing;

These methods all seem really clunky and heavy on the processor.

What is the best way of changing sample rate of an AUGraph at runtime?

rahzark
  • 494
  • 1
  • 4
  • 13
  • After some tests, I've found out reinitializing the AUGraph is not as bad as it looked. I'm going to follow #1 for now, possibly changing to #2 in the future. Thanks everyone! – rahzark Jan 02 '12 at 15:28

3 Answers3

1

typically #1 for continuous audio streaming scenarios.

your program may have a special need or benefit by using another approach you have listed:

  • #2: you need to process where reinitialization is not a concern.
  • #3: you need to mix and process two streams with different input sample rates together at the same time, particularly if you find yourself SRCing the signal multiple times.

but, if you just need playback with SRC and lowest latency is not a concern, you may want to try an AudioQueue instead.

justin
  • 104,054
  • 14
  • 179
  • 226
0

I'm pretty sure that it can't be done in runtime. Solution #2 is your best bet, along with #3. For sample rate conversion, libsndfile can probably be adapted to your needs.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • Resampling can be done at runtime. iOS 5 may have an new audio unit that can do the resampling for you. – hotpaw2 Dec 28 '11 at 19:11
0

If you don't want latency from tearing down and rebuilding the audio graph, you may need to resample the sound data (for all but one sample rate).

You could either resample the sounds data before starting to play it, or run a real-time resampler as part of the audio graph. Many iOS music apps do the latter as part of a built-in sampler-based synth unit, so the device has plenty of compute power to do so.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153