From bab7d0f6e7266f5b34c0a8ac4a826de774a3a6a1 Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 22 Oct 2008 16:46:44 +0000 Subject: [PATCH] reset audio on game load, powernes when 'reset' selected --- source/ngc/fceugx.c | 2 +- source/ngc/fceuload.c | 2 ++ source/ngc/gcaudio.c | 41 +++++++++++++++++++++++++++++++++++------ source/ngc/gcaudio.h | 3 ++- source/ngc/menu.c | 3 ++- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/source/ngc/fceugx.c b/source/ngc/fceugx.c index 9b9526c..8739ed6 100644 --- a/source/ngc/fceugx.c +++ b/source/ngc/fceugx.c @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) while (1); } - InitialiseSound(); + InitialiseAudio(); fatInit (8, false); #ifndef HW_RVL DVD_Init(); diff --git a/source/ngc/fceuload.c b/source/ngc/fceuload.c index 7afc3d7..356cb65 100644 --- a/source/ngc/fceuload.c +++ b/source/ngc/fceuload.c @@ -24,6 +24,7 @@ #include "sound.h" #include "file.h" +#include "gcaudio.h" #include "common.h" #include "pad.h" #include "menudraw.h" @@ -157,6 +158,7 @@ int GCMemROM(int method, int size) FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. SetSoundVariables(); + ResetAudio(); romLoaded = true; return 1; } diff --git a/source/ngc/gcaudio.c b/source/ngc/gcaudio.c index 226b481..8e66a21 100644 --- a/source/ngc/gcaudio.c +++ b/source/ngc/gcaudio.c @@ -23,7 +23,13 @@ static int mixtail = 0; static int whichab = 0; int IsPlaying = 0; -static int mixercollect( u8 *outbuffer, int len ) +/**************************************************************************** + * MixerCollect + * + * Collects sound samples from mixbuffer and puts them into outbuffer + * Makes sure to align them to 32 bytes for AUDIO_InitDMA + ***************************************************************************/ +static int MixerCollect( u8 *outbuffer, int len ) { u32 *dst = (u32 *)outbuffer; u32 *src = (u32 *)mixbuffer; @@ -54,12 +60,12 @@ static int mixercollect( u8 *outbuffer, int len ) * AudioSwitchBuffers * * Manages which buffer is played next - ****************************************************************************/ + ***************************************************************************/ void AudioSwitchBuffers() { if ( !ConfigRequested ) { - int len = mixercollect( soundbuffer[whichab], 3840 ); + int len = MixerCollect( soundbuffer[whichab], 3840 ); DCFlushRange(soundbuffer[whichab], len); AUDIO_InitDMA((u32)soundbuffer[whichab], len); AUDIO_StartDMA(); @@ -69,7 +75,12 @@ void AudioSwitchBuffers() else IsPlaying = 0; } -void InitialiseSound() +/**************************************************************************** + * InitialiseAudio + * + * Initializes sound system on first load of emulator + ***************************************************************************/ +void InitialiseAudio() { AUDIO_Init(NULL); // Start audio subsystem AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); @@ -78,6 +89,11 @@ void InitialiseSound() memset(mixbuffer, 0, 16000); } +/**************************************************************************** + * StopAudio + * + * Pause audio output when returning to menu + ***************************************************************************/ void StopAudio() { AUDIO_StopDMA(); @@ -86,9 +102,22 @@ void StopAudio() } /**************************************************************************** - * Audio incoming is monaural + * ResetAudio * - * PlaySound will simply mix to get it right + * Reset audio output when loading a new game + ***************************************************************************/ +void ResetAudio() +{ + memset(soundbuffer, 0, 3840*2); + memset(mixbuffer, 0, 16000); + mixhead = mixtail = 0; +} + +/**************************************************************************** + * PlaySound + * + * Puts incoming mono samples into mixbuffer + * Splits mono samples into two channels (stereo) ****************************************************************************/ void PlaySound( int *Buffer, int count ) { diff --git a/source/ngc/gcaudio.h b/source/ngc/gcaudio.h index 25db73a..5e3bdbd 100644 --- a/source/ngc/gcaudio.h +++ b/source/ngc/gcaudio.h @@ -10,6 +10,7 @@ * Audio driver ****************************************************************************/ -void InitialiseSound(); +void InitialiseAudio(); void StopAudio(); +void ResetAudio(); void PlaySound( int *Buffer, int samples ); diff --git a/source/ngc/menu.c b/source/ngc/menu.c index d625e4b..733473b 100644 --- a/source/ngc/menu.c +++ b/source/ngc/menu.c @@ -38,6 +38,7 @@ #include "fceuload.h" extern void ResetNES(void); +extern void PowerNES(void); extern void FCEU_ResetPalette(void); extern int menu; @@ -389,7 +390,7 @@ GameMenu () break; case 1: // Reset Game - ResetNES(); + PowerNES(); quit = retval = 1; break;