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,
31 #include "data/sounds_data.c"
32 static const ResourceData samples
[] = {
45 #ifdef HAVE_VOICE_FILES
51 RESOURCE(fifteen_out
),
57 RESOURCE(advantage_player_one
),
58 RESOURCE(advantage_player_two
),
77 RESOURCE(in_the_first_set
),
78 RESOURCE(in_the_second_set
),
79 RESOURCE(in_the_third_set
),
80 RESOURCE(in_the_fourth_set
),
81 RESOURCE(in_the_fifth_set
),
102 static sound_id voice_queue
[VOICE_QUEUE_MAX
];
103 static int voice_queue_size
= 0;
104 static int voice_queue_position
= 0;
106 int voice_finished_flag
= 1;
112 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
113 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
116 sounds
= (Sound
*)calloc(SOUND_MAX
, sizeof(Sound
));
118 for( i
=0; i
<SOUND_MAX
; i
++) {
119 data
= Mix_LoadWAV_RW(SDL_RWFromConstMem(samples
[i
].data
, samples
[i
].size
), 1);
121 fprintf( stderr
, "Error: %s\n", SDL_GetError());
125 sounds
[i
].data
= data
;
128 /* for Voice Queue processing */
129 Mix_ChannelFinished(voice_channel_finished
);
132 void play_sample_n(sound_id id
, int n
)
134 if (id
>= SOUND_MAX
) {
135 fprintf(stderr
, "Cannot play sound #%d.\n", id
);
140 Mix_FadeInChannel(CHANNEL_BY_ID(id
), sounds
[id
].data
, -1, FADE_IN_MS
);
142 Mix_PlayChannel(CHANNEL_BY_ID(id
), sounds
[id
].data
, n
);
145 /* Audience stops clapping when ball is served */
146 if (id
>= SOUND_RACKET_FIRST
&& id
<= SOUND_RACKET_LAST
) {
147 stop_sample(SOUND_APPLAUSE
);
151 void stop_sample(sound_id id
)
153 Mix_FadeOutChannel(CHANNEL_BY_ID(id
), FADE_OUT_MS
);
156 void pan_sample(sound_id id
, float position
)
158 if (position
== 0.5) {
159 Mix_SetPanning(CHANNEL_BY_ID(id
), 255, 255);
162 Mix_SetPanning(CHANNEL_BY_ID(id
), 255*(1.0-position
), 255*(position
));
168 voice_queue_size
= 0;
169 Mix_HaltChannel(CHANNEL_VOICE
);
172 void voice_enqueue(sound_id id
)
174 if (voice_queue_size
< VOICE_QUEUE_MAX
) {
175 voice_queue
[voice_queue_size
++] = id
;
177 fprintf(stderr
, "Voice queue overflow. Skipping: %d\n", id
);
183 if (voice_queue_size
> 0) {
184 voice_queue_position
= 0;
185 voice_finished_flag
= 0;
186 Mix_PlayChannel(CHANNEL_VOICE
, sounds
[voice_queue
[voice_queue_position
]].data
, 0);
187 voice_queue_position
++;
191 void voice_say_list(int n
, ...)
200 for (i
=0; i
<n
; i
++) {
201 id
= (sound_id
)va_arg(ap
, int);
208 void voice_channel_finished(int channel
)
210 if (channel
== CHANNEL_VOICE
) {
211 if (voice_queue_position
< voice_queue_size
) {
212 Mix_PlayChannel(CHANNEL_VOICE
, sounds
[voice_queue
[voice_queue_position
]].data
, 0);
213 voice_queue_position
++;
215 voice_finished_flag
= 1;
216 voice_queue_position
= 0;