[英]Playing sound file in C with Allegro5
I am trying to play wav file in C with allegro5 and I wrote below code: 我正在尝试使用allegro5在C中播放wav文件,并编写了以下代码:
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if (!al_init()){
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
if (!al_install_audio()){
fprintf(stderr, "failed to initialize audio!\n");
return -1;
}
if (!al_init_acodec_addon()){
fprintf(stderr, "failed to initialize audio codecs!\n");
return -1;
}
if (!al_reserve_samples(1)){
fprintf(stderr, "failed to reserve samples!\n");
return -1;
}
al_install_audio();
al_init_acodec_addon();
ALLEGRO_SAMPLE *sample = al_load_sample("bomb.wav"); //sample always NULL
al_reserve_samples(1);
if (!sample){
printf("Audio clip sample not loaded!\n");
return -1;
}
display = al_create_display(640, 480);
if (!display){
fprintf(stderr, "failed to create display!\n");
return -1;
}
/* Loop the sample until the display closes. */
al_play_sample(sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
al_rest(10.0);
al_destroy_display(display);
al_destroy_sample(sample);
return 0;
}
I debuged this in visual studio 2013 and sample always NULL . 我在Visual Studio 2013中对此进行了调试,并始终采样NULL 。 I am tried some variety format.
我尝试了多种格式。
Ex: ALLEGRO_SAMPLE *sample = al_load_sample("\\\\bomb.wav");
例如:
ALLEGRO_SAMPLE *sample = al_load_sample("\\\\bomb.wav");
ALLEGRO_SAMPLE *sample = al_load_sample("Resource Files\\bomb.wav");
ALLEGRO_SAMPLE *sample = al_load_sample("\\Resource Files\\bomb.wav");
ALLEGRO_SAMPLE *sample = al_load_sample("C:\\bomb.wav");//after copied in C drive
ALLEGRO_SAMPLE *sample = al_load_sample("C:/bomb.wav");
and etc. 等等。
I am confused. 我很困惑。 How can I succeed this problem.
我该如何解决这个问题。 Thanks in advance.
提前致谢。 Sorry language.
抱歉的语言。
ALLEGRO_SAMPLE *sample = al_load_sample("bomb.ogg"); //convert to ogg file your link
它为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.