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,
34 static char* samples
[] = {
47 #ifdef HAVE_VOICE_FILES
59 "advantage-player-one.ogg",
60 "advantage-player-two.ogg",
79 "in-the-first-set.ogg",
80 "in-the-second-set.ogg",
81 "in-the-third-set.ogg",
82 "in-the-fourth-set.ogg",
83 "in-the-fifth-set.ogg",
104 static sound_id voice_queue
[VOICE_QUEUE_MAX
];
105 static int voice_queue_size
= 0;
106 static int voice_queue_position
= 0;
108 int voice_finished_flag
= 1;
113 TennixArchive
* tnxar
;
115 if( Mix_OpenAudio( 44100, AUDIO_S16SYS
, 2, 1024) < 0) {
116 fprintf( stderr
, "Error initializing SDL_mixer: %s\n", Mix_GetError());
119 sounds
= (Sound
*)calloc(SOUND_MAX
, sizeof(Sound
));
121 rectangle(40, (HEIGHT
-40)/2, WIDTH
-80, 40, 100, 100, 100);
125 tnxar
= tnxar_open(ARCHIVE_FILE
);
127 for( i
=0; i
<SOUND_MAX
; i
++) {
128 if (tnxar_set_current_filename(tnxar
, samples
[i
]) != 0) {
129 data
= Mix_LoadWAV_RW(SDL_RWFromMem(tnxar_read_current(tnxar
), tnxar_size_current(tnxar
)), 1);
131 fprintf(stderr
, "Cannot find %s\n", samples
[i
]);
135 fprintf( stderr
, "Error: %s\n", SDL_GetError());
139 sounds
[i
].data
= data
;
141 rectangle(40, (HEIGHT
-40)/2, (WIDTH
-80)*(GR_COUNT
+i
)/(SOUND_MAX
+GR_COUNT
), 40, 100, 250, 100);
142 rectangle(40, (HEIGHT
-40)/2+20, (WIDTH
-80)*(GR_COUNT
+i
)/(SOUND_MAX
+GR_COUNT
), 10, 170, 250, 170);
152 /* for Voice Queue processing */
153 Mix_ChannelFinished(voice_channel_finished
);
156 void play_sample_n(sound_id id
, int n
)
158 if (id
>= SOUND_MAX
) {
159 fprintf(stderr
, "Cannot play sound #%d.\n", id
);
164 Mix_FadeInChannel(CHANNEL_BY_ID(id
), sounds
[id
].data
, -1, FADE_IN_MS
);
166 Mix_PlayChannel(CHANNEL_BY_ID(id
), sounds
[id
].data
, n
);
169 /* Audience stops clapping when ball is served */
170 if (id
>= SOUND_RACKET_FIRST
&& id
<= SOUND_RACKET_LAST
) {
171 stop_sample(SOUND_APPLAUSE
);
175 void stop_sample(sound_id id
)
177 Mix_FadeOutChannel(CHANNEL_BY_ID(id
), FADE_OUT_MS
);
180 void pan_sample(sound_id id
, float position
)
182 if (position
== 0.5) {
183 Mix_SetPanning(CHANNEL_BY_ID(id
), 255, 255);
186 Mix_SetPanning(CHANNEL_BY_ID(id
), 255*(1.0-position
), 255*(position
));
192 voice_queue_size
= 0;
193 Mix_HaltChannel(CHANNEL_VOICE
);
196 void voice_enqueue(sound_id id
)
198 if (voice_queue_size
< VOICE_QUEUE_MAX
) {
199 voice_queue
[voice_queue_size
++] = id
;
201 fprintf(stderr
, "Voice queue overflow. Skipping: %d\n", id
);
207 if (voice_queue_size
> 0) {
208 voice_queue_position
= 0;
209 voice_finished_flag
= 0;
210 Mix_PlayChannel(CHANNEL_VOICE
, sounds
[voice_queue
[voice_queue_position
]].data
, 0);
211 voice_queue_position
++;
215 void voice_say_list(int n
, ...)
224 for (i
=0; i
<n
; i
++) {
225 id
= (sound_id
)va_arg(ap
, int);
232 void voice_channel_finished(int channel
)
234 if (channel
== CHANNEL_VOICE
) {
235 if (voice_queue_position
< voice_queue_size
) {
236 Mix_PlayChannel(CHANNEL_VOICE
, sounds
[voice_queue
[voice_queue_position
]].data
, 0);
237 voice_queue_position
++;
239 voice_finished_flag
= 1;
240 voice_queue_position
= 0;