broken, whee

This commit is contained in:
Steve Checkoway
2004-03-24 03:19:10 +00:00
parent b64a709ace
commit b1e9d52108
2 changed files with 37 additions and 101 deletions
@@ -24,9 +24,12 @@ const unsigned samples = 2048;
const unsigned freq = 44100; const unsigned freq = 44100;
const unsigned buffersize = samples*samplesize/8; const unsigned buffersize = samples*samplesize/8;
static volatile Uint32 fill_me = 0; namespace
static UInt8 *buffer[2]; {
static CmpSoundHeader header; volatile Uint32 fill_me = 0;
UInt8 *buffer[2];
CmpSoundHeader header;
}
RageSound_QT1::RageSound_QT1() RageSound_QT1::RageSound_QT1()
{ {
@@ -89,71 +92,54 @@ RageSound_QT1::~RageSound_QT1()
SAFE_DELETE_ARRAY(buffer[1]); 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) // while (!SOUNDMAN)
SDL_Delay(10); // SDL_Delay(10);
LockMutex L(SOUNDMAN->lock); // LockMutex L(SOUNDMAN->lock);
static SoundMixBuffer mix;
RageSound_QT1 *P = reinterpret_cast<RageSound_QT1 *>(chan->userInfo); RageSound_QT1 *P = reinterpret_cast<RageSound_QT1 *>(chan->userInfo);
LOG->Trace("GetData");
LOG->Flush();
fill_me = cmd_passed->param2; fill_me = cmd_passed->param2;
UInt32 play_me = !fill_me; UInt32 play_me = !fill_me;
if (!P->last_pos) if (!P->last_pos)
{ {
TimeRecord tr; P->last_pos = P->GetPosition(NULL);
ClockGetTime(P->clock, &tr); // Why the hell do I do this?
UInt64 temp = tr.value.hi; // Maybe because there should be a hardware interrupt when the sound buffer
temp <<= 32; // is half empty? But what does that have to do with the number of samples?
temp |= tr.value.lo;
double d = static_cast<double>(temp)/tr.scale*freq;
temp = static_cast<UInt64>(d);
P->last_pos = static_cast<UInt32>(temp & 0x00000000FFFFFFFFLL);
P->last_pos += samples * 3 / 2; P->last_pos += samples * 3 / 2;
} }
else else
P->last_pos += samples; P->last_pos += samples;
bool moreThanOneSound;
/* Swap buffers */ /* Swap buffers */
header.samplePtr = reinterpret_cast<Ptr>(buffer[play_me]); header.samplePtr = reinterpret_cast<Ptr>(buffer[play_me]);
SndCommand cmd; SndCommand cmd;
cmd.cmd = bufferCmd; cmd.cmd = bufferCmd;
cmd.param1 = 0; cmd.param1 = 0;
cmd.param2 = reinterpret_cast<long>(&header); cmd.param2 = reinterpret_cast<long>(&header);
OSErr err = SndDoCommand(chan, &cmd, 0); OSErr err = SndDoCommand(chan, &cmd, false);
if (err != noErr) if (err != noErr)
goto bail; goto bail;
LOG->Trace("First command");
LOG->Flush();
/* Clear the fill buffer */ /* Clear the fill buffer */
memset(buffer[fill_me], 0, buffersize); // memset(buffer[fill_me], 0, buffersize);
moreThanOneSound = P->sounds.size() > 1; // moreThanOneSound = P->sounds.size() > 1;
for (unsigned i=0; i<P->sounds.size(); ++i)
{
if (P->sounds[i]->stopping)
continue;
unsigned got = P->sounds[i]->snd->GetPCM(reinterpret_cast<char *>(buffer[fill_me]),
buffersize, P->last_pos);
if (moreThanOneSound)
mix.write(reinterpret_cast<SInt16 *>(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<SInt16 *>(buffer[fill_me]));
P->Mix((int16_t *)buffer[fill_me], buffersize/channels, P->last_pos, P->GetPosition(NULL));
cmd.cmd = callBackCmd; cmd.cmd = callBackCmd;
cmd.param2 = play_me; cmd.param2 = play_me;
err = SndDoCommand(chan, &cmd, 0); err = SndDoCommand(chan, &cmd, false);
if (err != noErr) if (err != noErr)
goto bail; goto bail;
LOG->Trace("Second command");
LOG->Flush();
return; return;
bail: 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);
vector<sound *>snds = 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 int64_t RageSound_QT1::GetPosition(const RageSoundBase *snd) const
{ {
#pragma unused (snd) #pragma unused (snd)
@@ -214,7 +156,7 @@ int64_t RageSound_QT1::GetPosition(const RageSoundBase *snd) const
temp <<= 32; temp <<= 32;
temp |= tr.value.lo; temp |= tr.value.lo;
double d = static_cast<double>(temp)/tr.scale*freq; double d = static_cast<double>(temp)/tr.scale*freq;
return static_cast<UInt64>(d); return static_cast<int64_t>(d);
} }
float RageSound_QT1::GetPlayLatency() const float RageSound_QT1::GetPlayLatency() const
+10 -16
View File
@@ -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 namespace QT
{ {
#include <QuickTime/QuickTime.h> #include <QuickTime/QuickTime.h>
} }
#include "RageSound.h" #include "RageSound.h"
#include "RageSoundDriver.h" #include "RageSoundDriver_Generic_Software.h"
class RageSound_QT1: public RageSoundDriver class RageSound_QT1: public RageSound_Generic_Software
{ {
private: private:
struct sound /* struct sound
{ {
RageSoundBase *snd; RageSoundBase *snd;
bool stopping; bool stopping;
int flush_pos; int flush_pos;
sound() { snd=NULL; stopping=false; flush_pos=0; } sound() { snd=NULL; stopping=false; flush_pos=0; }
}; };*/
vector<sound *> sounds; // vector<sound *> sounds;
QT::ComponentInstance clock; QT::ComponentInstance clock;
QT::SndChannelPtr channel; QT::SndChannelPtr channel;
int last_pos; int last_pos;
float latency; float latency;
protected: protected:
virtual void StartMixing(RageSoundBase *snd); // virtual void StartMixing(RageSoundBase *snd);
virtual void StopMixing(RageSoundBase *snd); // virtual void StopMixing(RageSoundBase *snd);
virtual int64_t GetPosition(const RageSoundBase *snd) const; int64_t GetPosition(const RageSoundBase *snd) const;
virtual void Update (float delta); // void Update (float delta);
virtual float GetPlayLatency() const; float GetPlayLatency() const;
public: public:
RageSound_QT1(); RageSound_QT1();