5

When audio players (like VLC, for example) play compressed audio files (like mp3, for instance), do they first convert them to pcm data (like in wav files) and then play it? It seems very logical to me - first to decompress a mp3 file to an uncompressed wav file and then to play it. But I failed to find any confirmation to the idea on the Internet. And besides, I'm not sure that it's true because if we have many mp3 files to be played they will take much RAM when all decompressed.

But if players do not decompress mp3-files to wav-files, it means that they do NOT use an mp3 decoder at all. It sounds strange. So how do they play compressed audio? Could you, please, help me to figure all this out? Really hope for your help.

6

Usually, an application that plays encoded files (be it audio or video) will need to decode that file to a format that the target interface (be it a video or audio interface) can output on a standard port (like analog or spdif for audio, hdmi or vga for video).

Most audio interfaces are waiting for PCM datas. Depending on the OS host of the platform, the player will implement a decoder, make call to an external library, or use an OS implementation of the decoder.

Nevertheless (and fortunately) most used codecs don't require that you keep the whole signal in memory (like the whole mp3 file or the whole mp4 file). There usually is a frame concept, which means that a frame is a set of data that can be decoded as a unit (notice that in this context, a frame might represent several PCM audio samples or several images of a video stream). These units are usually less than a second in duration.

So only frames and their decoded result has to be kept in memory during the decoding process. Then, next encoded data are read from file, decoded, and passed to the interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.