Tutorial: playing sound ======================= Example for basic sound functions. step 1 At first we have to initialize VgaGames and open a window or switch to graphical screen. ==>
int main(int argc, char ** argv) { char * arg0; // for the name of the program char buf[64]; // for explaining text int lastvol; /* initialize vgagames, always pass argv[0] */ if (vg_init_vgagames(argv[0],0,NULL) < 0) {exit(1);} /* open window */ if ((arg0=strrchr(argv[0],'/'))==NULL) {arg0=argv[0];} else {arg0++;} if (vg_window_open(arg0,0,0) < 0) {exit(1);} |
/* start soundserver */ if (vg_sound_startserver(0,0,NULL) < 0) {vg_window_close(); exit(1);} /* load midi-file attaching it to nickname "s-music" using orignal volume */ vg_sound_attach("sound/phatjail.mid","s-music",100); |
/* start midi-file becoming louder for 5 seconds up to its normal volume */ vg_sound_play("s-music",5,1); sleep(5); /* music is playing */ sleep(5); /* pausing midi-file */ vg_sound_paus("s-music"); sleep(3); /* continuing midi-file */ vg_sound_cont("s-music"); sleep(5); /* changing main volume */ lastvol=vg_sound_volm("0",-1); /* get current volume */ vg_sound_volm("0",lastvol+10); /* add 10 to current volume */ sleep(3); /* stopping music */ vg_sound_stop("s-music",5); sleep(5); /* music is stopped */ sleep(3); /* end soundserver and close window */ vg_sound_endserver(); vg_window_close(); exit(0); } |