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 #include "data/sounds_data.c"
31 void init_sound( const char *data_dir
) {
32 strcpy( datadir
, data_dir
);
34 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
35 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
39 void play_sample( ResourceData sound
, unsigned char channel
, int loop
) {
40 static Mix_Chunk
* chunks
[CH_MAX
] = { 0 };
42 if( chunks
[channel
] != NULL
) {
43 Mix_FreeChunk( chunks
[channel
]);
44 chunks
[channel
] = NULL
;
47 chunks
[channel
] = Mix_LoadWAV_RW( SDL_RWFromConstMem( sound
.data
, sound
.size
), 1);
48 if( chunks
[channel
] != NULL
) {
49 Mix_PlayChannel( channel
, chunks
[channel
], loop
);
51 fprintf( stderr
, "Error: %s\n", Mix_GetError());
55 void fade_out( unsigned char channel
) {
56 Mix_FadeOutChannel( channel
, FADE_OUT_MS
);
60 ResourceData sounds
[] = { RESOURCE(ground1
), RESOURCE(ground2
) };
61 play_sample( sounds
[rand()%2], CH_GROUND
, 0);
65 ResourceData sounds
[] = { RESOURCE(racket1
), RESOURCE(racket2
) };
66 play_sample( sounds
[rand()%2], CH_RACKET
, 0);
69 void sound_audience() {
70 play_sample( RESOURCE(audience
), CH_AUDIENCE
, -1);
73 void sound_applause() {
74 play_sample( RESOURCE(applause
), CH_APPLAUSE
, 0);
77 void sound_applause_stop() {
78 fade_out( CH_APPLAUSE
);
82 play_sample( RESOURCE(out
), CH_OUT
, 0);