Made the emulation core use the new sound framework. MFC is currently broken.

This commit is contained in:
bgk 2008-12-26 19:33:19 +00:00
parent b334392f48
commit 8bc8270984
9 changed files with 47 additions and 119 deletions

View File

@ -10,6 +10,8 @@
#include "dmg/gb_apu/Gb_Apu.h" #include "dmg/gb_apu/Gb_Apu.h"
#include "dmg/gb_apu/Multi_Buffer.h" #include "dmg/gb_apu/Multi_Buffer.h"
#include "common/SoundDriver.h"
#define NR10 0x60 #define NR10 0x60
#define NR11 0x62 #define NR11 0x62
#define NR12 0x63 #define NR12 0x63
@ -32,21 +34,21 @@
#define NR51 0x81 #define NR51 0x81
#define NR52 0x84 #define NR52 0x84
SoundDriver * soundDriver = 0;
extern bool stopState; // TODO: silence sound when true extern bool stopState; // TODO: silence sound when true
int const SOUND_CLOCK_TICKS_ = 167772; // 1/100 second int const SOUND_CLOCK_TICKS_ = 167772; // 1/100 second
u16 soundFinalWave [1470]; static u16 soundFinalWave [1470];
int soundBufferLen = sizeof soundFinalWave;
int soundQuality = 1; int soundQuality = 1;
bool soundInterpolation = true; bool soundInterpolation = true;
bool soundPaused = true; bool soundPaused = true;
float soundFiltering = 0.5f; float soundFiltering = 0.5f;
float soundVolume = 1.0f;
bool soundEcho = false;
int SOUND_CLOCK_TICKS = SOUND_CLOCK_TICKS_; int SOUND_CLOCK_TICKS = SOUND_CLOCK_TICKS_;
int soundTicks = SOUND_CLOCK_TICKS_; int soundTicks = SOUND_CLOCK_TICKS_;
static float soundVolume = 1.0f;
static int soundEnableFlag = 0x3ff; // emulator channels enabled static int soundEnableFlag = 0x3ff; // emulator channels enabled
static float soundFiltering_ = -1; static float soundFiltering_ = -1;
static float soundVolume_ = -1; static float soundVolume_ = -1;
@ -344,8 +346,11 @@ static void end_frame( blip_time_t time )
stereo_buffer->end_frame( time ); stereo_buffer->end_frame( time );
} }
static void flush_samples() void flush_samples(Multi_Buffer * buffer)
{ {
// get the size in bytes of the sound driver buffer
int soundBufferLen = soundDriver->getBufferLength();
// soundBufferLen should have a whole number of sample pairs // soundBufferLen should have a whole number of sample pairs
assert( soundBufferLen % (2 * sizeof *soundFinalWave) == 0 ); assert( soundBufferLen % (2 * sizeof *soundFinalWave) == 0 );
@ -353,13 +358,13 @@ static void flush_samples()
int const out_buf_size = soundBufferLen / sizeof *soundFinalWave; int const out_buf_size = soundBufferLen / sizeof *soundFinalWave;
// Keep filling and writing soundFinalWave until it can't be fully filled // Keep filling and writing soundFinalWave until it can't be fully filled
while ( stereo_buffer->samples_avail() >= out_buf_size ) while ( buffer->samples_avail() >= out_buf_size )
{ {
stereo_buffer->read_samples( (blip_sample_t*) soundFinalWave, out_buf_size ); buffer->read_samples( (blip_sample_t*) soundFinalWave, out_buf_size );
if(soundPaused) if(soundPaused)
soundResume(); soundResume();
systemWriteDataToSoundBuffer(); soundDriver->write(soundFinalWave, soundBufferLen);
} }
} }
@ -386,7 +391,7 @@ void psoundTickfn()
// Run sound hardware to present // Run sound hardware to present
end_frame( SOUND_CLOCK_TICKS ); end_frame( SOUND_CLOCK_TICKS );
flush_samples(); flush_samples(stereo_buffer);
if ( soundFiltering_ != soundFiltering ) if ( soundFiltering_ != soundFiltering )
apply_filtering(); apply_filtering();
@ -464,19 +469,19 @@ static void remake_stereo_buffer()
void soundShutdown() void soundShutdown()
{ {
systemSoundShutdown(); delete soundDriver;
} }
void soundPause() void soundPause()
{ {
soundPaused = true; soundPaused = true;
systemSoundPause(); soundDriver->pause();
} }
void soundResume() void soundResume()
{ {
soundPaused = false; soundPaused = false;
systemSoundResume(); soundDriver->resume();
} }
void soundSetVolume( float volume ) void soundSetVolume( float volume )
@ -502,7 +507,7 @@ int soundGetEnable()
void soundReset() void soundReset()
{ {
systemSoundReset(); soundDriver->reset();
remake_stereo_buffer(); remake_stereo_buffer();
reset_apu(); reset_apu();
@ -516,7 +521,11 @@ void soundReset()
bool soundInit() bool soundInit()
{ {
if ( !systemSoundInit() ) soundDriver = systemSoundInit();
if ( !soundDriver )
return false;
if (!soundDriver->init(soundQuality))
return false; return false;
soundPaused = true; soundPaused = true;

View File

@ -33,16 +33,10 @@ extern bool soundPaused; // current paused state
// Cleans up sound. Afterwards, soundInit() can be called again. // Cleans up sound. Afterwards, soundInit() can be called again.
void soundShutdown(); void soundShutdown();
// Sound buffering
extern int soundBufferLen; // size of sound buffer in BYTES
extern u16 soundFinalWave[1470];// 16-bit SIGNED stereo sample buffer
//// GBA sound options //// GBA sound options
// Sets sample rate to 44100 / quality // Sets sample rate to 44100 / quality
void soundSetQuality( int quality ); void soundSetQuality( int quality );
extern int soundQuality; // current sound quality
// Sound settings // Sound settings
extern bool soundInterpolation; // 1 if PCM should have low-pass filtering extern bool soundInterpolation; // 1 if PCM should have low-pass filtering
@ -80,4 +74,8 @@ extern int soundTicks; // Number of 16.8 MHz clocks until soundTick() w
void soundSaveGame( gzFile ); void soundSaveGame( gzFile );
void soundReadGame( gzFile, int version ); void soundReadGame( gzFile, int version );
class Multi_Buffer;
void flush_samples(Multi_Buffer * buffer);
#endif // SOUND_H #endif // SOUND_H

View File

@ -20,6 +20,7 @@ typedef int16_t s16;
typedef int32_t s32; typedef int32_t s32;
typedef int64_t s64; typedef int64_t s64;
class SoundDriver;
struct EmulatedSystem { struct EmulatedSystem {
// main emulation function // main emulation function
@ -65,12 +66,7 @@ extern u32 systemReadJoypad(int);
extern u32 systemGetClock(); extern u32 systemGetClock();
extern void systemMessage(int, const char *, ...); extern void systemMessage(int, const char *, ...);
extern void systemSetTitle(const char *); extern void systemSetTitle(const char *);
extern void systemWriteDataToSoundBuffer(); extern SoundDriver * systemSoundInit();
extern void systemSoundShutdown();
extern void systemSoundPause();
extern void systemSoundResume();
extern void systemSoundReset();
extern bool systemSoundInit();
extern void systemScreenMessage(const char *); extern void systemScreenMessage(const char *);
extern void systemUpdateMotionSensor(); extern void systemUpdateMotionSensor();
extern int systemGetSensorX(); extern int systemGetSensorX();

View File

@ -1952,9 +1952,9 @@ void CPUSoftwareInterrupt(int comment)
} }
#endif #endif
if(reg[0].I) if(reg[0].I)
systemSoundPause(); soundPause();
else else
systemSoundResume(); soundResume();
break; break;
case 0x1F: case 0x1F:
BIOS_MidiKey2Freq(); BIOS_MidiKey2Freq();

View File

@ -50,22 +50,6 @@ static void end_frame( blip_time_t time )
stereo_buffer->end_frame( time ); stereo_buffer->end_frame( time );
} }
static void flush_samples()
{
// number of samples in output buffer
int const out_buf_size = soundBufferLen / sizeof *soundFinalWave;
// Keep filling and writing soundFinalWave until it can't be fully filled
while ( stereo_buffer->samples_avail() >= out_buf_size )
{
stereo_buffer->read_samples( (blip_sample_t*) soundFinalWave, out_buf_size );
if(soundPaused)
soundResume();
systemWriteDataToSoundBuffer();
}
}
static void apply_effects() static void apply_effects()
{ {
prevSoundEnable = soundGetEnable(); prevSoundEnable = soundGetEnable();
@ -106,7 +90,7 @@ void gbSoundTick()
// Run sound hardware to present // Run sound hardware to present
end_frame( SOUND_CLOCK_TICKS * ticks_to_time ); end_frame( SOUND_CLOCK_TICKS * ticks_to_time );
flush_samples(); flush_samples(stereo_buffer);
// Update effects config if it was changed // Update effects config if it was changed
if ( memcmp( &gb_effects_config_current, &gb_effects_config, if ( memcmp( &gb_effects_config_current, &gb_effects_config,

View File

@ -49,8 +49,6 @@ int RGB_LOW_BITS_MASK;
int systemRenderedFrames; int systemRenderedFrames;
int systemFPS; int systemFPS;
static SoundDriver * systemSoundDriver = 0;
inline VBA::Window * GUI() inline VBA::Window * GUI()
{ {
return VBA::Window::poGetInstance(); return VBA::Window::poGetInstance();
@ -156,39 +154,11 @@ void systemGbBorderOn()
{ {
} }
void systemWriteDataToSoundBuffer() SoundDriver * systemSoundInit()
{ {
systemSoundDriver->write(soundFinalWave, soundBufferLen); soundShutdown();
}
bool systemSoundInit() return new SoundSDL();
{
systemSoundShutdown();
systemSoundDriver = new SoundSDL();
bool ret = systemSoundDriver->init(soundQuality);
soundBufferLen = systemSoundDriver->getBufferLength();
return ret;
}
void systemSoundShutdown()
{
delete systemSoundDriver;
}
void systemSoundPause()
{
systemSoundDriver->pause();
}
void systemSoundResume()
{
systemSoundDriver->resume();
}
void systemSoundReset()
{
systemSoundDriver->reset();
} }
void debuggerMain() void debuggerMain()

View File

@ -605,7 +605,7 @@ void Window::vInitSystem()
void Window::vUnInitSystem() void Window::vUnInitSystem()
{ {
systemSoundShutdown(); soundShutdown();
} }
void Window::vInitSDL() void Window::vInitSDL()

View File

@ -224,8 +224,6 @@ int sdlMirroringEnable = 0;
static int ignore_first_resize_event = 0; static int ignore_first_resize_event = 0;
static SoundDriver * systemSoundDriver = 0;
/* forward */ /* forward */
void systemConsoleMessage(const char*); void systemConsoleMessage(const char*);
@ -2712,37 +2710,9 @@ int systemGetSensorY()
return inputGetSensorY(); return inputGetSensorY();
} }
void systemWriteDataToSoundBuffer() SoundDriver * systemSoundInit()
{ {
systemSoundDriver->write(soundFinalWave, soundBufferLen); soundShutdown();
}
bool systemSoundInit() return new SoundSDL();
{
systemSoundShutdown();
systemSoundDriver = new SoundSDL();
bool ret = systemSoundDriver->init(soundQuality);
soundBufferLen = systemSoundDriver->getBufferLength();
return ret;
}
void systemSoundShutdown()
{
delete systemSoundDriver;
}
void systemSoundPause()
{
systemSoundDriver->pause();
}
void systemSoundResume()
{
systemSoundDriver->resume();
}
void systemSoundReset()
{
systemSoundDriver->reset();
} }

View File

@ -25,6 +25,7 @@
#include "../agb/GBA.h" #include "../agb/GBA.h"
#include "../Port.h" #include "../Port.h"
#include "../Sound.h"
#include "../armdis.h" #include "../armdis.h"
#include "../elf.h" #include "../elf.h"
#include "exprNode.h" #include "exprNode.h"
@ -2643,7 +2644,7 @@ char* strqtok (char* string, const char* ctrl)
debuggerRegisters(0, NULL); debuggerRegisters(0, NULL);
while(debugger) { while(debugger) {
systemSoundPause(); soundPause();
debuggerDisableBreakpoints(); debuggerDisableBreakpoints();
printf("debugger> "); printf("debugger> ");
commandCount = 0; commandCount = 0;