a NEED DEBUG version of openal sound system, nakee, try to FIX it! :)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3409 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hyperiris 2009-06-12 14:40:50 +00:00
parent b8d3cae6e3
commit ff0ec2b3f8
4 changed files with 42 additions and 24 deletions

View File

@ -25,18 +25,18 @@
#include "FixedSizeQueue.h" #include "FixedSizeQueue.h"
#include "AudioCommon.h" #include "AudioCommon.h"
void CMixer::Mix(short *samples, int numSamples) int CMixer::Mix(short *samples, int numSamples)
{ {
if (! samples) { if (! samples) {
Premix(NULL, 0); Premix(NULL, 0);
return; return 0;
} }
// silence // silence
memset(samples, 0, numSamples * 2 * sizeof(short)); memset(samples, 0, numSamples * 2 * sizeof(short));
if (g_dspInitialize.pEmulatorState) { if (g_dspInitialize.pEmulatorState) {
if (*g_dspInitialize.pEmulatorState != 0) if (*g_dspInitialize.pEmulatorState != 0)
return; return 0;
} }
// first get the DTK Music // first get the DTK Music
@ -46,9 +46,11 @@ void CMixer::Mix(short *samples, int numSamples)
Premix(samples, numSamples); Premix(samples, numSamples);
push_sync.Enter();
int count = 0; int count = 0;
while (m_queueSize > queue_minlength && count < numSamples * 2) {
push_sync.Enter();
while (m_queueSize > queue_minlength && count < numSamples * 2)
{
int x = samples[count]; int x = samples[count];
x += sample_queue.front(); x += sample_queue.front();
if (x > 32767) x = 32767; if (x > 32767) x = 32767;
@ -64,6 +66,8 @@ void CMixer::Mix(short *samples, int numSamples)
m_queueSize-=2; m_queueSize-=2;
} }
push_sync.Leave(); push_sync.Leave();
return count;
} }

View File

@ -31,7 +31,7 @@ public:
CMixer() : m_sampleRate(48000),m_bits(16),m_channels(2), m_mode(2), m_HLEready(false),m_queueSize(0) {} CMixer() : m_sampleRate(48000),m_bits(16),m_channels(2), m_mode(2), m_HLEready(false),m_queueSize(0) {}
// Called from audio threads // Called from audio threads
virtual void Mix(short *sample, int numSamples); virtual int Mix(short *sample, int numSamples);
// Called from main thread // Called from main thread
virtual void PushSamples(short* samples, int num_stereo_samples, int core_sample_rate); virtual void PushSamples(short* samples, int num_stereo_samples, int core_sample_rate);
@ -40,6 +40,8 @@ public:
int GetSampleRate() {return m_sampleRate;} int GetSampleRate() {return m_sampleRate;}
int GetDataSize() {return m_queueSize;}
void SetThrottle(bool use) { m_throttle = use;} void SetThrottle(bool use) { m_throttle = use;}
void SetDTKMusic(bool use) { m_EnableDTKMusic = use;} void SetDTKMusic(bool use) { m_EnableDTKMusic = use;}

View File

@ -23,7 +23,7 @@
class NullMixer : public CMixer { class NullMixer : public CMixer {
public: public:
virtual void Mix(short *sample, int numSamples) {} virtual int Mix(short *sample, int numSamples) {return 0;}
virtual void PushSamples(short* samples, int num_stereo_samples, virtual void PushSamples(short* samples, int num_stereo_samples,
int core_sample_rate) {} int core_sample_rate) {}
}; };

View File

@ -86,7 +86,10 @@ void OpenALStream::Stop()
void OpenALStream::Update() void OpenALStream::Update()
{ {
soundSyncEvent.Set(); //if (m_mixer->GetDataSize()) //here need debug
{
soundSyncEvent.Set();
}
} }
THREAD_RETURN OpenALStream::ThreadFunc(void* args) THREAD_RETURN OpenALStream::ThreadFunc(void* args)
@ -120,28 +123,37 @@ void OpenALStream::SoundLoop()
while (!threadData) while (!threadData)
{ {
ALint iBuffersProcessed = 0; soundCriticalSection.Enter();
alGetSourcei(uiSource, AL_BUFFERS_PROCESSED, &iBuffersProcessed); int numBytesToRender = 32768; //ya, this is a hack, we need real data count
int numBytesRender = m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
soundCriticalSection.Leave();
if (iBuffersProcessed) //if (numBytesRender) //here need debug
{ {
// Remove the Buffer from the Queue. (uiBuffer contains the Buffer ID for the unqueued Buffer) ALint iBuffersProcessed = 0;
ALuint uiTempBuffer = 0; alGetSourcei(uiSource, AL_BUFFERS_PROCESSED, &iBuffersProcessed);
alSourceUnqueueBuffers(uiSource, 1, &uiTempBuffer);
soundCriticalSection.Enter(); if (iBuffersProcessed)
int numBytesToRender = 32768; //ya, this is a hack, we need real data count
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
soundCriticalSection.Leave();
unsigned long ulBytesWritten = 0;
//if (ulBytesWritten)
{ {
//alBufferData(uiTempBuffer, ulFormat, pDecodeBuffer, ulBytesWritten, ulFrequency); // Remove the Buffer from the Queue. (uiBuffer contains the Buffer ID for the unqueued Buffer)
alBufferData(uiTempBuffer, AL_FORMAT_STEREO16, realtimeBuffer, numBytesToRender, ulFrequency); ALuint uiTempBuffer = 0;
alSourceUnqueueBuffers(uiSource, 1, &uiTempBuffer);
/*
soundCriticalSection.Enter();
int numBytesToRender = 32768; //ya, this is a hack, we need real data count
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
soundCriticalSection.Leave();
unsigned long ulBytesWritten = 0;
*/
//if (numBytesRender)
{
alBufferData(uiTempBuffer, AL_FORMAT_STEREO16, realtimeBuffer, numBytesToRender, ulFrequency);
}
alSourceQueueBuffers(uiSource, 1, &uiTempBuffer); alSourceQueueBuffers(uiSource, 1, &uiTempBuffer);
} }
} }
if (!threadData) if (!threadData)
soundSyncEvent.Wait(); soundSyncEvent.Wait();
} }