I always curious how could the computer able to play music, and how could one implemented an audio player, in a GUI app, or in a termial process like mpsyt.

Let's assume we already have an audio file (in mp3, wav, ogg,... format), and we want to build a program to read the file, play it on our computer's speakers, the process would be:

For decoding, there's a lot of decoders available so we can use, each format need a different decoder. More about this later.

To actually play these decoded data on the device, we need to communicate with the device via the OS's audio device interface. There are different interface depends on the OS you're using, for example:

There are some cross platform implementation to provide an easier to use API across platforms, one of which is Rust's cpal.