summaryrefslogtreecommitdiffstats
path: root/src/audio/oal/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/oal/stream.h')
-rw-r--r--src/audio/oal/stream.h87
1 files changed, 81 insertions, 6 deletions
diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h
index 9a2a2fbe..bdbf19e0 100644
--- a/src/audio/oal/stream.h
+++ b/src/audio/oal/stream.h
@@ -11,6 +11,7 @@ public:
virtual ~IDecoder() { }
virtual bool IsOpened() = 0;
+ virtual void FileOpen() = 0;
virtual uint32 GetSampleSize() = 0;
virtual uint32 GetSampleCount() = 0;
@@ -48,12 +49,70 @@ public:
uint32 GetLength()
{
+ FileOpen(); // abort deferred init, we need length now - game has to cache audio file sizes
return float(GetSampleCount()) * 1000.0f / float(GetSampleRate());
}
virtual uint32 Decode(void *buffer) = 0;
};
+#ifdef MULTITHREADED_AUDIO
+template <typename T> class tsQueue
+{
+public:
+ tsQueue() : count(0) { }
+
+ void push(const T &value)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ m_queue.push(value);
+ count++;
+ }
+
+ bool peekPop(T *retVal)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (count == 0)
+ return false;
+
+ *retVal = m_queue.front();
+ m_queue.pop();
+ count--;
+ return true;
+ }
+
+ void swapNts(tsQueue<T> &replaceWith)
+ {
+ m_queue.swap(replaceWith.m_queue);
+ replaceWith.count = count;
+ }
+
+ /*
+ void swapTs(tsQueue<T> &replaceWith)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ std::lock_guard<std::mutex> lock2(replaceWith.m_mutex);
+ swapNts(replaceWith);
+ }
+ */
+
+ bool emptyNts()
+ {
+ return count == 0;
+ }
+ /*
+ bool emptyTs()
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ return emptyNts();
+ }
+ */
+
+ std::queue<T> m_queue;
+ int count;
+ mutable std::mutex m_mutex;
+};
+#endif
class CStream
{
char m_aFilename[128];
@@ -63,6 +122,16 @@ class CStream
bool m_bPaused;
bool m_bActive;
+public:
+#ifdef MULTITHREADED_AUDIO
+ std::mutex m_mutex;
+ std::queue<std::pair<ALuint, ALuint>> m_fillBuffers; // left and right buffer
+ tsQueue<std::pair<ALuint, ALuint>> m_queueBuffers;
+ bool m_bDoSeek;
+ uint32 m_SeekPos;
+ uint8 m_nDeleteMe; // 1: add to delete list 2: already on delete list
+#endif
+
void *m_pBuffer;
bool m_bReset;
@@ -72,7 +141,14 @@ class CStream
int32 m_nLoopCount;
IDecoder *m_pSoundFile;
-
+
+ void BuffersShouldBeFilled(); // all
+ bool BufferShouldBeFilledAndQueued(std::pair<ALuint, ALuint>*); // two (left-right)
+#ifdef MULTITHREADED_AUDIO
+ void FlagAsToBeProcessed(bool close = false);
+ bool QueueBuffers();
+#endif
+
bool HasSource();
void SetPosition(int i, float x, float y, float z);
void SetPitch(float pitch);
@@ -81,15 +157,15 @@ class CStream
void SetPlay(bool state);
bool FillBuffer(ALuint *alBuffer);
- int32 FillBuffers();
+ int32 FillBuffers();
void ClearBuffers();
-public:
+//public:
static void Initialise();
static void Terminate();
CStream(char *filename, ALuint *sources, ALuint (&buffers)[NUM_STREAMBUFFERS], uint32 overrideSampleRate = 32000);
~CStream();
- void Delete();
+ void Close();
bool IsOpened();
bool IsPlaying();
@@ -100,12 +176,11 @@ public:
uint32 GetPosMS();
uint32 GetLengthMS();
- bool Setup(bool imSureQueueIsEmpty = false);
+ bool Setup(bool imSureQueueIsEmpty = false, bool lock = true);
void Start();
void Stop();
void Update(void);
void SetLoopCount(int32);
-
void ProviderInit();
void ProviderTerm();