From a2090150615b96e040324d471c6fd0bd53360eb8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 24 Nov 2008 00:50:49 +0000 Subject: Remove aplay fallback stuff Attempt to re-open audio if it didn't work before --- src/audio.c | 46 ++++++++++++++++------------------------------ src/types.h | 2 -- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/audio.c b/src/audio.c index 56803fa..7464bea 100644 --- a/src/audio.c +++ b/src/audio.c @@ -70,35 +70,22 @@ void audio_trigger_moo() { AudioContext *a = audio_context; + if ( a == NULL ) { + /* Try to open the audio again */ + printf("Trying to open the audio again...\n"); + audio_setup(); + a = audio_context; + if ( a == NULL ) return; + } if ( a->mootex != 0 ) return; printf("Moo!\n"); a->mootex = 1; - if ( a->aplay_fallback ) { - - pid_t pid; - int status; - - pid = fork(); - if ( !( (pid != 0) && (pid != -1) ) ) { - if ( pid == -1 ) { - fprintf(stderr, "fork() failed.\n"); - return; - } else { - /* Forked successfully, child process */ - execlp("aplay", "aplay", DATADIR"/openmoocow/moo.wav", NULL); - } - } /* else forked successfully, parent process */ - waitpid(pid, &status, 0); - a->mootex = 0; - - } else { - if ( a->moo_pos == a->moo_len ) { - a->moo_pos = 0; - } + if ( a->moo_pos == a->moo_len ) { + a->moo_pos = 0; } - + } /* SDL audio initial setup */ @@ -114,8 +101,6 @@ void audio_setup() { /* Create audio context */ a = malloc(sizeof(AudioContext)); assert(a != NULL); - audio_context = a; - a->mootex = 0; /* 16-bit mono audio at 44.1 kHz */ @@ -129,19 +114,20 @@ void audio_setup() { if ( SDL_OpenAudio(&fmt, NULL) < 0 ) { fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); - a->aplay_fallback = 1; + free(a); return; } - a->aplay_fallback = 0; if ( SDL_LoadWAV(DATADIR"/openmoocow/moo.wav", &wave, &data, &dlen) == NULL ) { fprintf(stderr, "Couldn't load moo sound: %s\n", SDL_GetError()); + free(a); return; } SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq, AUDIO_S16, 1, 44100); cvt.buf = malloc(dlen*cvt.len_mult); if ( cvt.buf == NULL ) { fprintf(stderr, "Not enough memory to convert audio \n"); + free(a); return; } memcpy(cvt.buf, data, dlen); @@ -153,6 +139,8 @@ void audio_setup() { a->moo_pos = a->moo_len; /* Play nothing to start with */ a->moo_buf = (Sint16 *)cvt.buf; + audio_context = a; + SDL_PauseAudio(0); } @@ -161,9 +149,7 @@ void audio_shutdown(AudioContext *a) { if ( a == NULL ) return; - if ( !a->aplay_fallback ) { - SDL_CloseAudio(); - } + SDL_CloseAudio(); /* Now this can be freed */ free(a); diff --git a/src/types.h b/src/types.h index 89ff7f4..b864742 100644 --- a/src/types.h +++ b/src/types.h @@ -58,8 +58,6 @@ typedef struct { long moo_pos; Sint16 *moo_buf; - int aplay_fallback; - unsigned int mootex; } AudioContext; -- cgit v1.2.3