2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
2008-09-12 07:28:40 +02:00
|
|
|
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* softdev July 2006
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* audio.cpp
|
2008-08-06 03:09:59 +02:00
|
|
|
*
|
2008-09-12 07:28:40 +02:00
|
|
|
* Audio driver
|
|
|
|
* Audio is fixed to 32Khz/16bit/Stereo
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-11 18:28:37 +01:00
|
|
|
#include <asndlib.h>
|
2008-09-12 07:28:40 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
2009-01-30 03:20:43 +01:00
|
|
|
#include "s9xdebug.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#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-12-30 01:08:17 +01:00
|
|
|
extern int ConfigRequested;
|
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
/*** Double buffered audio ***/
|
|
|
|
#define AUDIOBUFFER 2048
|
2008-12-30 01:08:17 +01:00
|
|
|
static unsigned char soundbuffer[2][AUDIOBUFFER] __attribute__ ((__aligned__ (32)));
|
2008-08-06 03:09:59 +02:00
|
|
|
static int whichab = 0; /*** Audio buffer flip switch ***/
|
|
|
|
|
|
|
|
#define AUDIOSTACK 16384
|
2008-12-30 01:08:17 +01:00
|
|
|
static lwpq_t audioqueue;
|
|
|
|
static lwp_t athread;
|
2008-08-06 03:09:59 +02:00
|
|
|
static uint8 astack[AUDIOSTACK];
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
2008-08-06 03:09:59 +02:00
|
|
|
* Audio Threading
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
static void *
|
|
|
|
AudioThread (void *arg)
|
|
|
|
{
|
2008-09-12 07:28:40 +02:00
|
|
|
LWP_InitQueue (&audioqueue);
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
while (1)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-09-12 07:28:40 +02:00
|
|
|
whichab ^= 1;
|
|
|
|
if (ConfigRequested)
|
|
|
|
memset (soundbuffer[whichab], 0, AUDIOBUFFER);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
so.samples_mixed_so_far = so.play_position = 0;
|
|
|
|
S9xMixSamples (soundbuffer[whichab], AUDIOBUFFER >> 1);
|
|
|
|
}
|
|
|
|
LWP_ThreadSleep (audioqueue);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
return NULL;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
2008-08-07 07:19:17 +02:00
|
|
|
* MixSamples
|
2008-09-12 07:28:40 +02:00
|
|
|
* This continually calls S9xMixSamples On each DMA Completion
|
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
static void
|
|
|
|
GCMixSamples ()
|
|
|
|
{
|
2009-03-11 18:28:37 +01:00
|
|
|
if (!ConfigRequested)
|
|
|
|
{
|
|
|
|
AUDIO_StopDMA ();
|
|
|
|
DCFlushRange (soundbuffer[whichab], AUDIOBUFFER);
|
|
|
|
AUDIO_InitDMA ((u32) soundbuffer[whichab], AUDIOBUFFER);
|
|
|
|
AUDIO_StartDMA ();
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2009-03-11 18:28:37 +01:00
|
|
|
LWP_ThreadSignal (audioqueue);
|
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
2009-03-12 08:07:52 +01:00
|
|
|
* InitAudio
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
void
|
2009-03-12 08:07:52 +01:00
|
|
|
InitAudio ()
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2009-06-13 10:40:45 +02:00
|
|
|
#ifdef NO_SOUND
|
|
|
|
AUDIO_Init (NULL);
|
2009-07-01 19:40:04 +02:00
|
|
|
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
|
|
|
|
AUDIO_RegisterDMACallback(GCMixSamples);
|
2009-06-13 10:40:45 +02:00
|
|
|
#else
|
|
|
|
ASND_Init();
|
|
|
|
#endif
|
2009-04-01 07:47:01 +02:00
|
|
|
LWP_CreateThread (&athread, AudioThread, NULL, astack, AUDIOSTACK, 100);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 20:03:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* SwitchAudioMode
|
|
|
|
*
|
|
|
|
* Switches between menu sound and emulator sound
|
|
|
|
***************************************************************************/
|
2009-03-11 18:28:37 +01:00
|
|
|
void
|
|
|
|
SwitchAudioMode(int mode)
|
|
|
|
{
|
|
|
|
if(mode == 0) // emulator
|
|
|
|
{
|
|
|
|
#ifndef NO_SOUND
|
|
|
|
ASND_Pause(1);
|
2009-06-13 10:40:45 +02:00
|
|
|
AUDIO_StopDMA();
|
2009-03-11 18:28:37 +01:00
|
|
|
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
|
|
|
|
AUDIO_RegisterDMACallback(GCMixSamples);
|
2009-06-13 19:48:03 +02:00
|
|
|
#endif
|
2009-03-11 18:28:37 +01:00
|
|
|
}
|
|
|
|
else // menu
|
|
|
|
{
|
|
|
|
#ifndef NO_SOUND
|
2009-06-13 19:48:03 +02:00
|
|
|
ASND_Init();
|
2009-03-11 18:28:37 +01:00
|
|
|
ASND_Pause(0);
|
2009-06-13 19:48:03 +02:00
|
|
|
#else
|
|
|
|
AUDIO_StopDMA();
|
2009-03-11 18:28:37 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-28 20:03:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ShutdownAudio
|
|
|
|
*
|
|
|
|
* Shuts down audio subsystem. Useful to avoid unpleasant sounds if a
|
|
|
|
* crash occurs during shutdown.
|
|
|
|
***************************************************************************/
|
2009-03-12 08:07:52 +01:00
|
|
|
void ShutdownAudio()
|
|
|
|
{
|
|
|
|
AUDIO_StopDMA();
|
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
2008-08-06 03:09:59 +02:00
|
|
|
* AudioStart
|
|
|
|
*
|
|
|
|
* Called to kick off the Audio Queue
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
void
|
|
|
|
AudioStart ()
|
|
|
|
{
|
2008-09-12 07:28:40 +02:00
|
|
|
GCMixSamples ();
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|