summaryrefslogtreecommitdiffstats
path: root/src/audio/oal/stream.h
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2020-05-11 22:21:26 +0200
committeraap <aap@papnet.eu>2020-05-11 22:21:26 +0200
commit0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2 (patch)
tree16bf11e0e8a0353448a643322e9511e8ba659fca /src/audio/oal/stream.h
parentCVisibilityPlugins (diff)
parentMerge remote-tracking branch 'origin/master' into miami (diff)
downloadre3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar.gz
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar.bz2
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar.lz
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar.xz
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.tar.zst
re3-0eb5f93e96bfc4b31c0bde01e9f1296b3b612bc2.zip
Diffstat (limited to 'src/audio/oal/stream.h')
-rw-r--r--src/audio/oal/stream.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h
new file mode 100644
index 00000000..f1e5f458
--- /dev/null
+++ b/src/audio/oal/stream.h
@@ -0,0 +1,112 @@
+#pragma once
+#include "common.h"
+
+#ifdef AUDIO_OAL
+#include <AL/al.h>
+
+#define NUM_STREAMBUFFERS 4
+
+class IDecoder
+{
+public:
+ virtual ~IDecoder() { }
+
+ virtual bool IsOpened() = 0;
+
+ virtual uint32 GetSampleSize() = 0;
+ virtual uint32 GetSampleCount() = 0;
+ virtual uint32 GetSampleRate() = 0;
+ virtual uint32 GetChannels() = 0;
+
+ uint32 GetAvgSamplesPerSec()
+ {
+ return GetChannels() * GetSampleRate();
+ }
+
+ uint32 ms2samples(uint32 ms)
+ {
+ return float(ms) / 1000.0f * float(GetChannels()) * float(GetSampleRate());
+ }
+
+ uint32 samples2ms(uint32 sm)
+ {
+ return float(sm) * 1000.0f / float(GetChannels()) / float(GetSampleRate());
+ }
+
+ uint32 GetBufferSamples()
+ {
+ //return (GetAvgSamplesPerSec() >> 2) - (GetSampleCount() % GetChannels());
+ return (GetAvgSamplesPerSec() / 4); // 250ms
+ }
+
+ uint32 GetBufferSize()
+ {
+ return GetBufferSamples() * GetSampleSize();
+ }
+
+ virtual void Seek(uint32 milliseconds) = 0;
+ virtual uint32 Tell() = 0;
+
+ uint32 GetLength()
+ {
+ return float(GetSampleCount()) * 1000.0f / float(GetSampleRate());
+ }
+
+ virtual uint32 Decode(void *buffer) = 0;
+};
+
+class CStream
+{
+ char m_aFilename[128];
+ ALuint &m_alSource;
+ ALuint (&m_alBuffers)[NUM_STREAMBUFFERS];
+
+ bool m_bPaused;
+ bool m_bActive;
+
+ void *m_pBuffer;
+
+ bool m_bReset;
+ uint32 m_nVolume;
+ uint8 m_nPan;
+ uint32 m_nPosBeforeReset;
+
+ IDecoder *m_pSoundFile;
+
+ bool HasSource();
+ void SetPosition(float x, float y, float z);
+ void SetPitch(float pitch);
+ void SetGain(float gain);
+ void Pause();
+ void SetPlay(bool state);
+
+ bool FillBuffer(ALuint alBuffer);
+ int32 FillBuffers();
+ void ClearBuffers();
+public:
+ static void Initialise();
+ static void Terminate();
+
+ CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUFFERS]);
+ ~CStream();
+ void Delete();
+
+ bool IsOpened();
+ bool IsPlaying();
+ void SetPause (bool bPause);
+ void SetVolume(uint32 nVol);
+ void SetPan (uint8 nPan);
+ void SetPosMS (uint32 nPos);
+ uint32 GetPosMS();
+ uint32 GetLengthMS();
+
+ bool Setup();
+ void Start();
+ void Stop();
+ void Update(void);
+
+ void ProviderInit();
+ void ProviderTerm();
+};
+
+#endif \ No newline at end of file