mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 05:24:21 +01:00
Use gc audio (not working yet)
This commit is contained in:
parent
4d09c7252b
commit
2cc88f4b8e
2
Makefile
2
Makefile
@ -58,7 +58,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
#---------------------------------------------------------------------------------
|
||||
# automatically build a list of object files for our project
|
||||
#---------------------------------------------------------------------------------
|
||||
CFILES := char_to_kc.c
|
||||
CFILES := char_to_kc.c gcaudio.c
|
||||
CPPFILES := Display.cpp main.cpp Prefs.cpp SID.cpp REU.cpp IEC.cpp 1541fs.cpp \
|
||||
1541d64.cpp 1541t64.cpp 1541job.cpp SAM.cpp C64.cpp CPUC64.cpp VIC.cpp \
|
||||
CIA.cpp CPU1541.cpp menu.cpp
|
||||
|
@ -269,6 +269,8 @@ void MOS6581::SetState(MOS6581State *ss)
|
||||
|
||||
#if defined(AMIGA) || defined(__riscos__)
|
||||
const uint32 SAMPLE_FREQ = 22050; // Sample output frequency in Hz
|
||||
#elif defined(GEKKO)
|
||||
const uint32 SAMPLE_FREQ = 48000;
|
||||
#else
|
||||
const uint32 SAMPLE_FREQ = 44100; // Sample output frequency in Hz
|
||||
#endif
|
||||
@ -1362,6 +1364,9 @@ void DigitalRenderer::calc_buffer(int16 *buf, long count)
|
||||
#elif defined(AMIGA)
|
||||
#include "SID_Amiga.i"
|
||||
|
||||
#elif defined(GEKKO)
|
||||
#include "SID_wii.i"
|
||||
|
||||
#elif defined(HAVE_SDL)
|
||||
#include "SID_SDL.i"
|
||||
|
||||
@ -1383,9 +1388,6 @@ void DigitalRenderer::calc_buffer(int16 *buf, long count)
|
||||
#elif defined(__riscos__)
|
||||
#include "SID_Acorn.i"
|
||||
|
||||
#elif defined(GEKKO)
|
||||
#include "SID_wii.i"
|
||||
|
||||
#else // No sound
|
||||
void DigitalRenderer::init_sound(void) {ready = false;}
|
||||
DigitalRenderer::~DigitalRenderer() {}
|
||||
|
93
Src/SID_wii.i
Normal file
93
Src/SID_wii.i
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* SID_linux.i - 6581 emulation, Linux specific stuff
|
||||
*
|
||||
* Frodo (C) 1994-1997,2002 Christian Bauer
|
||||
* Linux sound stuff by Bernd Schmidt
|
||||
*/
|
||||
|
||||
#include "gcaudio.h"
|
||||
|
||||
#include "VIC.h"
|
||||
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
|
||||
void DigitalRenderer::init_sound(void)
|
||||
{
|
||||
this->sndbufsize = 1024;
|
||||
|
||||
ready = false;
|
||||
InitialiseAudio();
|
||||
ResetAudio();
|
||||
|
||||
this->sound_buffer = new int16[this->sndbufsize];
|
||||
ready = true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
DigitalRenderer::~DigitalRenderer()
|
||||
{
|
||||
StopAudio();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Pause sound output
|
||||
*/
|
||||
|
||||
void DigitalRenderer::Pause(void)
|
||||
{
|
||||
StopAudio();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Resume sound output
|
||||
*/
|
||||
|
||||
void DigitalRenderer::Resume(void)
|
||||
{
|
||||
/* Done by PlayAudio() */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fill buffer, sample volume (for sampled voice)
|
||||
*/
|
||||
|
||||
void DigitalRenderer::EmulateLine(void)
|
||||
{
|
||||
static int divisor = 0;
|
||||
static int to_output = 0;
|
||||
static int buffer_pos = 0;
|
||||
|
||||
if (!ready)
|
||||
return;
|
||||
|
||||
sample_buf[sample_in_ptr] = volume;
|
||||
sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE;
|
||||
|
||||
/*
|
||||
* Now see how many samples have to be added for this line
|
||||
*/
|
||||
divisor += SAMPLE_FREQ;
|
||||
while (divisor >= 0)
|
||||
divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++;
|
||||
|
||||
/*
|
||||
* Calculate the sound data only when we have enough to fill
|
||||
* the buffer entirely.
|
||||
*/
|
||||
if ((buffer_pos + to_output) >= sndbufsize) {
|
||||
int datalen = sndbufsize - buffer_pos;
|
||||
to_output -= datalen;
|
||||
calc_buffer(sound_buffer + buffer_pos, datalen*2);
|
||||
PlaySound((uint16_t*)sound_buffer, sndbufsize);
|
||||
buffer_pos = 0;
|
||||
}
|
||||
}
|
140
Src/gcaudio.c
Normal file
140
Src/gcaudio.c
Normal file
@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
* FCE Ultra 0.98.12
|
||||
* Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric September 2008
|
||||
* eke-eke October 2008
|
||||
*
|
||||
* gcaudio.c
|
||||
*
|
||||
* Audio driver
|
||||
****************************************************************************/
|
||||
|
||||
#include <gccore.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static u8 ConfigRequested = 0;
|
||||
static u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32);
|
||||
static u8 mixbuffer[16000];
|
||||
static int mixhead = 0;
|
||||
static int mixtail = 0;
|
||||
static int whichab = 0;
|
||||
static int IsPlaying = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
int done = 0;
|
||||
|
||||
// Always clear output buffer
|
||||
memset(outbuffer, 0, len);
|
||||
|
||||
while ( ( mixtail != mixhead ) && ( done < len ) )
|
||||
{
|
||||
*dst++ = src[mixtail++];
|
||||
if (mixtail == 4000) mixtail = 0;
|
||||
done += 4;
|
||||
}
|
||||
|
||||
// Realign to 32 bytes for DMA
|
||||
mixtail -= ((done&0x1f) >> 2);
|
||||
if (mixtail < 0)
|
||||
mixtail += 4000;
|
||||
done &= ~0x1f;
|
||||
if (!done)
|
||||
return len >> 1;
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* AudioSwitchBuffers
|
||||
*
|
||||
* Manages which buffer is played next
|
||||
***************************************************************************/
|
||||
static void AudioSwitchBuffers()
|
||||
{
|
||||
if ( !ConfigRequested )
|
||||
{
|
||||
int len = MixerCollect( soundbuffer[whichab], 3840 );
|
||||
DCFlushRange(soundbuffer[whichab], len);
|
||||
AUDIO_InitDMA((u32)soundbuffer[whichab], len);
|
||||
AUDIO_StartDMA();
|
||||
whichab ^= 1;
|
||||
IsPlaying = 1;
|
||||
}
|
||||
else IsPlaying = 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* InitialiseAudio
|
||||
*
|
||||
* Initializes sound system on first load of emulator
|
||||
***************************************************************************/
|
||||
void InitialiseAudio()
|
||||
{
|
||||
AUDIO_Init(NULL); // Start audio subsystem
|
||||
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
|
||||
AUDIO_RegisterDMACallback( AudioSwitchBuffers );
|
||||
memset(soundbuffer, 0, 3840*2);
|
||||
memset(mixbuffer, 0, 16000);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* StopAudio
|
||||
*
|
||||
* Pause audio output when returning to menu
|
||||
***************************************************************************/
|
||||
void StopAudio()
|
||||
{
|
||||
AUDIO_StopDMA();
|
||||
IsPlaying = 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ResetAudio
|
||||
*
|
||||
* 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( uint16_t *Buffer, int count )
|
||||
{
|
||||
int i;
|
||||
u16 sample;
|
||||
u32 *dst = (u32 *)mixbuffer;
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
sample = Buffer[i];
|
||||
dst[mixhead++] = sample | ( sample << 16);
|
||||
if (mixhead == 4000)
|
||||
mixhead = 0;
|
||||
}
|
||||
|
||||
// Restart Sound Processing if stopped
|
||||
if (IsPlaying == 0)
|
||||
{
|
||||
AudioSwitchBuffers ();
|
||||
}
|
||||
}
|
27
Src/gcaudio.h
Normal file
27
Src/gcaudio.h
Normal file
@ -0,0 +1,27 @@
|
||||
/****************************************************************************
|
||||
* From the FCE Ultra 0.98.12
|
||||
* Nintendo Wii/Gamecube Port
|
||||
*
|
||||
* Tantric September 2008
|
||||
* eke-eke October 2008
|
||||
* Simon Kagstrom Jan 2009
|
||||
*
|
||||
* gcaudio.h
|
||||
*
|
||||
* Audio driver
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void InitialiseAudio();
|
||||
void StopAudio();
|
||||
void ResetAudio();
|
||||
void PlaySound( uint16_t *Buffer, int samples );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
#endif
|
@ -34,7 +34,7 @@ extern "C" int main(int argc, char **argv)
|
||||
fatInitDefault();
|
||||
|
||||
// Init SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user