# Reading mp3 Sound data as PCM samples?

**URL:** <https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069>\
**Category:** FMOD Engine\
**Created:** [January 8, 2024, 7:56am UTC](https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069 "2024-01-08T07:56:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aishi1](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@aishi1](https://qa.fmod.com/u/aishi1)\
**Post date:** [January 8, 2024, 7:56am UTC](https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069/1 "2024-01-08T07:56:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![aishi1](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@aishi1](https://qa.fmod.com/u/aishi1)\
**Post date:** [January 8, 2024, 10:57am UTC](https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069/2 "2024-01-08T10:57:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [January 9, 2024, 5:24am UTC](https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069/3 "2024-01-09T05:24:50Z")

</div>

Happy to hear you’ve found a solution.

> [@aishi1](#):
>
> 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?

This is correct.

If you haven’t already, I would recommend reading over the [Core API Guide section on Advanced Sound Creation](https://www.fmod.com/docs/2.02/api/core-guide.html#advanced-sound-creation) for more info on creating Sounds using [FMOD\_CREATESOUNDEXINFO](https://www.fmod.com/docs/2.02/api/core-api-system.html#fmod_createsoundexinfo) for PCM read callbacks, FMOD\_OPENMEMORY, etc.

---

<div class="post-metadata">

**Author:** ![aishi1](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@aishi1](https://qa.fmod.com/u/aishi1)\
**Post date:** [January 9, 2024, 6:24am UTC](https://qa.fmod.com/t/reading-mp3-sound-data-as-pcm-samples/21069/4 "2024-01-09T06:24:08Z")

</div>

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.
