Also add PNG files to binary release
[tennix.git] / sound.c
blobac917d8d3399177e6eaa1c0b2b72ea95a01dc85e
1 #include <SDL/SDL_mixer.h>
3 #include "tennix.h"
4 #include "sound.h"
6 void init_sound() {
7 if( Mix_OpenAudio( 44100, AUDIO_S16SYS, 2, 1024) < 0) {
8 fprintf( stderr, "Error initializing SDL_mixer: %s\n", Mix_GetError());
12 void play_sample( const char* filename, unsigned char channel, int loop) {
13 static Mix_Chunk* chunks[CH_MAX] = { 0 };
15 if( chunks[channel] != NULL) {
16 Mix_FreeChunk( chunks[channel]);
17 chunks[channel] = NULL;
20 chunks[channel] = Mix_LoadWAV( filename);
21 if( chunks[channel] != NULL) {
22 Mix_PlayChannel( channel, chunks[channel], loop);
26 void fade_out( unsigned char channel) {
27 Mix_FadeOutChannel( channel, FADE_OUT_MS);
30 void sound_ground() {
31 const char* sounds[] = { "data/ground1.wav", "data/ground2.wav" };
32 play_sample( sounds[rand()%2], CH_GROUND, 0);
35 void sound_racket( unsigned char powershot) {
36 const char* sounds[] = { "data/racket1.wav", "data/racket2.wav" };
37 if( powershot) {
38 play_sample( "data/powershot.wav", CH_RACKET, 0);
39 } else {
40 play_sample( sounds[rand()%2], CH_RACKET, 0);
44 void sound_audience() {
45 play_sample( "data/audience.wav", CH_AUDIENCE, -1);
48 void sound_applause() {
49 play_sample( "data/applause.wav", CH_APPLAUSE, 0);
52 void sound_applause_stop() {
53 fade_out( CH_APPLAUSE);