私は、効果音を常に生成し、SDL コールバック関数のサウンド バッファーに出力するプログラムを書いています。バックグラウンドでMP3も再生する必要があります。どうすればいいですか?自分で MP3 をデコードして効果音とミックスする必要がありますか?
必要に応じて別のライブラリに変更できます。
MP3 を再生するスレッドを作成する必要があります。「pthread lib」を使用できます。プロジェクトに pthread lib を追加するだけです (何もダウンロードする必要はありません)。
スレッドでは、あなたのメインを邪魔することなくあなたの歌が流れます
スレッドを使用して例を書きます
#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;
}