1 /*
2 * XGalaga-SDL - a SDL port of XGalaga, clone of the game Galaga
3 * Copyright (c) 1995-1998 Joe Rumsey (mrogre@mediaone.net)
4 * Copyright (c) 1994 Sujal M. Patel (smpatel@wam.umd.edu)
5 * Copyright (c) 2000 Andy Tarkinson <atark@thepipeline.net>
6 * Copyright (c) 2010 Frank Zago
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24 #ifdef NOSOUND
25
init_sound()26 void init_sound () {}
sound_exit(void)27 void sound_exit(void) {}
play_sound(int sound)28 void play_sound (int sound) {}
29
30 #else
31 #include <SDL/SDL_mixer.h>
32
33 #include "xgalaga.h"
34
35 static int audioOK;
36
37 static const char *FILENAME[] = {
38 "explode.wav",
39 "firetorp.wav",
40 "shield.wav",
41 "torphit.wav",
42 "explode_big.wav",
43 "ddloo.wav",
44 "warp.wav",
45 "smart.wav",
46 };
47
48 #define NUM_SOUNDS (sizeof(FILENAME)/sizeof(char*))
49
50 static Mix_Chunk *sounds[NUM_SOUNDS];
51
init_sound(void)52 void init_sound (void)
53 {
54 unsigned int i;
55 char filename[MAXFILENAME];
56
57 /* Open the audio device */
58 if (Mix_OpenAudio(11025, AUDIO_U8, 1, 512) < 0 ) {
59 fprintf(stderr,
60 "Warning: Couldn't set 11025 Hz 8-bit audio\n- Reason: %s\n",
61 SDL_GetError());
62 return;
63 }
64
65 for (i=0; i<NUM_SOUNDS; i++) {
66 snprintf(filename, MAXFILENAME, "%s/sounds/%s", DATADIR, FILENAME[i]);
67 filename[MAXFILENAME-1] = '\0';
68 sounds[i] = Mix_LoadWAV(filename);
69
70 if (!sounds[i])
71 fprintf(stderr, "Warning: Couldn't load sound %s\n", filename);
72 }
73
74 audioOK = 1;
75 }
76
sound_exit(void)77 void sound_exit(void)
78 {
79 unsigned int i;
80
81 if (audioOK) {
82 Mix_CloseAudio();
83 for (i=0;i<NUM_SOUNDS;i++) {
84 Mix_FreeChunk(sounds[i]);
85 }
86 audioOK = 0;
87 }
88 }
89
play_sound(int sound)90 void play_sound (int sound)
91 {
92 if (audioOK && playSounds)
93 Mix_PlayChannel(sound, sounds[sound], 0);
94 }
95
96 #endif /* NOSOUND */
97