5 * Copyright (C) 2003, 2007, 2008 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,
29 #include "data/sounds_data.c"
30 static const ResourceData samples
[] = {
45 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
46 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
49 sounds
= (Sound
*)calloc(SOUND_MAX
, sizeof(Sound
));
51 for( i
=0; i
<SOUND_MAX
; i
++) {
52 data
= Mix_LoadWAV_RW(SDL_RWFromConstMem(samples
[i
].data
, samples
[i
].size
), 1);
54 fprintf( stderr
, "Error: %s\n", SDL_GetError());
58 sounds
[i
].data
= data
;
63 void play_sample_n(sound_id id
, int n
)
65 if (id
>= SOUND_MAX
) {
66 fprintf(stderr
, "Cannot play sound #%d.\n", id
);
71 Mix_FadeInChannel(id
, sounds
[id
].data
, -1, FADE_IN_MS
);
73 Mix_PlayChannel(id
, sounds
[id
].data
, n
);
76 if (id
== SOUND_RACKET
) {
77 stop_sample(SOUND_APPLAUSE
);
81 void stop_sample(sound_id id
)
83 Mix_FadeOutChannel(id
, FADE_OUT_MS
);
86 void pan_sample(sound_id id
, float position
)
88 if (position
== 0.5) {
89 Mix_SetPanning(id
, 255, 255);
92 Mix_SetPanning(id
, 255*(1.0-position
), 255*(position
));