Streaming mp3 file through a callback function

(Noam) #1


I am in the process of checking if FMOD is suitable for my needs.
I am using VC++ (Visual Studio 2015).

I am trying to stream an mp3 audio through a callback function.
Playing the mp3 is very easy using createStream();
To stream the mp3 via a callback function,I set the FMOD_CREATESOUNDEXINFO parameter of createStream().
Indeed the callback function was activated, but it played for a couple of seconds and stopped.

I suppose it is just a matter of setting the FMOD_CREATESOUNDEXINFO struct properly for mp3.

Is there an example that shows how it should be done?
(I searched for such an example here and on other web sites without success).


(Brett Paterson) #2

Hi Noam,
The read callback that you are using in createSound is for PCM data only.

The only real way to try and feed raw mp3 data into fmod is through a file read callback, through System::setFileSystem, then createSound would be instructed to open a dummy/non existent file.

(Noam) #3

Hello Brett,

Thank you for your reply.
I will also try what you are suggesting.
Is there a specific example in …/api/lowlevel/examples/ folder that I can use?

In addition, I actually found a different way to do what I want, which is to use FMOD_DSP.
Essentially, I followed the dsp_custom.cpp example from the …/api/lowlevel/examples/ folder, and it was doing exactly what I needed.


(Brett Paterson) #4

Hi noam. DSP is for PCM data as well, so you would have to decode the data yourself if it was mp3.

You could use FMOD to decode mp3 data from file/memory/network and use createSound with FMOD_OPENONLY, then use Sound::readData into your DSP callback if you wanted.

(Noam) #5

Hi Brett,

I am not sure I understand why DSP is not suitable.
It is also possible that since I am new to FMOD, I did something that although working, is wrong.

Essentially I did the following:

  1. Opened an mp3 file with CreateSound().
  2. Created a DSP callback and connected it to FMOD system using createDSP().
  3. Played the mp3 file by calling playSound().

The result was that I could manipulate the mp3 file samples in the DSP callback, which is exactly what I wanted (e.g. change the volume).

Obviously, if this is a wrong way of doing it, and the way you suggest is better, I would like to do it the way you suggest.
Can you point me to a file read callback example?


(Brett Paterson) #6

you said “am trying to stream an mp3 audio through a callback function.”
You are not trying to do that it now sounds like. You are trying to modify the PCM data after playing an mp3.
The whole time I have been talking about how to pass mp3 data directly to a callback so that FMOD decodes it for you, so this is why there is some confusion.

(Noam) #7

I suppose you are right.
Sorry for the confusion and thank you for your help.