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