summaryrefslogtreecommitdiffstats
path: root/src/audio/oal/stream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/oal/stream.cpp')
-rw-r--r--src/audio/oal/stream.cpp72
1 files changed, 63 insertions, 9 deletions
diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp
index c4f1b67c..58b5dc02 100644
--- a/src/audio/oal/stream.cpp
+++ b/src/audio/oal/stream.cpp
@@ -85,10 +85,17 @@ public:
class CMP3File : public IDecoder
{
+protected:
mpg123_handle *m_pMH;
bool m_bOpened;
uint32 m_nRate;
uint32 m_nChannels;
+
+ CMP3File() :
+ m_pMH(nil),
+ m_bOpened(false),
+ m_nRate(0),
+ m_nChannels(0) {}
public:
CMP3File(const char *path) :
m_pMH(nil),
@@ -270,6 +277,51 @@ public:
};
#endif
+class CADFFile : public CMP3File
+{
+ static ssize_t r_read(void* fh, void* buf, size_t size)
+ {
+ size_t bytesRead = fread(buf, 1, size, (FILE*)fh);
+ uint8* _buf = (uint8*)buf;
+ for (int i = 0; i < size; i++)
+ _buf[i] ^= 0x22;
+ return bytesRead;
+ }
+ static off_t r_seek(void* fh, off_t pos, int seekType)
+ {
+ fseek((FILE*)fh, pos, seekType);
+ return ftell((FILE*)fh);
+ }
+ static void r_close(void* fh)
+ {
+ fclose((FILE*)fh);
+ }
+public:
+ CADFFile(const char* path)
+ {
+ m_pMH = mpg123_new(nil, nil);
+ if (m_pMH)
+ {
+ long rate = 0;
+ int channels = 0;
+ int encoding = 0;
+
+ FILE* f = fopen(path, "rb");
+
+ m_bOpened = mpg123_replace_reader_handle(m_pMH, r_read, r_seek, r_close) == MPG123_OK
+ && mpg123_open_handle(m_pMH, f) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK;
+ m_nRate = rate;
+ m_nChannels = channels;
+
+ if (IsOpened())
+ {
+ mpg123_format_none(m_pMH);
+ mpg123_format(m_pMH, rate, channels, encoding);
+ }
+ }
+ }
+};
+
void CStream::Initialise()
{
#ifndef AUDIO_OPUS
@@ -317,14 +369,16 @@ CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUF
m_pSoundFile = new CMP3File(m_aFilename);
else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".wav")], ".wav"))
m_pSoundFile = new CSndFile(m_aFilename);
+ else if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".adf")], ".adf"))
+ m_pSoundFile = new CADFFile(m_aFilename);
#else
if (!strcasecmp(&m_aFilename[strlen(m_aFilename) - strlen(".opus")], ".opus"))
m_pSoundFile = new COpusFile(m_aFilename);
#endif
else
m_pSoundFile = nil;
- ASSERT(m_pSoundFile != nil);
- if (m_pSoundFile && m_pSoundFile->IsOpened() )
+
+ if ( IsOpened() )
{
m_pBuffer = malloc(m_pSoundFile->GetBufferSize());
ASSERT(m_pBuffer!=nil);
@@ -371,14 +425,14 @@ bool CStream::HasSource()
bool CStream::IsOpened()
{
- return m_pSoundFile->IsOpened();
+ return m_pSoundFile && m_pSoundFile->IsOpened();
}
bool CStream::IsPlaying()
{
if ( !HasSource() || !IsOpened() ) return false;
- if ( m_pSoundFile->IsOpened() && !m_bPaused )
+ if ( !m_bPaused )
{
ALint sourceState;
alGetSourcei(m_alSource, AL_SOURCE_STATE, &sourceState);
@@ -446,7 +500,7 @@ void CStream::SetPan(uint8 nPan)
void CStream::SetPosMS(uint32 nPos)
{
- if ( !m_pSoundFile->IsOpened() ) return;
+ if ( !IsOpened() ) return;
m_pSoundFile->Seek(nPos);
ClearBuffers();
}
@@ -454,7 +508,7 @@ void CStream::SetPosMS(uint32 nPos)
uint32 CStream::GetPosMS()
{
if ( !HasSource() ) return 0;
- if ( !m_pSoundFile->IsOpened() ) return 0;
+ if ( !IsOpened() ) return 0;
ALint offset;
//alGetSourcei(m_alSource, AL_SAMPLE_OFFSET, &offset);
@@ -467,7 +521,7 @@ uint32 CStream::GetPosMS()
uint32 CStream::GetLengthMS()
{
- if ( !m_pSoundFile->IsOpened() ) return 0;
+ if ( !IsOpened() ) return 0;
return m_pSoundFile->GetLength();
}
@@ -475,7 +529,7 @@ bool CStream::FillBuffer(ALuint alBuffer)
{
if ( !HasSource() )
return false;
- if ( !m_pSoundFile->IsOpened() )
+ if ( !IsOpened() )
return false;
if ( !(alBuffer != AL_NONE && alIsBuffer(alBuffer)) )
return false;
@@ -517,7 +571,7 @@ void CStream::ClearBuffers()
bool CStream::Setup()
{
- if ( m_pSoundFile->IsOpened() )
+ if ( IsOpened() )
{
m_pSoundFile->Seek(0);
alSourcei(m_alSource, AL_SOURCE_RELATIVE, AL_TRUE);