New and updated SVG artwork, referee, clean-up
[tennix.git] / sound.c
blob2b695e695e43a2b69ec19b1d903b546b6162aab4
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
6 *
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,
20 * MA 02110-1301, USA.
22 **/
24 #include "tennix.h"
25 #include "sound.h"
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);
50 } else {
51 fprintf( stderr, "Error: %s\n", Mix_GetError());
55 void fade_out( unsigned char channel) {
56 Mix_FadeOutChannel( channel, FADE_OUT_MS);
59 void sound_ground() {
60 ResourceData sounds[] = { RESOURCE(ground1), RESOURCE(ground2) };
61 play_sample( sounds[rand()%2], CH_GROUND, 0);
64 void sound_racket() {
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);
81 void sound_out() {
82 play_sample( RESOURCE(out), CH_OUT, 0);