0

I'm writing a program which constantly generates sound effects and output them to a sound buffer in a SDL callback function. Now I need to play a MP3 in the background as well. How do I do this? Do I need to decode the MP3 and mix it with the sound effects myself?

I can change to another library if necessary.

genpfault
  • 51,148
  • 11
  • 85
  • 139
MK Wong
  • 95
  • 5

1 Answers1

0

you have to create a thread that play your MP3 , you can use the "pthread lib " you just have to add the pthread lib in your project ( do not need to download anything )

in a thread your song will be running without distrurb your main

i write you an example using thread

#include <pthread.h>

void * Play(void * ptr)
{
   /*
      HERE PLAY your MP3 
      you can also do a loop inside your thread
   */


   return NULL;
}

//in your main for example
int main()
{

    //create a thread that play yout song in backround of main 
    pthread_t thread_play_MP3;
    pthread_create(&thread_play_MP3,NULL,Play,NULL);

    while(1)
    {
       //  HERE : your main code 
    }

    return 0;
}
psykoblast
  • 116
  • 1
  • 6