How to play an audio in C Language

Asked

Viewed 2,606 times

3

If you can help me, I’m doing an Electronic Urn in C language, I’d like to put that little vote after a person takes a vow.

I already have that sound in . mp3 and . wav format, how do I play that sound after a vote? Do you have any specific library?

2 answers

3


You can use a library, which will facilitate your development.

Example with FMOD

#include <conio.h>
#include "inc/fmod.h"

FSOUND_SAMPLE* handle;

int main ()
{
   // init FMOD sound system
   FSOUND_Init (44100, 32, 0);

   // load and play mp3
   handle=FSOUND_Sample_Load (0,"my.mp3",0, 0, 0);
   FSOUND_PlaySound (0,handle);

   // wait until the users hits a key to end the app
   while (!_kbhit())
   {
   }

   // clean up
   FSOUND_Sample_Free (handle);
   FSOUND_Close();
}

Source: Source

  • 1

    Remembering that Bass and Fmod are paid if it is for commercial use

  • @Bacco well remembered, by the question of the OP should be a college project or exercise learning...in this case there will be no problem for him.... :)

  • I believe that will not have problem anyway, I only commented because other people can read in the future, for other uses.

  • @Bacco quiet, I had not attacked me for this... :)

  • Where I find Fmod, on their website there is no place to download the library, only Fmodstudio

1

In addition to those that have already been cited have those that play WAV files with Sdl_mixer:

  • The SDL (Simple Directmedia Layer)
  • Sdl_mixer

See more here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.