Playing sound in C ++ using native system calls?

So, on Windows, you can use the PlaySound to play an MP3 file in a C ++ application. What features can I use for Mac OS X / Linux? I would also appreciate if you could reference some sample programs like Hello-World, demonstrating this.

+6
source share
3 answers

You can simply open("/dev/dsp") and write to it. I suppose this is as “a native homework” as you can get.

+4
source

Regarding Audio: Linux! = Mac, so I will answer separately.

MacOS uses basic audio for low-level audio. Based on this, there are several higher-level APIs. If you just want to play the sound file, most likely the path of the AV Foundation Framework . Here you will find an example to create a simple iOS application that can be easily ported to MacOS.

For Linux, the whole situation is rather delicate. There are many different frameworks and libraries, and it is very unlikely that it is low level or high level, as some of them imitate others. Basically there is ALSA and OSS for low level audio. Both of them are shit. Jack strives to provide the foundation for professional sound, but it's not very portable (at least if you're interested in embedded devices). Most Linux OSs currently use PulseAudio as their audio server, which also has a simple API for simple single-sound playback and a very complex API for low-level content. And then there is the gstreamer library, which is quite portable and has a half-descent API and is especially designed to play audio and video files and streams, and perhaps this is the way to work on Linux.

I personally recommend using PortAudio , which is a library that provides - as the name indicates - an audio system that is portable across multiple operating systems and audio systems . PortAudio is also well designed and has a simple but flexible API.

+3
source

Well, I'm not sure that on current desktop computers there are some more additional services / libraries that play audio files, but if you really want to make low-level audio output from OS OS, start looking here . Perhaps this is too low level for your needs.

+1
source

Source: https://habr.com/ru/post/908806/


All Articles