Reading mp3 Sound data as PCM samples?

Is there a way to read PCM data from an FMOD::Sound loaded with compressed bitstream type, such as an mp3 or ogg?

I tried setting the PCM read callback on System::createSound, but it doesn’t seem to fire in HTML FMOD regardless of sound type.
I used Sound::lock, reading raw pcm bytes and Sound::readData when opened with FMOD_OPENONLY. Both methods seem to return the same data. Since I have no idea how to read 16-bit bitstream data (that’s what getFormat returns), I tried parsing the retrieved data as signed 16-bit integers, but the result doesn’t match to the sound data.

Is there a correct way to read this?

Ah, I found the issue after more carefully reading the documentation.

I was using FMOD_CREATECOMPRESSEDSAMPLE, so correct me if I’m wrong, but it seems like since the data of compressed files like mp3 and ogg was left compressed in FMOD’s buffers, there is no way for FMOD to then give you interpreted PCM data since it decompresses it on the fly?

After switching to FMOD_CREATESAMPLE, (I also switched from open memory point → open memory) the PCM Read callback is now firing and giving the expected data.

Happy to hear you’ve found a solution.

This is correct.

If you haven’t already, I would recommend reading over the Core API Guide section on Advanced Sound Creation for more info on creating Sounds using FMOD_CREATESOUNDEXINFO for PCM read callbacks, FMOD_OPENMEMORY, etc.

1 Like

Thanks for your answer, the page you linked was actually the section that helped me find the solution. It might not mean much coming from me, but the docs are some of the best I’ve used and extremely helpful.

2 Likes