struct voice *next;
};
+static int audio_state = 0;
static float sound_vol = 1.0f;
static float music_vol = 1.0f;
void audio_init(void)
{
+ audio_state = 0;
/* Configure the audio. */
if (SDL_OpenAudio(&spec, NULL) == 0)
{
+ audio_state = 1;
SDL_PauseAudio(0);
}
else fprintf(stderr, "%s\n", SDL_GetError());
void audio_play(const char *filename, float a)
{
- struct voice *V;
+ if (audio_state)
+ {
+ struct voice *V;
- /* If we're already playing this sound, preempt the running copy. */
+ /* If we're already playing this sound, preempt the running copy. */
- for (V = voices; V; V = V->next)
- if (strcmp(V->name, filename) == 0)
- {
- ov_raw_seek(&V->vf, 0);
+ for (V = voices; V; V = V->next)
+ if (strcmp(V->name, filename) == 0)
+ {
+ ov_raw_seek(&V->vf, 0);
- V->amp = a;
+ V->amp = a;
- if (V->amp > 1.0) V->amp = 1.0;
- if (V->amp < 0.0) V->amp = 0.0;
+ if (V->amp > 1.0) V->amp = 1.0;
+ if (V->amp < 0.0) V->amp = 0.0;
- return;
- }
+ return;
+ }
- /* Create a new voice structure. */
+ /* Create a new voice structure. */
- V = voice_init(filename, a);
+ V = voice_init(filename, a);
- /* Add it to the list of sounding voices. */
+ /* Add it to the list of sounding voices. */
- SDL_LockAudio();
- {
- V->next = voices;
- voices = V;
+ SDL_LockAudio();
+ {
+ V->next = voices;
+ voices = V;
+ }
+ SDL_UnlockAudio();
}
- SDL_UnlockAudio();
}
/*---------------------------------------------------------------------------*/
void audio_music_play(const char *filename)
{
- audio_music_stop();
-
- SDL_LockAudio();
+ if (audio_state)
{
- if ((music = voice_init(filename, 0.0f)))
+ audio_music_stop();
+
+ SDL_LockAudio();
{
- music->loop = 1;
+ if ((music = voice_init(filename, 0.0f)))
+ {
+ music->loop = 1;
+ }
}
+ SDL_UnlockAudio();
}
- SDL_UnlockAudio();
}
-void audio_music_queue(const char *filename)
+void audio_music_queue(const char *filename, float t)
{
- SDL_LockAudio();
+ if (audio_state)
{
- if ((queue = voice_init(filename, 0.0f)))
+ SDL_LockAudio();
{
- queue->loop = 1;
+ if ((queue = voice_init(filename, 0.0f)))
+ {
+ queue->loop = 1;
+
+ if (t > 0.0f)
+ queue->damp = +1.0f / (AUDIO_RATE * t);
+ }
}
+ SDL_UnlockAudio();
}
- SDL_UnlockAudio();
}
void audio_music_stop(void)
{
- SDL_LockAudio();
+ if (audio_state)
{
- if (music)
+ SDL_LockAudio();
{
- voice_free(music);
+ if (music)
+ {
+ voice_free(music);
+ }
+ music = NULL;
}
- music = NULL;
+ SDL_UnlockAudio();
}
- SDL_UnlockAudio();
}
/*---------------------------------------------------------------------------*/
{
if (music)
{
- if (strcmp(filename, music->name))
+ if (strcmp(filename, music->name) != 0)
{
- audio_music_queue(filename);
audio_music_fade_out(t);
-
- if (queue) queue->damp = +1.0f / (AUDIO_RATE * t);
+ audio_music_queue(filename, t);
}
else audio_music_fade_in(t);
}