5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 static char datadir
[MAXPATHLEN
];
29 void init_sound( const char *data_dir
) {
30 strcpy( datadir
, data_dir
);
32 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
33 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
37 void play_sample( const char* filename
, unsigned char channel
, int loop
) {
38 static Mix_Chunk
* chunks
[CH_MAX
] = { 0 };
42 strcat( fn
, filename
);
44 if( chunks
[channel
] != NULL
) {
45 Mix_FreeChunk( chunks
[channel
]);
46 chunks
[channel
] = NULL
;
49 chunks
[channel
] = Mix_LoadWAV( fn
);
50 if( chunks
[channel
] != NULL
) {
51 Mix_PlayChannel( channel
, chunks
[channel
], loop
);
53 fprintf( stderr
, "Error: %s\n", Mix_GetError());
57 void fade_out( unsigned char channel
) {
58 Mix_FadeOutChannel( channel
, FADE_OUT_MS
);
62 const char* sounds
[] = { "ground1.wav", "ground2.wav" };
63 play_sample( sounds
[rand()%2], CH_GROUND
, 0);
66 void sound_racket( unsigned char powershot
) {
67 const char* sounds
[] = { "racket1.wav", "racket2.wav" };
69 play_sample( "powershot.wav", CH_RACKET
, 0);
71 play_sample( sounds
[rand()%2], CH_RACKET
, 0);
75 void sound_audience() {
76 play_sample( "audience.wav", CH_AUDIENCE
, -1);
79 void sound_applause() {
80 play_sample( "applause.wav", CH_APPLAUSE
, 0);
83 void sound_applause_stop() {
84 fade_out( CH_APPLAUSE
);