2 #include <SDL/SDL_mixer.h>
13 static Mix_Music *music[NUM_TUNES];
14 static int music_volume[NUM_TUNES] = {128,128,128};
15 static Mix_Chunk *wav[NUM_SOUNDS];
21 char *add_data_path(char *);
32 "music/4est_fulla3s.mod"
35 // Return 1 if the sound is ready to roll, and 0 if not.
41 // Initialise output with SDL_mixer
42 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 4096) < 0) {
43 fprintf(stderr, "Couldn't open SDL_mixer audio: %s\n", SDL_GetError());
47 // Preload all the tunes into memory
48 for (i=0; i<NUM_TUNES; i++) {
49 s = add_data_path(tune_file[i]);
51 music[i] = Mix_LoadMUS(s);
52 if(!music[i]) printf("Failed to load %s.\n", s);
57 // Preload all the wav files into memory
58 for (i=0; i<NUM_SOUNDS; i++) {
59 s = add_data_path(wav_file[i]);
61 wav[i] = Mix_LoadWAV(s);
71 if(!opt_sound) return;
72 Mix_PlayChannel(-1, wav[i], 0);
79 play_tune(int i) {/*{{{*/
80 if(!opt_music) return;
84 Mix_FadeOutMusic(1500);
86 Mix_FadeInMusic(music[i],-1,2000);
87 Mix_VolumeMusic(music_volume[i]);
94 * The init_sound() routine is called first.
95 * The play_sound() routine is called with the index number of the sound we wish to play.
96 * The play_tune() routine is called with the index number of the tune we wish to play.