Multi-threaded audio fixes
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#ifdef MULTITHREADED_AUDIO
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <condition_variable>
|
||||
#endif
|
||||
#include "oal/stream.h"
|
||||
|
||||
@@ -522,13 +523,10 @@ _FindMP3s(void)
|
||||
} else
|
||||
bShortcut = FALSE;
|
||||
|
||||
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
||||
|
||||
if (aStream[0] && aStream[0]->IsOpened())
|
||||
if (aStream[0] && aStream[0]->Open(filepath))
|
||||
{
|
||||
total_ms = aStream[0]->GetLengthMS();
|
||||
aStream[0]->Close();
|
||||
aStream[0] = NULL;
|
||||
|
||||
OutputDebugString(fd.cFileName);
|
||||
|
||||
@@ -596,13 +594,10 @@ _FindMP3s(void)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
||||
|
||||
if (aStream[0] && aStream[0]->IsOpened())
|
||||
if (aStream[0] && aStream[0]->Open(filepath))
|
||||
{
|
||||
total_ms = aStream[0]->GetLengthMS();
|
||||
aStream[0]->Close();
|
||||
aStream[0] = NULL;
|
||||
|
||||
OutputDebugString(fd.cFileName);
|
||||
|
||||
@@ -656,13 +651,10 @@ _FindMP3s(void)
|
||||
} else
|
||||
bShortcut = FALSE;
|
||||
|
||||
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
||||
|
||||
if (aStream[0] && aStream[0]->IsOpened())
|
||||
if (aStream[0] && aStream[0]->Open(filepath))
|
||||
{
|
||||
total_ms = aStream[0]->GetLengthMS();
|
||||
aStream[0]->Close();
|
||||
aStream[0] = NULL;
|
||||
|
||||
OutputDebugString(fd.cFileName);
|
||||
|
||||
@@ -818,6 +810,9 @@ cSampleManager::Initialise(void)
|
||||
|
||||
EFXInit();
|
||||
|
||||
for(int i = 0; i < MAX_STREAMS; i++)
|
||||
aStream[i] = new CStream(ALStreamSources[i], ALStreamBuffers[i]);
|
||||
|
||||
CStream::Initialise();
|
||||
|
||||
{
|
||||
@@ -973,13 +968,10 @@ cSampleManager::Initialise(void)
|
||||
|
||||
for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
|
||||
{
|
||||
aStream[0] = new CStream(StreamedNameTable[i], ALStreamSources[0], ALStreamBuffers[0], IsThisTrackAt16KHz(i) ? 16000 : 32000);
|
||||
|
||||
if ( aStream[0] && aStream[0]->IsOpened() )
|
||||
if ( aStream[0] && aStream[0]->Open(StreamedNameTable[i], IsThisTrackAt16KHz(i) ? 16000 : 32000) )
|
||||
{
|
||||
uint32 tatalms = aStream[0]->GetLengthMS();
|
||||
aStream[0]->Close();
|
||||
aStream[0] = NULL;
|
||||
|
||||
nStreamLength[i] = tatalms;
|
||||
}
|
||||
@@ -1023,7 +1015,8 @@ cSampleManager::Initialise(void)
|
||||
{
|
||||
for ( int32 i = 0; i < MAX_STREAMS; i++ )
|
||||
{
|
||||
aStream[i] = NULL;
|
||||
aStream[i]->Close();
|
||||
|
||||
nStreamVolume[i] = 100;
|
||||
nStreamPan[i] = 63;
|
||||
}
|
||||
@@ -1110,14 +1103,7 @@ void
|
||||
cSampleManager::Terminate(void)
|
||||
{
|
||||
for (int32 i = 0; i < MAX_STREAMS; i++)
|
||||
{
|
||||
CStream *stream = aStream[i];
|
||||
if (stream)
|
||||
{
|
||||
stream->Close();
|
||||
aStream[i] = NULL;
|
||||
}
|
||||
}
|
||||
aStream[i]->Close();
|
||||
|
||||
for ( int32 i = 0; i < NUM_CHANNELS; i++ )
|
||||
aChannel[i].Term();
|
||||
@@ -1168,6 +1154,9 @@ cSampleManager::Terminate(void)
|
||||
|
||||
CStream::Terminate();
|
||||
|
||||
for(int32 i = 0; i < MAX_STREAMS; i++)
|
||||
delete aStream[i];
|
||||
|
||||
if ( nSampleBankMemoryStartAddress[SFX_BANK_0] != 0 )
|
||||
{
|
||||
free((void *)nSampleBankMemoryStartAddress[SFX_BANK_0]);
|
||||
@@ -1693,22 +1682,16 @@ cSampleManager::PreloadStreamedFile(uint32 nFile, uint8 nStream)
|
||||
|
||||
if ( nFile < TOTAL_STREAMED_SOUNDS )
|
||||
{
|
||||
if ( aStream[nStream] )
|
||||
{
|
||||
aStream[nStream]->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
stream->Close();
|
||||
|
||||
strcpy(filename, StreamedNameTable[nFile]);
|
||||
|
||||
CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
ASSERT(stream != NULL);
|
||||
|
||||
aStream[nStream] = stream;
|
||||
stream->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
if ( !stream->Setup() )
|
||||
{
|
||||
stream->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1720,7 +1703,7 @@ cSampleManager::PauseStream(bool8 nPauseFlag, uint8 nStream)
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
stream->SetPause(nPauseFlag != FALSE);
|
||||
}
|
||||
@@ -1733,12 +1716,9 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
stream->Start();
|
||||
}
|
||||
stream->Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1752,11 +1732,8 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
if ( nFile >= TOTAL_STREAMED_SOUNDS )
|
||||
return FALSE;
|
||||
|
||||
if ( aStream[nStream] )
|
||||
{
|
||||
aStream[nStream]->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
aStream[nStream]->Close();
|
||||
|
||||
if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
|
||||
{
|
||||
do
|
||||
@@ -1773,11 +1750,10 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
nFile = 0;
|
||||
|
||||
strcpy(filename, StreamedNameTable[nFile]);
|
||||
CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
|
||||
aStream[nStream] = stream;
|
||||
|
||||
if (stream->Setup()) {
|
||||
CStream *stream = aStream[nStream];
|
||||
stream->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
if ( stream->Setup() ) {
|
||||
stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
|
||||
nStreamLoopedFlag[nStream] = TRUE;
|
||||
if (position != 0)
|
||||
@@ -1788,19 +1764,18 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
return TRUE;
|
||||
} else {
|
||||
stream->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
|
||||
if (e->pLinkPath != NULL)
|
||||
aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
aStream[nStream]->Open(e->pLinkPath, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
else {
|
||||
strcpy(filename, _mp3DirectoryPath);
|
||||
strcat(filename, e->aFilename);
|
||||
|
||||
aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream]);
|
||||
aStream[nStream]->Open(filename);
|
||||
}
|
||||
|
||||
if (aStream[nStream]->Setup()) {
|
||||
@@ -1813,7 +1788,6 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
return TRUE;
|
||||
} else {
|
||||
aStream[nStream]->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
// fall through, start playing from another song
|
||||
}
|
||||
@@ -1832,9 +1806,8 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
_bIsMp3Active = 0;
|
||||
strcpy(filename, StreamedNameTable[nFile]);
|
||||
|
||||
CStream* stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
|
||||
aStream[nStream] = stream;
|
||||
CStream* stream = aStream[nStream];
|
||||
stream->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
|
||||
if (stream->Setup()) {
|
||||
stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
|
||||
@@ -1847,18 +1820,17 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
return TRUE;
|
||||
} else {
|
||||
stream->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (mp3->pLinkPath != NULL)
|
||||
aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
aStream[nStream]->Open(mp3->pLinkPath, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
else {
|
||||
strcpy(filename, _mp3DirectoryPath);
|
||||
strcat(filename, mp3->aFilename);
|
||||
|
||||
aStream[nStream] = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
aStream[nStream]->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
}
|
||||
|
||||
if (aStream[nStream]->Setup()) {
|
||||
@@ -1869,7 +1841,6 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
return TRUE;
|
||||
} else {
|
||||
aStream[nStream]->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1881,9 +1852,9 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
}
|
||||
strcpy(filename, StreamedNameTable[nFile]);
|
||||
|
||||
CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
aStream[nStream] = stream;
|
||||
aStream[nStream]->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
|
||||
|
||||
if ( stream->Setup() ) {
|
||||
stream->SetLoopCount(nStreamLoopedFlag[nStream] ? 0 : 1);
|
||||
@@ -1896,7 +1867,6 @@ cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream)
|
||||
return TRUE;
|
||||
} else {
|
||||
stream->Close();
|
||||
aStream[nStream] = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1908,14 +1878,10 @@ cSampleManager::StopStreamedFile(uint8 nStream)
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
{
|
||||
stream->Close();
|
||||
aStream[nStream] = NULL;
|
||||
stream->Close();
|
||||
|
||||
if ( nStream == 0 )
|
||||
_bIsMp3Active = FALSE;
|
||||
}
|
||||
if ( nStream == 0 )
|
||||
_bIsMp3Active = FALSE;
|
||||
}
|
||||
|
||||
int32
|
||||
@@ -1925,7 +1891,7 @@ cSampleManager::GetStreamedFilePosition(uint8 nStream)
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
if ( _bIsMp3Active )
|
||||
{
|
||||
@@ -1968,7 +1934,7 @@ cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, bool8 nEffect
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
if ( nEffectFlag ) {
|
||||
if ( nStream == 1 || nStream == 2 )
|
||||
@@ -1998,7 +1964,7 @@ cSampleManager::IsStreamPlaying(uint8 nStream)
|
||||
|
||||
CStream *stream = aStream[nStream];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
{
|
||||
if ( stream->IsPlaying() )
|
||||
return TRUE;
|
||||
@@ -2014,7 +1980,7 @@ cSampleManager::Service(void)
|
||||
{
|
||||
CStream *stream = aStream[i];
|
||||
|
||||
if ( stream )
|
||||
if ( stream->IsOpened() )
|
||||
stream->Update();
|
||||
}
|
||||
int refCount = CChannel::channelsThatNeedService;
|
||||
|
||||
Reference in New Issue
Block a user