diff --git a/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp b/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp index d969272a9a..75d0a440b6 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_QT1.cpp @@ -24,9 +24,12 @@ const unsigned samples = 2048; const unsigned freq = 44100; const unsigned buffersize = samples*samplesize/8; -static volatile Uint32 fill_me = 0; -static UInt8 *buffer[2]; -static CmpSoundHeader header; +namespace +{ + volatile Uint32 fill_me = 0; + UInt8 *buffer[2]; + CmpSoundHeader header; +} RageSound_QT1::RageSound_QT1() { @@ -89,71 +92,54 @@ RageSound_QT1::~RageSound_QT1() SAFE_DELETE_ARRAY(buffer[1]); } -void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) +void RageSound_QT1::GetData(SndChannelPtr chan, SndCommand *cmd_passed) { - while (!SOUNDMAN) - SDL_Delay(10); - LockMutex L(SOUNDMAN->lock); - static SoundMixBuffer mix; +// while (!SOUNDMAN) +// SDL_Delay(10); +// LockMutex L(SOUNDMAN->lock); RageSound_QT1 *P = reinterpret_cast(chan->userInfo); + LOG->Trace("GetData"); + LOG->Flush(); fill_me = cmd_passed->param2; UInt32 play_me = !fill_me; if (!P->last_pos) { - TimeRecord tr; - ClockGetTime(P->clock, &tr); - UInt64 temp = tr.value.hi; - temp <<= 32; - temp |= tr.value.lo; - double d = static_cast(temp)/tr.scale*freq; - temp = static_cast(d); - P->last_pos = static_cast(temp & 0x00000000FFFFFFFFLL); + P->last_pos = P->GetPosition(NULL); + // Why the hell do I do this? + // Maybe because there should be a hardware interrupt when the sound buffer + // is half empty? But what does that have to do with the number of samples? P->last_pos += samples * 3 / 2; } else P->last_pos += samples; - bool moreThanOneSound; /* Swap buffers */ header.samplePtr = reinterpret_cast(buffer[play_me]); SndCommand cmd; cmd.cmd = bufferCmd; cmd.param1 = 0; cmd.param2 = reinterpret_cast(&header); - OSErr err = SndDoCommand(chan, &cmd, 0); + OSErr err = SndDoCommand(chan, &cmd, false); if (err != noErr) goto bail; + LOG->Trace("First command"); + LOG->Flush(); /* Clear the fill buffer */ - memset(buffer[fill_me], 0, buffersize); - moreThanOneSound = P->sounds.size() > 1; - - for (unsigned i=0; isounds.size(); ++i) - { - if (P->sounds[i]->stopping) - continue; - - unsigned got = P->sounds[i]->snd->GetPCM(reinterpret_cast(buffer[fill_me]), - buffersize, P->last_pos); - if (moreThanOneSound) - mix.write(reinterpret_cast(buffer[fill_me]), got / 2); - if (got < buffersize) - { - P->sounds[i]->stopping = true; - P->sounds[i]->flush_pos = P->last_pos + (got * 8 / samplesize); - } - } - - if (moreThanOneSound) - mix.read(reinterpret_cast(buffer[fill_me])); +// memset(buffer[fill_me], 0, buffersize); +// moreThanOneSound = P->sounds.size() > 1; + P->Mix((int16_t *)buffer[fill_me], buffersize/channels, P->last_pos, P->GetPosition(NULL)); cmd.cmd = callBackCmd; cmd.param2 = play_me; - err = SndDoCommand(chan, &cmd, 0); + err = SndDoCommand(chan, &cmd, false); if (err != noErr) goto bail; + LOG->Trace("Second command"); + LOG->Flush(); + return; bail: @@ -161,50 +147,6 @@ bail: } -void RageSound_QT1::StartMixing(RageSoundBase *snd) -{ - sound *s = new sound; - s->snd = snd; - - LockMutex L(SOUNDMAN->lock); - sounds.push_back(s); -} - -void RageSound_QT1::StopMixing(RageSoundBase *snd) -{ - LockMutex L(SOUNDMAN->lock); - - /* Find the sound. */ - unsigned i; - for(i = 0; i < sounds.size(); ++i) - if(sounds[i]->snd == snd) break; - if(i == sounds.size()) - { - LOG->Trace("not stopping a sound because it's not playing"); - return; - } - - delete sounds[i]; - sounds.erase(sounds.begin()+i, sounds.begin()+i+1); - LOG->Trace("There are %ld sounds playing", sounds.size()); -} - -void RageSound_QT1::Update(float delta) -{ -#pragma unused (delta) - LockMutex L(SOUNDMAN->lock); - - vectorsnds = sounds; - for (unsigned i = 0; i < snds.size(); ++i) - { - if (!sounds[i]->stopping) - continue; - if (GetPosition(snds[i]->snd) < sounds[i]->flush_pos) - continue; - snds[i]->snd->StopPlaying(); - } -} - int64_t RageSound_QT1::GetPosition(const RageSoundBase *snd) const { #pragma unused (snd) @@ -214,7 +156,7 @@ int64_t RageSound_QT1::GetPosition(const RageSoundBase *snd) const temp <<= 32; temp |= tr.value.lo; double d = static_cast(temp)/tr.scale*freq; - return static_cast(d); + return static_cast(d); } float RageSound_QT1::GetPlayLatency() const diff --git a/stepmania/src/arch/Sound/RageSoundDriver_QT1.h b/stepmania/src/arch/Sound/RageSoundDriver_QT1.h index 1ffabc7659..d0bd6c3c73 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_QT1.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_QT1.h @@ -11,42 +11,36 @@ * */ -/* ugh, what a hack! QT includes Carbon/Carbon.h which -* has defs for a few things defined in RageUtil.h which -* is included in arch.cpp along w/ (eventually) this. -* How do I do this without using phony namespaces? -* --Steve -*/ namespace QT { #include } #include "RageSound.h" -#include "RageSoundDriver.h" +#include "RageSoundDriver_Generic_Software.h" -class RageSound_QT1: public RageSoundDriver +class RageSound_QT1: public RageSound_Generic_Software { private: - struct sound +/* struct sound { RageSoundBase *snd; bool stopping; int flush_pos; sound() { snd=NULL; stopping=false; flush_pos=0; } - }; + };*/ - vector sounds; +// vector sounds; QT::ComponentInstance clock; QT::SndChannelPtr channel; int last_pos; float latency; protected: - virtual void StartMixing(RageSoundBase *snd); - virtual void StopMixing(RageSoundBase *snd); - virtual int64_t GetPosition(const RageSoundBase *snd) const; - virtual void Update (float delta); - virtual float GetPlayLatency() const; +// virtual void StartMixing(RageSoundBase *snd); +// virtual void StopMixing(RageSoundBase *snd); + int64_t GetPosition(const RageSoundBase *snd) const; +// void Update (float delta); + float GetPlayLatency() const; public: RageSound_QT1();