use pngs instead of bmps
[tennix.git] / sound.c
blob27c6dd6ada5a2d3f694110a20db30744f87041fd
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 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 };
39 char fn[MAXPATHLEN];
41 strcpy( fn, datadir);
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);
52 } else {
53 fprintf( stderr, "Error: %s\n", Mix_GetError());
57 void fade_out( unsigned char channel) {
58 Mix_FadeOutChannel( channel, FADE_OUT_MS);
61 void sound_ground() {
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" };
68 if( powershot) {
69 play_sample( "powershot.wav", CH_RACKET, 0);
70 } else {
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);