Search code examples
c++audioandroid-ndkoboe

Can i add and/or replace audio sources in oboe without restarting the audio stream?


I need to extract audio assets on the fly and load them in to a timeline for playback.

I also need to render varying lengths of the asset files, but I have an idea I'm going to try out tomorrow that will sort that I think, if anyone has any tips that would be great though.

I have been playing with oboe RhythmGame code which is the closest, of the oboe samples, to what i'm trying to do. But it's not happy when I try and add or change audio sources on the fly.

Is this something oboe can do or will I have to cycle the audio stream on and off for each new set of files?


Solution

  • What you're proposing can definitely be done without needing to restart the audio stream. The audio stream will just request PCM data on each callback. It's your app's job to supply that PCM data.

    In the RhythmGame sample compressed audio files are decoded into memory using the DataSource object. The Player object then wraps this DataSource to control playback through the set methods.

    If you need to play audio data from files in a timeline I would create a new Timeline class which copies the relevant sections of audio data from DataSources and places them sequentially into a buffer. Then your audio stream can read directly from that buffer on each callback.