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
[] = {
48 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
49 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
52 sounds
= (Sound
*)calloc(SOUND_MAX
, sizeof(Sound
));
54 for( i
=0; i
<SOUND_MAX
; i
++) {
55 data
= Mix_LoadWAV_RW(SDL_RWFromConstMem(samples
[i
].data
, samples
[i
].size
), 1);
57 fprintf( stderr
, "Error: %s\n", SDL_GetError());
61 sounds
[i
].data
= data
;
66 void play_sample_n(sound_id id
, int n
)
68 if (id
>= SOUND_MAX
) {
69 fprintf(stderr
, "Cannot play sound #%d.\n", id
);
74 Mix_FadeInChannel(id
%8, sounds
[id
].data
, -1, FADE_IN_MS
);
76 Mix_PlayChannel(id
%8, sounds
[id
].data
, n
);
79 /* Audience stops clapping when ball is served */
80 if (id
>= SOUND_RACKET_FIRST
&& id
<= SOUND_RACKET_LAST
) {
81 stop_sample(SOUND_APPLAUSE
);
85 void stop_sample(sound_id id
)
87 Mix_FadeOutChannel(id
%8, FADE_OUT_MS
);
90 void pan_sample(sound_id id
, float position
)
92 if (position
== 0.5) {
93 Mix_SetPanning(id
%8, 255, 255);
96 Mix_SetPanning(id
%8, 255*(1.0-position
), 255*(position
));