audiomp3audio-streamingmpeglame

Is it possible to stitch MP3 frames together?


I'm working with CBR, no bit reservoir, 192k bitrate, and 48k sample rate MP3 files.

CBR + 192k bitrate + 48k sample rate gives a clean 576 bytes per frame.

No bit reservoir is to make each frame independent.

The reason I want to stitch them is that I want to stream the MP3 (chunk by chunk).

Therefore I need to decode each chunk into PCM for playback.

When stitching the raw PCM data of the decoded MP3 together, I can hear a click/glitch/silence/something between each chunk on playback.

How can I stream MP3 perfectly without any click, considering my constraints (only CBR, no bit reservoir, etc)? Is it even possible?


Solution

  • I don't think you can cut and concatenate MP3 frames naively. The Inverse Modified Discrete Cosine Transform (IMDCT) which is part of the decoding process - has different windowing modes. The windowing mode is signaled within each MP3 frame. In at least one windowing mode the IMDCT is reusing values from the previous MP3 frame. This means - you need to decode the previous frame to decode the current frame correctly.

    Lets assume you have packets from file a and file b and you like to play:

    a1 a2 a3 b6 b7 b8

    to decode b6 correctly - you need to decode b5 and then throw away the PCM samples of b5. So at the cut you have to prime the decoder with b5 without playing b5.

    a1 a2 a3 [b5] b6 b7 b8

    You could send your player an additional packet at the cuts and then signal the player to discard the primming samples of the decoded additional packets.