Play an Audio File from C program

Hi all,

I need to integrate some code into a C program where I can playback audio files. What is the recommended way to do this? I can already play from the command line using aplay

Can I just use syscalls?

Eoin

Hi @eoin_oc,

That depends on the complexity of the audio files you want to play, being *.wav, *.midi or even *.mp3. But either way, let me present you some options:

One option is to call aplay with the necessary parameters from your C/C++ application, taking the proper care of resource allocation, thread handling, etc.

Another way, is to use OpenAL.

And another way, is to use ALSA API and libasound, like shown here.

You can also use mpg123 library for playing *mp3. See its documentation here and a sample program here.

Best regards,
André Curvello