Fixed stop of DSP HLE+LLE and some clean up(reset all variables in DSound creation)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2760 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2009-03-27 11:06:52 +00:00
parent b5b42746ed
commit bffe311b3e
6 changed files with 117 additions and 103 deletions

View File

@ -46,20 +46,15 @@ void AOSound::SoundLoop()
while (!threadData) while (!threadData)
{ {
soundCriticalSection.Enter(); soundCriticalSection.Enter();
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2); m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
ao_play(device, (char*)realtimeBuffer, numBytesToRender); ao_play(device, (char*)realtimeBuffer, numBytesToRender);
soundCriticalSection.Leave(); soundCriticalSection.Leave();
if (! threadData) if (! threadData)
soundSyncEvent.Wait(); soundSyncEvent.Wait();
} }
ao_close(device); ao_close(device);
device = NULL; device = NULL;
ao_shutdown();
} }
void *soundThread(void *args) void *soundThread(void *args)
@ -93,7 +88,10 @@ void AOSound::Stop()
delete thread; delete thread;
thread = NULL; thread = NULL;
soundSyncEvent.Shutdown(); soundSyncEvent.Shutdown();
} }
AOSound::~AOSound() {
// FIXME: crashes dolphin
// ao_shutdown();
}
#endif #endif

View File

@ -44,7 +44,7 @@ class AOSound : public SoundStream
public: public:
AOSound(CMixer *mixer) : SoundStream(mixer) {} AOSound(CMixer *mixer) : SoundStream(mixer) {}
virtual ~AOSound() {} virtual ~AOSound();
virtual bool Start(); virtual bool Start();

View File

@ -64,9 +64,10 @@ class DSound : public SoundStream
DWORD dwSoundBytes); DWORD dwSoundBytes);
public: public:
DSound(CMixer *mixer, void *hWnd = NULL) : SoundStream(mixer) {} DSound(CMixer *mixer, void *hWnd = NULL) : SoundStream(mixer),
bufferSize(0),
DSound(CMixer *mixer) : SoundStream(mixer) {} totalRenderedBytes(0),
currentPos(0),lastPos(0) {}
virtual ~DSound() {} virtual ~DSound() {}

View File

