diff --git a/source/ngc/audio.cpp b/source/ngc/audio.cpp index 463080f..c98216b 100644 --- a/source/ngc/audio.cpp +++ b/source/ngc/audio.cpp @@ -21,7 +21,50 @@ static int tail = 0; static u8 mixerdata[MIXBUFFSIZE]; #define MIXERMASK ((MIXBUFFSIZE >> 2) - 1) -static u8 soundbuffer[3200] ATTRIBUTE_ALIGN(32); +static u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); +extern int ConfigRequested; +static int whichab = 0; +int IsPlaying = 0; + +/**************************************************************************** + * MIXER_GetSamples + ***************************************************************************/ +static int MIXER_GetSamples( u8 *dstbuffer, int maxlen ) +{ + u32 *src = (u32 *)mixerdata; + u32 *dst = (u32 *)dstbuffer; + u32 intlen = maxlen >> 2; + + memset(dstbuffer, 0, maxlen); + + while( ( head != tail ) && intlen ) + { + *dst++ = src[tail++]; + tail &= MIXERMASK; + intlen--; + } + + return 3200; +} + +/**************************************************************************** + * MIXER_GetSamples + ***************************************************************************/ + +static void AudioPlayer() +{ + if ( !ConfigRequested ) + { + int len = MIXER_GetSamples(soundbuffer[whichab], 3200); + DCFlushRange(soundbuffer[whichab],len); + AUDIO_InitDMA((u32)soundbuffer[whichab],len); + AUDIO_StartDMA(); + whichab ^= 1; + IsPlaying = 1; + } + else + IsPlaying = 0; +} /**************************************************************************** * MIXER_AddSamples @@ -54,57 +97,44 @@ void MIXER_AddSamples( u8 *sampledata, int len ) fixofs += fixinc; } while( --intlen ); + + // Restart Sound Processing if stopped + if (IsPlaying == 0) + { + ConfigRequested = 0; + AudioPlayer(); + } } /**************************************************************************** -* MIXER_GetSamples -****************************************************************************/ -int MIXER_GetSamples( u8 *dstbuffer, int maxlen ) -{ - u32 *src = (u32 *)mixerdata; - u32 *dst = (u32 *)dstbuffer; - u32 intlen = maxlen >> 2; - - memset(dstbuffer, 0, maxlen); - - while( ( head != tail ) && intlen ) - { - *dst++ = src[tail++]; - tail &= MIXERMASK; - intlen--; - } - - return 3200; -} - -static void AudioPlayer() -{ - AUDIO_StopDMA(); - MIXER_GetSamples(soundbuffer, 3200); - DCFlushRange(soundbuffer,3200); - AUDIO_InitDMA((u32)soundbuffer,3200); - AUDIO_StartDMA(); -} + * MIXER_GetSamples + ***************************************************************************/ void InitialiseSound() { AUDIO_Init(NULL); // Start audio subsystem AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); AUDIO_RegisterDMACallback(AudioPlayer); - memset(soundbuffer, 0, 3200); + memset(soundbuffer, 0, 3840*2); + memset(mixerdata, 0, MIXBUFFSIZE); } +/**************************************************************************** + * MIXER_GetSamples + ***************************************************************************/ + void ResetAudio() { - memset(soundbuffer, 0, 3200); + memset(soundbuffer, 0, 3840*2); + memset(mixerdata, 0, MIXBUFFSIZE); } +/**************************************************************************** + * MIXER_GetSamples + ***************************************************************************/ + void StopAudio() { AUDIO_StopDMA(); -} - -void StartAudio() -{ - AUDIO_StartDMA(); + IsPlaying = 0; } diff --git a/source/ngc/audio.h b/source/ngc/audio.h index 9a68471..6ae5fd1 100644 --- a/source/ngc/audio.h +++ b/source/ngc/audio.h @@ -12,9 +12,7 @@ #define __AUDIOMIXER__ void MIXER_AddSamples( u8 *sampledata, int len ); -int MIXER_GetSamples( u8 *dstbuffer, int maxlen ); void StopAudio(); -void StartAudio(); void ResetAudio(); void InitialiseSound(); diff --git a/source/ngc/input.cpp b/source/ngc/input.cpp index 17e1c45..4e2e1e2 100644 --- a/source/ngc/input.cpp +++ b/source/ngc/input.cpp @@ -20,6 +20,7 @@ #include "vba.h" #include "button_mapping.h" +#include "audio.h" #include "video.h" #include "input.h" #include "tbtime.h" @@ -298,6 +299,7 @@ u32 GetJoy(int pad) #endif ) { + StopAudio(); ConfigRequested = 1; return 0; } diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 9a7252a..8207576 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -646,7 +646,6 @@ MainMenu (int selectedMenu) { tb_t start,end; mftb(&start); - StopAudio(); int quit = 0; int ret; @@ -738,7 +737,6 @@ MainMenu (int selectedMenu) count++; } - StartAudio(); mftb(&end); loadtimeradjust += tb_diff_msec(&end, &start); }