|
|
@ -76,30 +76,30 @@ static plAudioFileReader *CreateReader( hsBool fullpath, const char filename[], |
|
|
|
|
|
|
|
|
|
|
|
hsError plSoundPreloader::Run() |
|
|
|
hsError plSoundPreloader::Run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
hsTArray<plSoundBuffer*> templist; |
|
|
|
hsTArray<plSoundBuffer*> templist; |
|
|
|
|
|
|
|
|
|
|
|
while (fRunning) |
|
|
|
while (fRunning) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fCritSect.Lock(); |
|
|
|
fCritSect.Lock(); |
|
|
|
for (int i = fBuffers.GetCount(); i > 0; i--) |
|
|
|
for (int i = fBuffers.GetCount(); i > 0; i--) |
|
|
|
{ |
|
|
|
{ |
|
|
|
templist.Append(fBuffers.Pop()); |
|
|
|
templist.Append(fBuffers.Pop()); |
|
|
|
} |
|
|
|
} |
|
|
|
fCritSect.Unlock(); |
|
|
|
fCritSect.Unlock(); |
|
|
|
|
|
|
|
|
|
|
|
if (templist.GetCount() == 0) |
|
|
|
if (templist.GetCount() == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fEvent.Wait(); |
|
|
|
fEvent.Wait(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
plAudioFileReader *reader = nil; |
|
|
|
plAudioFileReader *reader = nil; |
|
|
|
for (int i = templist.GetCount(); i > 0; i--) |
|
|
|
for (int i = templist.GetCount(); i > 0; i--) |
|
|
|
{ |
|
|
|
{ |
|
|
|
plSoundBuffer* buf = templist.Pop(); |
|
|
|
plSoundBuffer* buf = templist.Pop(); |
|
|
|
|
|
|
|
|
|
|
|
if (buf->GetData()) |
|
|
|
if (buf->GetData()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
reader = CreateReader(true, buf->GetFileName(), buf->GetAudioReaderType(), buf->GetReaderSelect());
|
|
|
|
reader = CreateReader(true, buf->GetFileName(), buf->GetAudioReaderType(), buf->GetReaderSelect());
|
|
|
|
|
|
|
|
|
|
|
|
if( reader ) |
|
|
|
if( reader ) |
|
|
@ -109,39 +109,39 @@ hsError plSoundPreloader::Run() |
|
|
|
buf->SetAudioReader(reader); // give sound buffer reader, since we may need it later
|
|
|
|
buf->SetAudioReader(reader); // give sound buffer reader, since we may need it later
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
buf->SetError(); |
|
|
|
buf->SetError(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
buf->SetLoaded(true); |
|
|
|
buf->SetLoaded(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we need to be sure that all buffers are removed from our load list when shutting this thread down or we will hang,
|
|
|
|
// we need to be sure that all buffers are removed from our load list when shutting this thread down or we will hang,
|
|
|
|
// since the sound buffer will wait to be destroyed until it is marked as loaded
|
|
|
|
// since the sound buffer will wait to be destroyed until it is marked as loaded
|
|
|
|
fCritSect.Lock(); |
|
|
|
fCritSect.Lock(); |
|
|
|
for (int i = fBuffers.GetCount(); i > 0; i--) |
|
|
|
for (int i = fBuffers.GetCount(); i > 0; i--) |
|
|
|
{ |
|
|
|
{ |
|
|
|
plSoundBuffer* buf = fBuffers.Pop(); |
|
|
|
plSoundBuffer* buf = fBuffers.Pop(); |
|
|
|
buf->SetLoaded(true); |
|
|
|
buf->SetLoaded(true); |
|
|
|
} |
|
|
|
} |
|
|
|
fCritSect.Unlock(); |
|
|
|
fCritSect.Unlock(); |
|
|
|
|
|
|
|
|
|
|
|
return hsOK; |
|
|
|
return hsOK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static plSoundPreloader gLoaderThread; |
|
|
|
static plSoundPreloader gLoaderThread; |
|
|
|
|
|
|
|
|
|
|
|
void plSoundBuffer::Init() |
|
|
|
void plSoundBuffer::Init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
gLoaderThread.Start(); |
|
|
|
gLoaderThread.Start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void plSoundBuffer::Shutdown() |
|
|
|
void plSoundBuffer::Shutdown() |
|
|
|
{ |
|
|
|
{ |
|
|
|
gLoaderThread.Stop(); |
|
|
|
gLoaderThread.Stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// Constructor/Destructor //////////////////////////////////////////////////
|
|
|
|
//// Constructor/Destructor //////////////////////////////////////////////////
|
|
|
@ -350,8 +350,8 @@ plSoundBuffer::ELoadReturnVal plSoundBuffer::AsyncLoad(plAudioFileReader::Stream |
|
|
|
return kError; |
|
|
|
return kError; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gLoaderThread.AddBuffer(this); |
|
|
|
gLoaderThread.AddBuffer(this); |
|
|
|
fLoading = true; |
|
|
|
fLoading = true; |
|
|
|
} |
|
|
|
} |
|
|
|
if(fLoaded)
|
|
|
|
if(fLoaded)
|
|
|
|
{
|
|
|
|
{
|
|
|
|