2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
2008-10-16 03:52:18 +02:00
|
|
|
* Snes9x 1.50
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-10-16 03:52:18 +02:00
|
|
|
* Nintendo Gamecube Audio
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* Audio is fixed to 32Khz/16bit/Stereo
|
2008-10-16 03:52:18 +02:00
|
|
|
*
|
|
|
|
* softdev July 2006
|
|
|
|
****************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "cpuexec.h"
|
|
|
|
#include "ppu.h"
|
|
|
|
#include "apu.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "soundux.h"
|
|
|
|
#include "spc700.h"
|
|
|
|
#include "spc7110.h"
|
|
|
|
#include "controls.h"
|
|
|
|
|
|
|
|
#include "video.h"
|
2008-10-16 03:52:18 +02:00
|
|
|
#include "ftfont.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
/*** Double buffered audio ***/
|
|
|
|
#define AUDIOBUFFER 2048
|
|
|
|
static unsigned char soundbuffer[2][AUDIOBUFFER]
|
|
|
|
__attribute__ ((__aligned__ (32)));
|
|
|
|
static int whichab = 0; /*** Audio buffer flip switch ***/
|
|
|
|
extern int ConfigRequested;
|
|
|
|
|
|
|
|
#define AUDIOSTACK 16384
|
|
|
|
lwpq_t audioqueue;
|
|
|
|
lwp_t athread;
|
|
|
|
static uint8 astack[AUDIOSTACK];
|
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
/**
|
2008-08-06 03:09:59 +02:00
|
|
|
* Audio Threading
|
2008-10-16 03:52:18 +02:00
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
static void *
|
|
|
|
AudioThread (void *arg)
|
|
|
|
{
|
2008-10-16 03:52:18 +02:00
|
|
|
LWP_InitQueue (&audioqueue);
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
whichab ^= 1;
|
|
|
|
if (ConfigRequested)
|
|
|
|
memset (soundbuffer[whichab], 0, AUDIOBUFFER);
|
|
|
|
else
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:52:18 +02:00
|
|
|
so.samples_mixed_so_far = so.play_position = 0;
|
|
|
|
S9xMixSamples (soundbuffer[whichab], AUDIOBUFFER >> 1);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
2008-10-16 03:52:18 +02:00
|
|
|
LWP_ThreadSleep (audioqueue);
|
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
return NULL;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
/**
|
|
|
|
* MixSamples
|
|
|
|
* This continually calls S9xMixSamples On each DMA Completion
|
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
static void
|
|
|
|
GCMixSamples ()
|
|
|
|
{
|
2008-10-16 03:52:18 +02:00
|
|
|
AUDIO_StopDMA ();
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
DCFlushRange (soundbuffer[whichab], AUDIOBUFFER);
|
|
|
|
AUDIO_InitDMA ((u32) soundbuffer[whichab], AUDIOBUFFER);
|
|
|
|
AUDIO_StartDMA ();
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
LWP_ThreadSignal (audioqueue);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
/**
|
|
|
|
* InitGCAudio
|
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
void
|
|
|
|
InitGCAudio ()
|
|
|
|
{
|
2008-10-16 03:52:18 +02:00
|
|
|
AUDIO_SetDSPSampleRate (AI_SAMPLERATE_32KHZ);
|
|
|
|
AUDIO_RegisterDMACallback (GCMixSamples);
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
LWP_CreateThread (&athread, AudioThread, NULL, astack, AUDIOSTACK, 80);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 03:52:18 +02:00
|
|
|
/**
|
2008-08-06 03:09:59 +02:00
|
|
|
* AudioStart
|
|
|
|
*
|
|
|
|
* Called to kick off the Audio Queue
|
2008-10-16 03:52:18 +02:00
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
void
|
|
|
|
AudioStart ()
|
|
|
|
{
|
2008-10-16 03:52:18 +02:00
|
|
|
GCMixSamples ();
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|