@ -31,7 +31,6 @@ void CMixer::Mix(short *samples, int numSamples)
Premix(NULL, 0); Premix(NULL, 0);
return; return;
} }
// silence // silence
memset(samples, 0, numSamples * 2 * sizeof(short)); memset(samples, 0, numSamples * 2 * sizeof(short));
@ -68,13 +67,14 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
if (!soundStream) if (!soundStream)
return; return;
push_sync.Enter();
if (m_queueSize == 0) if (m_queueSize == 0)
{ {
m_queueSize = queue_minlength; m_queueSize = queue_minlength;
for (int i = 0; i < queue_minlength; i++) for (int i = 0; i < queue_minlength; i++)
sample_queue.push((s16)0); sample_queue.push((s16)0);
} }
push_sync.Leave();
static int PV1l=0,PV2l=0,PV3l=0,PV4l=0; static int PV1l=0,PV2l=0,PV3l=0,PV4l=0;
static int PV1r=0,PV2r=0,PV3r=0,PV4r=0; static int PV1r=0,PV2r=0,PV3r=0,PV4r=0;
static int acc=0; static int acc=0;
@ -85,11 +85,15 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
#endif #endif
// Write Other Audio // Write Other Audio
if (m_throttle) { if (! m_throttle)
return;
/* This is only needed for non-AX sound, currently directly /* This is only needed for non-AX sound, currently directly
streamed and DTK sound. For AX we call SoundStream::Update in streamed and DTK sound. For AX we call SoundStream::Update in
AXTask() for example. */ AXTask() for example. */
while (m_queueSize > queue_maxlength / 2) { while (m_queueSize > queue_maxlength / 2) {
// Urgh. // Urgh.
if (g_dspInitialize.pEmulatorState) { if (g_dspInitialize.pEmulatorState) {
if (*g_dspInitialize.pEmulatorState != 0) if (*g_dspInitialize.pEmulatorState != 0)
@ -100,11 +104,9 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
} }
push_sync.Enter(); push_sync.Enter();
while (num_stereo_samples) while (num_stereo_samples) {
{
acc += m_sampleRate; acc += m_sampleRate;
while (num_stereo_samples && (acc >= 48000)) while (num_stereo_samples && (acc >= 48000)) {
{
PV4l=PV3l; PV4l=PV3l;
PV3l=PV2l; PV3l=PV2l;
PV2l=PV1l; PV2l=PV1l;
@ -121,13 +123,12 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
s32 DataL = PV1l; s32 DataL = PV1l;
s32 DataR = PV1r; s32 DataR = PV1r;
if (m_mode == 1) //linear if (m_mode == 1) { //linear
{
DataL = PV1l + ((PV2l - PV1l)*acc)/48000; DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
DataR = PV1r + ((PV2r - PV1r)*acc)/48000; DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
} }
else if (m_mode == 2) //cubic else if (m_mode == 2) {//cubic
{
s32 a0l = PV1l - PV2l - PV4l + PV3l; s32 a0l = PV1l - PV2l - PV4l + PV3l;
s32 a0r = PV1r - PV2r - PV4r + PV3r; s32 a0r = PV1r - PV2r - PV4r + PV3r;
s32 a1l = PV4l - PV3l - a0l; s32 a1l = PV4l - PV3l - a0l;
@ -161,5 +162,4 @@ void CMixer::PushSamples(short *samples, int num_stereo_samples)
} }
push_sync.Leave(); push_sync.Leave();
} }
}

View File

@ -217,23 +217,30 @@ void Initialize(void *init)
void DSP_StopSoundStream() void DSP_StopSoundStream()
{ {
// fprintf(stderr, "in dsp stop\n"); /*
if (!soundStream) if (!soundStream)
PanicAlert("Can't stop non running SoundStream!"); PanicAlert("Can't stop non running SoundStream!");
soundStream->Stop(); soundStream->Stop();
delete soundStream; delete soundStream;
soundStream = NULL; soundStream = NULL;
// fprintf(stderr, "in dsp stop end\n"); */
} }
void Shutdown() void Shutdown()
{ {
// FIXME: called before stop is finished???? NOTICE_LOG(DSPHLE, "Shutting down DSP plugin");
// fprintf(stderr, "in dsp shutdown\n");
if (soundStream) {
soundStream->Stop();
delete soundStream;
soundStream = NULL;
}
// Check that soundstream already is stopped. // Check that soundstream already is stopped.
if (soundStream) while (soundStream) {
PanicAlert("SoundStream alive in DSP::Shutdown!"); ERROR_LOG(DSPHLE, "Waiting for sound stream");
Common::SleepCurrentThread(2000);
}
// Stop the sound recording // Stop the sound recording
if (log_ai) if (log_ai)
@ -252,6 +259,7 @@ void Shutdown()
m_frame->sMailEnd.clear(); m_frame->sMailEnd.clear();
} }
#endif #endif
INFO_LOG(DSPHLE, "Done shutting down DSP plugin");
} }
void DoState(unsigned char **ptr, int mode) void DoState(unsigned char **ptr, int mode)

View File

@ -261,22 +261,29 @@ void Initialize(void *init)
void DSP_StopSoundStream() void DSP_StopSoundStream()
{ {
if (!soundStream) }
PanicAlert("Can't stop non running SoundStream!");
void Shutdown(void)
{
NOTICE_LOG(DSPHLE, "Shutting down DSP plugin");
if (soundStream) {
soundStream->Stop(); soundStream->Stop();
delete soundStream; delete soundStream;
soundStream = NULL; soundStream = NULL;
} }
void Shutdown(void)
{
// Check that soundstream already is stopped. // Check that soundstream already is stopped.
if (soundStream) while (soundStream) {
PanicAlert("SoundStream alive in DSP::Shutdown!"); ERROR_LOG(DSPHLE, "Waiting for sound stream");
Common::SleepCurrentThread(2000);
}
// Stop the sound recording // Stop the sound recording
if (log_ai) if (log_ai)
g_wave_writer.Stop(); g_wave_writer.Stop();
INFO_LOG(DSPHLE, "Done shutting down DSP plugin");
} }
u16 DSP_WriteControlRegister(u16 _uFlag) u16 DSP_WriteControlRegister(u16 _uFlag)