3 extern int sound_flag, music_flag;
5 #define CONDERROR(a) if ((a)) {fprintf(stderr,"Error: %s\n",SDL_GetError());exit(1);}
6 #define NULLERROR(a) CONDERROR((a)==NULL)
8 #define TUNE_TITLE_PAGE 0
9 #define TUNE_GAMEPLAY 1
10 #define TUNE_HIGH_SCORE_ENTRY 2
16 static Mix_Music *music[NUM_TUNES];
17 static int music_volume[NUM_TUNES] = {128,128,128};
18 static Mix_Chunk *wav[NUM_SOUNDS];
24 char *add_path(char *);
35 "music/4est_fulla3s.mod"
40 // Return 1 if the sound is ready to roll, and 0 if not.
44 printf ("Initialise sound\n");
47 // Initialise output with SDL_mixer
48 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 4096) < 0) {
49 fprintf(stderr, "Couldn't open SDL_mixer audio: %s\n", SDL_GetError());
54 // What kind of sound did we get? Ah who cares. As long as it can play
55 // some basic bangs and simple music.
56 Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
57 printf("Opened audio at %d Hz %d bit %s\n", audio_rate,
59 (audio_channels > 1) ? "stereo" : "mono");
62 // Preload all the tunes into memory
63 for (i=0; i<NUM_TUNES; i++) {
64 if (!(music[i] = Mix_LoadMUS(add_path(tune_file[i])))) {
65 printf ("Failed to load %s\n",add_path(tune_file[i]));
69 // Preload all the wav files into memory
70 for (i=0; i<NUM_SOUNDS; i++) {
71 wav[i] = Mix_LoadWAV(add_path(wav_file[i]));
79 if(!sound_flag) return;
81 printf ("play sound %d on first free channel\n",i);
83 Mix_PlayChannel(-1, wav[i], 0);
92 play_tune(int i) {/*{{{*/
93 if(!sound_flag || !music_flag) return;
97 Mix_FadeOutMusic(1500);
99 printf("Stop playing %d\n",playing);
103 printf ("Play music %d\n",i);
104 printf ("volume %d\n",music_volume[i]);
106 Mix_FadeInMusic(music[i],-1,2000);
107 Mix_VolumeMusic(music_volume[i]);
114 * The init_sound() routine is called first.
115 * The play_sound() routine is called with the index number of the sound we wish to play.
116 * The play_tune() routine is called with the index number of the tune we wish to play.