繁体   English   中英

使用SDL在后台播放MP3时产生声音效果

[英]Generating sound effect while playing MP3 in the background in with SDL

我正在编写一个程序,该程序会不断生成声音效果,并将其输出到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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM