summaryrefslogtreecommitdiffstats
path: root/src/audio/sampman_oal.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audio/sampman_oal.cpp186
1 files changed, 84 insertions, 102 deletions
diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp
index 7fb84965..2d9f9e86 100644
--- a/src/audio/sampman_oal.cpp
+++ b/src/audio/sampman_oal.cpp
@@ -34,6 +34,13 @@
#include "oal/oal_utils.h"
#include "oal/aldlist.h"
#include "oal/channel.h"
+
+#include <utility>
+#ifdef MULTITHREADED_AUDIO
+#include <mutex>
+#include <queue>
+#include <condition_variable>
+#endif
#include "oal/stream.h"
#include "AudioManager.h"
@@ -515,14 +522,11 @@ _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();
- delete aStream[0];
- aStream[0] = NULL;
-
+ aStream[0]->Close();
+
OutputDebugString(fd.cFileName);
_pMP3List = new tMP3Entry;
@@ -573,14 +577,13 @@ _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();
- delete aStream[0];
- aStream[0] = NULL;
+ aStream[0]->Close();
+ OutputDebugString(fd.cFileName);
+
pList->pNext = new tMP3Entry;
tMP3Entry *e = pList->pNext;
@@ -732,6 +735,10 @@ cSampleManager::Initialise(void)
return TRUE;
EFXInit();
+
+ for(int i = 0; i < MAX_STREAMS; i++)
+ aStream[i] = new CStream(ALStreamSources[i], ALStreamBuffers[i]);
+
CStream::Initialise();
{
@@ -885,14 +892,16 @@ cSampleManager::Initialise(void)
debug("Cannot load audio cache\n");
#endif
- 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()) {
+ for ( int32 i = 0; i < TOTAL_STREAMED_SOUNDS; i++ )
+ {
+ if(aStream[0] && (
+#ifdef PS2_AUDIO_PATHS
+ aStream[0]->Open(PS2StreamedNameTable[i], IsThisTrackAt16KHz(i) ? 16000 : 32000) ||
+#endif
+ aStream[0]->Open(StreamedNameTable[i], IsThisTrackAt16KHz(i) ? 16000 : 32000)))
+ {
uint32 tatalms = aStream[0]->GetLengthMS();
- delete aStream[0];
- aStream[0] = NULL;
-
+ aStream[0]->Close();
nStreamLength[i] = tatalms;
} else
USERERROR("Can't open '%s'\n", StreamedNameTable[i]);
@@ -934,12 +943,13 @@ cSampleManager::Initialise(void)
{
for ( int32 i = 0; i < MAX_STREAMS; i++ )
{
- aStream[i] = NULL;
+ aStream[i]->Close();
+
nStreamVolume[i] = 100;
nStreamPan[i] = 63;
}
}
-
+
{
_bSampmanInitialised = TRUE;
@@ -1021,15 +1031,8 @@ void
cSampleManager::Terminate(void)
{
for (int32 i = 0; i < MAX_STREAMS; i++)
- {
- CStream *stream = aStream[i];
- if (stream)
- {
- delete stream;
- aStream[i] = NULL;
- }
- }
-
+ aStream[i]->Close();
+
for ( int32 i = 0; i < NUM_CHANNELS; i++ )
aChannel[i].Term();
@@ -1079,6 +1082,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]);
@@ -1599,28 +1605,21 @@ cSampleManager::StopChannel(uint32 nChannel)
void
cSampleManager::PreloadStreamedFile(uint8 nFile, uint8 nStream)
{
- char filename[MAX_PATH];
-
ASSERT( nStream < MAX_STREAMS );
if ( nFile < TOTAL_STREAMED_SOUNDS )
{
- if ( aStream[nStream] )
- {
- delete aStream[nStream];
- aStream[nStream] = NULL;
- }
-
- strcpy(filename, StreamedNameTable[nFile]);
-
- CStream *stream = new CStream(filename, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
- ASSERT(stream != NULL);
-
- aStream[nStream] = stream;
+ CStream *stream = aStream[nStream];
+
+ stream->Close();
+
+#ifdef PS2_AUDIO_PATHS
+ if(!stream->Open(PS2StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000))
+#endif
+ stream->Open(StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
if ( !stream->Setup() )
{
- delete stream;
- aStream[nStream] = NULL;
+ stream->Close();
}
}
}
@@ -1632,7 +1631,7 @@ cSampleManager::PauseStream(bool8 nPauseFlag, uint8 nStream)
CStream *stream = aStream[nStream];
- if ( stream )
+ if ( stream->IsOpened() )
{
stream->SetPause(nPauseFlag != FALSE);
}
@@ -1645,12 +1644,9 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
CStream *stream = aStream[nStream];
- if ( stream )
+ if ( stream->IsOpened() )
{
- if ( stream->IsOpened() )
- {
- stream->Start();
- }
+ stream->Start();
}
}
@@ -1664,11 +1660,8 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
if ( nFile >= TOTAL_STREAMED_SOUNDS )
return FALSE;
- if ( aStream[nStream] )
- {
- delete aStream[nStream];
- aStream[nStream] = NULL;
- }
+ aStream[nStream]->Close();
+
if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
{
do
@@ -1683,13 +1676,12 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
// Try to continue from previous song, if already started
if(!_GetMP3PosFromStreamPos(&position, &e) && !e) {
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];
+#ifdef PS2_AUDIO_PATHS
+ if(!stream->Open(PS2StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000))
+#endif
+ stream->Open(StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
+ if ( stream->Setup() ) {
if (position != 0)
stream->SetPosMS(position);
@@ -1697,19 +1689,18 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
return TRUE;
} else {
- delete stream;
- aStream[nStream] = NULL;
+ stream->Close();
}
return FALSE;
} else {
- if ( e->pLinkPath != NULL )
- aStream[nStream] = new CStream(e->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
+ if (e->pLinkPath != NULL)
+ 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()) {
@@ -1721,8 +1712,7 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
_bIsMp3Active = TRUE;
return TRUE;
} else {
- delete aStream[nStream];
- aStream[nStream] = NULL;
+ aStream[nStream]->Close();
}
// fall through, start playing from another song
}
@@ -1739,11 +1729,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
{
nFile = 0;
_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];
+#ifdef PS2_AUDIO_PATHS
+ if(!stream->Open(PS2StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000))
+#endif
+ stream->Open(StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
if (stream->Setup()) {
if (position != 0)
@@ -1753,19 +1743,17 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
return TRUE;
} else {
- delete stream;
- aStream[nStream] = NULL;
+ stream->Close();
}
return FALSE;
}
}
- if(mp3->pLinkPath != NULL)
- aStream[nStream] = new CStream(mp3->pLinkPath, ALStreamSources[nStream], ALStreamBuffers[nStream], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
+ if (mp3->pLinkPath != NULL)
+ 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]);
+ aStream[nStream]->Open(filename, IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
}
if (aStream[nStream]->Setup()) {
@@ -1775,8 +1763,7 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
#endif
return TRUE;
} else {
- delete aStream[nStream];
- aStream[nStream] = NULL;
+ aStream[nStream]->Close();
}
}
@@ -1786,11 +1773,11 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
position = 0;
nFile = 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];
+#ifdef PS2_AUDIO_PATHS
+ if(!stream->Open(PS2StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000))
+#endif
+ stream->Open(StreamedNameTable[nFile], IsThisTrackAt16KHz(nFile) ? 16000 : 32000);
if ( stream->Setup() ) {
if (position != 0)
@@ -1800,8 +1787,7 @@ cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
return TRUE;
} else {
- delete stream;
- aStream[nStream] = NULL;
+ stream->Close();
}
return FALSE;
}
@@ -1813,14 +1799,10 @@ cSampleManager::StopStreamedFile(uint8 nStream)
CStream *stream = aStream[nStream];
- if ( stream )
- {
- delete stream;
- aStream[nStream] = NULL;
+ stream->Close();
- if ( nStream == 0 )
- _bIsMp3Active = FALSE;
- }
+ if ( nStream == 0 )
+ _bIsMp3Active = FALSE;
}
int32
@@ -1830,7 +1812,7 @@ cSampleManager::GetStreamedFilePosition(uint8 nStream)
CStream *stream = aStream[nStream];
- if ( stream )
+ if ( stream->IsOpened() )
{
if ( _bIsMp3Active )
{
@@ -1868,7 +1850,7 @@ cSampleManager::SetStreamedVolumeAndPan(uint8 nVolume, uint8 nPan, uint8 nEffect
CStream *stream = aStream[nStream];
- if ( stream )
+ if ( stream->IsOpened() )
{
if ( nEffectFlag )
stream->SetVolume(m_nEffectsFadeVolume*nVolume*m_nEffectsVolume >> 14);
@@ -1894,7 +1876,7 @@ cSampleManager::IsStreamPlaying(uint8 nStream)
CStream *stream = aStream[nStream];
- if ( stream )
+ if ( stream->IsOpened() )
{
if ( stream->IsPlaying() )
return TRUE;
@@ -1910,7 +1892,7 @@ cSampleManager::Service(void)
{
CStream *stream = aStream[i];
- if ( stream )
+ if ( stream->IsOpened() )
stream->Update();
}
int refCount = CChannel::channelsThatNeedService;