clean up audio code a little

This commit is contained in:
Daryl Borth 2018-08-22 20:52:19 -06:00
parent 5ec455b738
commit 3eebfa84fe

View File

@ -15,7 +15,8 @@
#include <asndlib.h> #include <asndlib.h>
#include "fceusupport.h" #include "fceusupport.h"
static u8 ConfigRequested = 0; extern int ScreenshotRequested;
extern int ConfigRequested;
static u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); static u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32);
static u8 mixbuffer[16000]; static u8 mixbuffer[16000];
static int mixhead = 0; static int mixhead = 0;
@ -64,15 +65,16 @@ static int MixerCollect( u8 *outbuffer, int len )
***************************************************************************/ ***************************************************************************/
static void AudioSwitchBuffers() static void AudioSwitchBuffers()
{ {
if ( !ConfigRequested ) if ( !ScreenshotRequested && !ConfigRequested ) {
{ IsPlaying = 1;
whichab ^= 1;
int len = MixerCollect( soundbuffer[whichab], 3840 ); int len = MixerCollect( soundbuffer[whichab], 3840 );
DCFlushRange(soundbuffer[whichab], len); DCFlushRange(soundbuffer[whichab], len);
AUDIO_InitDMA((u32)soundbuffer[whichab], len); AUDIO_InitDMA((u32)soundbuffer[whichab], len);
IsPlaying = 1; whichab ^= 1;
}
else {
IsPlaying = 0;
} }
else IsPlaying = 0;
} }
/**************************************************************************** /****************************************************************************
@ -123,12 +125,6 @@ SwitchAudioMode(int mode)
DSP_Halt(); DSP_Halt();
AUDIO_RegisterDMACallback(AudioSwitchBuffers); AUDIO_RegisterDMACallback(AudioSwitchBuffers);
#endif #endif
memset(soundbuffer[0],0,3840);
memset(soundbuffer[1],0,3840);
DCFlushRange(soundbuffer[0],3840);
DCFlushRange(soundbuffer[1],3840);
AUDIO_InitDMA((u32)soundbuffer[whichab],3200);
AUDIO_StartDMA();
} }
else // menu else // menu
{ {
@ -166,18 +162,17 @@ void PlaySound( int32 *Buffer, int count )
u16 sample; u16 sample;
u32 *dst = (u32 *)mixbuffer; u32 *dst = (u32 *)mixbuffer;
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ ) {
{
sample = Buffer[i] & 0xffff; sample = Buffer[i] & 0xffff;
dst[mixhead++] = sample | ( sample << 16); dst[mixhead++] = sample | ( sample << 16);
if (mixhead == 4000) if (mixhead == 4000) {
mixhead = 0; mixhead = 0;
}
} }
// Restart Sound Processing if stopped // Restart Sound Processing if stopped
if (IsPlaying == 0) if (IsPlaying == 0) {
{ AUDIO_StartDMA();
AudioSwitchBuffers ();
} }
} }