0

I need to implement a playback of separate audio files in N channels, files may play sequentially or in parallel. I need to implement it on Android.

Timeline:

|file a...|file d....|file b...|......|file k|....

|.....|file g|file c..|file p.|....

I'm thinking two options, one being FMOD to decompress files and play them simultaneously. I have researched and FMOD seems to fit well and much easier than manually playing this using an AudioTrack. However, I can't understand if FMOD would allow us to save the entire merged output without playing it through.

I know that using solution here we can redirect output to a wav file, but is it possible to just create a final output instantly and save it using FMOD? Or will I have to manually merge PCMS into one stream after all..

Thanks.

Community
  • 1
  • 1
EvilDuck
  • 4,386
  • 23
  • 32

1 Answers1

1

An important question here is why you need to save the files out, if it's possible to do this offline then it would be a lot simpler. If you must record the concatenation of several files (including others played in parallel), it is quite possible with FMOD.

One way would be to use wave-writer-nrt output mode, which allows you to output a wav file based on FMOD playsound calls in faster than realtime.

Another way is to use a custom DSP to access the data stream of any submix as it plays, useful if you want other sounds actually playing at the same time.

Another is simply create the sound objects, then use Sound::lock to access the PCM data, which you could concatenate yourself to a destination. Keep in mind all the sounds would need to be the same sample rate and channels, otherwise you would need to do processing. Also keep in mind you cannot do this for parallel sounds unless you want to mix the audio yourself.

Mathew Block
  • 1,613
  • 1
  • 10
  • 9
  • Regarding the first question - I have a requirement to be able to output a resulting file from the resulting mix without playing it back and I'm looking for a best way to do it. I understand FMOD is awesome for playback, but can't figure out how good does it fit for saving a mix of arbitrary files specified by application. – EvilDuck Sep 30 '11 at 12:25
  • 1
    Since FMOD is designed for playback you need to load the sounds, then play them with FMOD. If you want to avoid hearing the result use the no-sound or wav-writer output modes. If you need to playback faster than realtime use the 'nrt' versions of those output modes. – Mathew Block Oct 02 '11 at 21:53
  • Thank you Mathew. OUTPUTMODE_WAVWRITER_NRT is what I needed indeed. If I update very frequently and start playback of other parallel sounds in other channels I will get what I want. Still, too bad FMOD doesn't have global record time tracking facilities, I can get only position within the currently playing sound, but in my case this is ok. – EvilDuck Oct 05 '11 at 09:51
  • 1
    Actually you can get a global time by using System::getDSPClock, this clock value is incremented for every sample produced by the system. It increments in number of output samples. So if the system is running at the default rate for Android of 24000, every second the clock will increase by that amount. – Mathew Block Oct 05 '11 at 22:25
  • Thank you Matthew! You've helped me a lot! – EvilDuck Oct 06 '11 at 07:49