From 8aac6060d36c5dca48c02988b654d4646b175e64 Mon Sep 17 00:00:00 2001 From: Fire-Head Date: Mon, 4 May 2020 20:33:48 +0300 Subject: oal upd --- src/audio/oal/stream.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/audio/oal/stream.h (limited to 'src/audio/oal/stream.h') diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h new file mode 100644 index 00000000..666d42e0 --- /dev/null +++ b/src/audio/oal/stream.h @@ -0,0 +1,57 @@ +#pragma once +#include "common.h" + +#ifdef AUDIO_OAL +#include + +#define NUM_STREAMBUFFERS 5 +#define STREAMBUFFER_SIZE 0x4000 + +class CStream +{ + char m_aFilename[128]; + ALuint &m_alSource; + ALuint (&m_alBuffers)[NUM_STREAMBUFFERS]; + + bool m_bIsOpened; + bool m_bPaused; + + uint32 m_nLength; + uint32 m_nLengthMS; + uint32 m_nBitRate; + + unsigned long m_nFormat; + unsigned long m_nFreq; + + uint32 m_nBufferSize; + void *m_pBuffer; + + ALint iTotalBuffersProcessed; + + bool FillBuffer(ALuint alBuffer); + int32 FillBuffers(); +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 SetPos (uint32 nPos); + + uint32 GetPos(); + uint32 GetLength(); + + bool Setup(); + void Start(); + void Update(void); +}; + +#endif \ No newline at end of file -- cgit v1.2.3 From 12a3499ca365756a77958d616423aca39a23234b Mon Sep 17 00:00:00 2001 From: Fire-Head Date: Thu, 7 May 2020 09:26:16 +0300 Subject: oal wav/mp3 stream update --- src/audio/oal/stream.h | 89 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 17 deletions(-) (limited to 'src/audio/oal/stream.h') diff --git a/src/audio/oal/stream.h b/src/audio/oal/stream.h index 666d42e0..f1e5f458 100644 --- a/src/audio/oal/stream.h +++ b/src/audio/oal/stream.h @@ -4,8 +4,56 @@ #ifdef AUDIO_OAL #include -#define NUM_STREAMBUFFERS 5 -#define STREAMBUFFER_SIZE 0x4000 +#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 { @@ -13,30 +61,34 @@ class CStream ALuint &m_alSource; ALuint (&m_alBuffers)[NUM_STREAMBUFFERS]; - bool m_bIsOpened; bool m_bPaused; - - uint32 m_nLength; - uint32 m_nLengthMS; - uint32 m_nBitRate; - - unsigned long m_nFormat; - unsigned long m_nFreq; + bool m_bActive; - uint32 m_nBufferSize; void *m_pBuffer; - ALint iTotalBuffersProcessed; + 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(); @@ -44,14 +96,17 @@ public: void SetPause (bool bPause); void SetVolume(uint32 nVol); void SetPan (uint8 nPan); - void SetPos (uint32 nPos); - - uint32 GetPos(); - uint32 GetLength(); + 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 -- cgit v1.2.3