Fixed unicode support.
This commit is contained in:
parent
d9e58fbdf9
commit
6e02974b10
|
@ -31,15 +31,6 @@ static cAudioString getExt(const cAudioString& filename)
|
||||||
return filename.substr(filename.find_last_of(_CTEXT(".")) + 1, filename.length()-filename.find_last_of(_CTEXT("."))-1);
|
return filename.substr(filename.find_last_of(_CTEXT(".")) + 1, filename.length()-filename.find_last_of(_CTEXT("."))-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Prevents a bug with NULL passed into cAudioString.
|
|
||||||
|
|
||||||
static cAudioString safeCStr(const char* str)
|
|
||||||
{
|
|
||||||
if( str != NULL ) return cAudioString(str);
|
|
||||||
else return cAudioString("");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! Returns a list of files/directories in the supplied directory. Used internally for auto-installation of plugins.
|
//! Returns a list of files/directories in the supplied directory. Used internally for auto-installation of plugins.
|
||||||
static cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
|
static cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,15 +60,7 @@ namespace cAudio
|
||||||
|
|
||||||
static const TCHAR* toWINSTR(const wchar_t* str)
|
static const TCHAR* toWINSTR(const wchar_t* str)
|
||||||
{
|
{
|
||||||
static int id = 0;
|
return str;
|
||||||
static char buffer[8][1024];
|
|
||||||
id = ++id & 0x7;
|
|
||||||
|
|
||||||
int slen = wcslen(str);
|
|
||||||
int buff_size = WideCharToMultiByte(CP_UTF8, 0, str, (int)(slen < 1023 ? slen : 1023), buffer[id], 1023, 0, false);
|
|
||||||
buffer[id][buff_size] = 0;
|
|
||||||
buffer[id][1023] = 0;
|
|
||||||
return buffer[id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* toUTF8(const cAudioString& str)
|
static const char* toUTF8(const cAudioString& str)
|
||||||
|
@ -89,8 +81,7 @@ namespace cAudio
|
||||||
int buff_size = MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), 0, 0);
|
int buff_size = MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), 0, 0);
|
||||||
if (buff_size == 0)
|
if (buff_size == 0)
|
||||||
return cAudioString();
|
return cAudioString();
|
||||||
|
|
||||||
|
|
||||||
buffer = new wchar_t[buff_size + 1];
|
buffer = new wchar_t[buff_size + 1];
|
||||||
memset((void*)buffer, 0, sizeof(wchar_t) * (buff_size + 1));
|
memset((void*)buffer, 0, sizeof(wchar_t) * (buff_size + 1));
|
||||||
MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), buffer, buff_size);
|
MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), buffer, buff_size);
|
||||||
|
@ -102,14 +93,22 @@ namespace cAudio
|
||||||
#else
|
#else
|
||||||
static const char* toWINSTR(const char* str)
|
static const char* toWINSTR(const char* str)
|
||||||
{
|
{
|
||||||
return str;
|
static int id = 0;
|
||||||
}
|
static char buffer[8][1024];
|
||||||
|
id = ++id & 0x7;
|
||||||
|
|
||||||
|
int slen = wcslen(str);
|
||||||
|
int buff_size = WideCharToMultiByte(CP_UTF8, 0, str, (int)(slen < 1023 ? slen : 1023), buffer[id], 1023, 0, false);
|
||||||
|
buffer[id][buff_size] = 0;
|
||||||
|
buffer[id][1023] = 0;
|
||||||
|
return buffer[id];
|
||||||
|
}
|
||||||
|
|
||||||
static const char* toUTF8(const cAudioString& str)
|
static const char* toUTF8(const cAudioString& str)
|
||||||
{
|
{
|
||||||
return str.c_str();
|
return str.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static cAudioString fromUTF8(const char* str)
|
static cAudioString fromUTF8(const char* str)
|
||||||
{
|
{
|
||||||
return cAudioString(str);
|
return cAudioString(str);
|
||||||
|
|
|
@ -39,10 +39,10 @@ namespace cAudio
|
||||||
if(DeviceName.empty())
|
if(DeviceName.empty())
|
||||||
CaptureDevice = alcCaptureOpenDevice(NULL, Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
CaptureDevice = alcCaptureOpenDevice(NULL, Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
||||||
else
|
else
|
||||||
CaptureDevice = alcCaptureOpenDevice(DeviceName.c_str(), Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
CaptureDevice = alcCaptureOpenDevice(toUTF8(DeviceName), Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
||||||
if(CaptureDevice)
|
if(CaptureDevice)
|
||||||
{
|
{
|
||||||
DeviceName = alcGetString(CaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER);
|
DeviceName = fromUTF8(alcGetString(CaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER));
|
||||||
Ready = true;
|
Ready = true;
|
||||||
checkError();
|
checkError();
|
||||||
getLogger()->logDebug("AudioCapture", "OpenAL Capture Device Opened.");
|
getLogger()->logDebug("AudioCapture", "OpenAL Capture Device Opened.");
|
||||||
|
@ -214,7 +214,7 @@ namespace cAudio
|
||||||
bool cAudioCapture::setDevice(const char* deviceName)
|
bool cAudioCapture::setDevice(const char* deviceName)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
DeviceName = safeCStr(deviceName);
|
DeviceName = fromUTF8(deviceName);
|
||||||
|
|
||||||
shutdownOpenALDevice();
|
shutdownOpenALDevice();
|
||||||
return initOpenALDevice();
|
return initOpenALDevice();
|
||||||
|
@ -223,7 +223,7 @@ namespace cAudio
|
||||||
bool cAudioCapture::initialize(const char* deviceName, unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
|
bool cAudioCapture::initialize(const char* deviceName, unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
DeviceName = safeCStr(deviceName);
|
DeviceName = fromUTF8(deviceName);
|
||||||
Frequency = frequency;
|
Frequency = frequency;
|
||||||
InternalBufferSize = internalBufferSize;
|
InternalBufferSize = internalBufferSize;
|
||||||
|
|
||||||
|
|
|
@ -258,10 +258,10 @@ namespace cAudio
|
||||||
if(!Initialized) return NULL;
|
if(!Initialized) return NULL;
|
||||||
|
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString audioName = safeCStr(name);
|
cAudioString audioName = fromUTF8(name);
|
||||||
cAudioString path = safeCStr(filename);
|
cAudioString path = fromUTF8(filename);
|
||||||
cAudioString ext = getExt(path);
|
cAudioString ext = getExt(path);
|
||||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
|
IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext));
|
||||||
|
|
||||||
if(!factory) {
|
if(!factory) {
|
||||||
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): No decoder could be found for (.%s).", audioName.c_str(), ext.c_str());
|
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): No decoder could be found for (.%s).", audioName.c_str(), ext.c_str());
|
||||||
|
@ -299,9 +299,9 @@ namespace cAudio
|
||||||
if(!Initialized) return NULL;
|
if(!Initialized) return NULL;
|
||||||
|
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString audioName = safeCStr(name);
|
cAudioString audioName = fromUTF8(name);
|
||||||
cAudioString ext = safeCStr(extension);
|
cAudioString ext = fromUTF8(extension);
|
||||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
|
IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext));
|
||||||
|
|
||||||
if(!factory) {
|
if(!factory) {
|
||||||
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", audioName.c_str(), ext.c_str());
|
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", audioName.c_str(), ext.c_str());
|
||||||
|
@ -314,7 +314,7 @@ namespace cAudio
|
||||||
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
|
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
|
||||||
source->drop();
|
source->drop();
|
||||||
|
|
||||||
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
|
IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
|
||||||
if(audio != NULL)
|
if(audio != NULL)
|
||||||
return audio;
|
return audio;
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ namespace cAudio
|
||||||
if(!Initialized) return NULL;
|
if(!Initialized) return NULL;
|
||||||
|
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString audioName = safeCStr(name);
|
cAudioString audioName = fromUTF8(name);
|
||||||
IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");
|
IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");
|
||||||
|
|
||||||
if(!factory) {
|
if(!factory) {
|
||||||
|
@ -348,7 +348,7 @@ namespace cAudio
|
||||||
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
|
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
|
||||||
source->drop();
|
source->drop();
|
||||||
|
|
||||||
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
|
IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
|
||||||
if(audio != NULL)
|
if(audio != NULL)
|
||||||
return audio;
|
return audio;
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ namespace cAudio
|
||||||
bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
|
bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString ext = safeCStr(extension);
|
cAudioString ext = fromUTF8(extension);
|
||||||
decodermap[ext] = factory;
|
decodermap[ext] = factory;
|
||||||
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", ext.c_str());
|
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", ext.c_str());
|
||||||
return true;
|
return true;
|
||||||
|
@ -370,7 +370,7 @@ namespace cAudio
|
||||||
void cAudioManager::unRegisterAudioDecoder(const char* extension)
|
void cAudioManager::unRegisterAudioDecoder(const char* extension)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString ext = safeCStr(extension);
|
cAudioString ext = fromUTF8(extension);
|
||||||
decodermapIterator it = decodermap.find(ext);
|
decodermapIterator it = decodermap.find(ext);
|
||||||
if(it != decodermap.end())
|
if(it != decodermap.end())
|
||||||
{
|
{
|
||||||
|
@ -382,7 +382,7 @@ namespace cAudio
|
||||||
bool cAudioManager::isAudioDecoderRegistered(const char* extension)
|
bool cAudioManager::isAudioDecoderRegistered(const char* extension)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString ext = safeCStr(extension);
|
cAudioString ext = fromUTF8(extension);
|
||||||
decodermapIterator it = decodermap.find(ext);
|
decodermapIterator it = decodermap.find(ext);
|
||||||
return (it != decodermap.end());
|
return (it != decodermap.end());
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ namespace cAudio
|
||||||
IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
|
IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString ext = safeCStr(extension);
|
cAudioString ext = fromUTF8(extension);
|
||||||
decodermapIterator it = decodermap.find(ext);
|
decodermapIterator it = decodermap.find(ext);
|
||||||
if(it != decodermap.end())
|
if(it != decodermap.end())
|
||||||
{
|
{
|
||||||
|
@ -413,7 +413,7 @@ namespace cAudio
|
||||||
bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
|
bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString safeName = safeCStr(name);
|
cAudioString safeName = fromUTF8(name);
|
||||||
datasourcemap[safeName] = factory;
|
datasourcemap[safeName] = factory;
|
||||||
dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
|
dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
|
||||||
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
|
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
|
||||||
|
@ -425,7 +425,7 @@ namespace cAudio
|
||||||
void cAudioManager::unRegisterDataSource(const char* name)
|
void cAudioManager::unRegisterDataSource(const char* name)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString safeName = safeCStr(name);
|
cAudioString safeName = fromUTF8(name);
|
||||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||||
if(it != datasourcemap.end())
|
if(it != datasourcemap.end())
|
||||||
{
|
{
|
||||||
|
@ -448,7 +448,7 @@ namespace cAudio
|
||||||
bool cAudioManager::isDataSourceRegistered(const char* name)
|
bool cAudioManager::isDataSourceRegistered(const char* name)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString safeName = safeCStr(name);
|
cAudioString safeName = fromUTF8(name);
|
||||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||||
return (it != datasourcemap.end());
|
return (it != datasourcemap.end());
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,7 @@ namespace cAudio
|
||||||
IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
|
IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString safeName = safeCStr(name);
|
cAudioString safeName = fromUTF8(name);
|
||||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||||
if(it != datasourcemap.end())
|
if(it != datasourcemap.end())
|
||||||
{
|
{
|
||||||
|
@ -562,7 +562,7 @@ namespace cAudio
|
||||||
IAudioSource* cAudioManager::getSoundByName(const char* name)
|
IAudioSource* cAudioManager::getSoundByName(const char* name)
|
||||||
{
|
{
|
||||||
cAudioMutexBasicLock lock(Mutex);
|
cAudioMutexBasicLock lock(Mutex);
|
||||||
cAudioString audioName = safeCStr(name);
|
cAudioString audioName = fromUTF8(name);
|
||||||
audioIndexIterator i = audioIndex.find(audioName);
|
audioIndexIterator i = audioIndex.find(audioName);
|
||||||
if (i == audioIndex.end())
|
if (i == audioIndex.end())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,82 +1,82 @@
|
||||||
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
||||||
// This file is part of the "cAudio Engine"
|
// This file is part of the "cAudio Engine"
|
||||||
// For conditions of distribution and use, see copyright notice in cAudio.h
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
||||||
|
|
||||||
#include "cFileSource.h"
|
#include "cFileSource.h"
|
||||||
#include "cUtils.h"
|
#include "cUtils.h"
|
||||||
|
|
||||||
#if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1
|
#if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace cAudio
|
namespace cAudio
|
||||||
{
|
{
|
||||||
|
|
||||||
cFileSource::cFileSource(const char* filename) : pFile(NULL), Valid(false), Filesize(0)
|
cFileSource::cFileSource(const char* filename) : pFile(NULL), Valid(false), Filesize(0)
|
||||||
{
|
{
|
||||||
cAudioString safeFilename = safeCStr(filename);
|
cAudioString safeFilename = fromUTF8(filename);
|
||||||
if(safeFilename.length() != 0)
|
if(safeFilename.length() != 0)
|
||||||
{
|
{
|
||||||
pFile = fopen(safeFilename.c_str(),"rb");
|
pFile = fopen(toUTF8(safeFilename),"rb");
|
||||||
if(pFile)
|
if(pFile)
|
||||||
Valid = true;
|
Valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Valid)
|
if(Valid)
|
||||||
{
|
{
|
||||||
fseek(pFile, 0, SEEK_END);
|
fseek(pFile, 0, SEEK_END);
|
||||||
Filesize = ftell(pFile);
|
Filesize = ftell(pFile);
|
||||||
fseek(pFile, 0, SEEK_SET);
|
fseek(pFile, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cFileSource::~cFileSource()
|
cFileSource::~cFileSource()
|
||||||
{
|
{
|
||||||
if(pFile)
|
if(pFile)
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cFileSource::isValid()
|
bool cFileSource::isValid()
|
||||||
{
|
{
|
||||||
return Valid;
|
return Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cFileSource::getCurrentPos()
|
int cFileSource::getCurrentPos()
|
||||||
{
|
{
|
||||||
return ftell(pFile);
|
return ftell(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cFileSource::getSize()
|
int cFileSource::getSize()
|
||||||
{
|
{
|
||||||
return Filesize;
|
return Filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cFileSource::read(void* output, int size)
|
int cFileSource::read(void* output, int size)
|
||||||
{
|
{
|
||||||
return fread(output, sizeof(char), size, pFile);
|
return fread(output, sizeof(char), size, pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cFileSource::seek(int amount, bool relative)
|
bool cFileSource::seek(int amount, bool relative)
|
||||||
{
|
{
|
||||||
if(relative == true)
|
if(relative == true)
|
||||||
{
|
{
|
||||||
int oldamount = ftell(pFile);
|
int oldamount = ftell(pFile);
|
||||||
fseek(pFile, amount, SEEK_CUR);
|
fseek(pFile, amount, SEEK_CUR);
|
||||||
|
|
||||||
//check against the absolute position
|
//check against the absolute position
|
||||||
if(oldamount+amount != ftell(pFile))
|
if(oldamount+amount != ftell(pFile))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fseek(pFile, amount, SEEK_SET);
|
fseek(pFile, amount, SEEK_SET);
|
||||||
if(amount != ftell(pFile))
|
if(amount != ftell(pFile))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,140 +1,140 @@
|
||||||
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
||||||
// This file is part of the "cAudio Engine"
|
// This file is part of the "cAudio Engine"
|
||||||
// For conditions of distribution and use, see copyright notice in cAudio.h
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "cLogger.h"
|
#include "cLogger.h"
|
||||||
#include "cConsoleLogReceiver.h"
|
#include "cConsoleLogReceiver.h"
|
||||||
#include "cFileLogReceiver.h"
|
#include "cFileLogReceiver.h"
|
||||||
#include "cUtils.h"
|
#include "cUtils.h"
|
||||||
|
|
||||||
namespace cAudio
|
namespace cAudio
|
||||||
{
|
{
|
||||||
cLogger::cLogger() : StartTime(0), MinLogLevel(ELL_INFO)
|
cLogger::cLogger() : StartTime(0), MinLogLevel(ELL_INFO)
|
||||||
{
|
{
|
||||||
StartTime = clock();
|
StartTime = clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cLogger::logCritical( const char* sender, const char *msg, ... )
|
void cLogger::logCritical( const char* sender, const char *msg, ... )
|
||||||
{
|
{
|
||||||
if(ELL_CRITICAL >= MinLogLevel)
|
if(ELL_CRITICAL >= MinLogLevel)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, msg );
|
va_start( args, msg );
|
||||||
broadcastMessage( ELL_CRITICAL, sender, msg, args );
|
broadcastMessage( ELL_CRITICAL, sender, msg, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cLogger::logError( const char* sender, const char *msg, ... )
|
void cLogger::logError( const char* sender, const char *msg, ... )
|
||||||
{
|
{
|
||||||
if(ELL_ERROR >= MinLogLevel)
|
if(ELL_ERROR >= MinLogLevel)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, msg );
|
va_start( args, msg );
|
||||||
broadcastMessage( ELL_ERROR, sender, msg, args );
|
broadcastMessage( ELL_ERROR, sender, msg, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cLogger::logWarning( const char* sender, const char *msg, ... )
|
void cLogger::logWarning( const char* sender, const char *msg, ... )
|
||||||
{
|
{
|
||||||
if(ELL_WARNING >= MinLogLevel)
|
if(ELL_WARNING >= MinLogLevel)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, msg );
|
va_start( args, msg );
|
||||||
broadcastMessage( ELL_WARNING, sender, msg, args );
|
broadcastMessage( ELL_WARNING, sender, msg, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cLogger::logInfo( const char* sender, const char *msg, ... )
|
void cLogger::logInfo( const char* sender, const char *msg, ... )
|
||||||
{
|
{
|
||||||
if(ELL_INFO >= MinLogLevel)
|
if(ELL_INFO >= MinLogLevel)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, msg );
|
va_start( args, msg );
|
||||||
broadcastMessage( ELL_INFO, sender, msg, args );
|
broadcastMessage( ELL_INFO, sender, msg, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cLogger::logDebug( const char* sender, const char *msg, ... )
|
void cLogger::logDebug( const char* sender, const char *msg, ... )
|
||||||
{
|
{
|
||||||
if(ELL_DEBUG >= MinLogLevel)
|
if(ELL_DEBUG >= MinLogLevel)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, msg );
|
va_start( args, msg );
|
||||||
broadcastMessage( ELL_DEBUG, sender, msg, args );
|
broadcastMessage( ELL_DEBUG, sender, msg, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cLogger::setLogLevel( const LogLevel& logLevel )
|
void cLogger::setLogLevel( const LogLevel& logLevel )
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
MinLogLevel = logLevel;
|
MinLogLevel = logLevel;
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
void cLogger::broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args )
|
void cLogger::broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args )
|
||||||
{
|
{
|
||||||
float messageTime = (clock() - StartTime) / (float)CLOCKS_PER_SEC;
|
float messageTime = (clock() - StartTime) / (float)CLOCKS_PER_SEC;
|
||||||
vsnprintf( TempTextBuf, 2048, msg, args );
|
vsnprintf( TempTextBuf, 2048, msg, args );
|
||||||
|
|
||||||
ReceiversIterator it = Receivers.begin();
|
ReceiversIterator it = Receivers.begin();
|
||||||
for (it = Receivers.begin(); it != Receivers.end(); it++)
|
for (it = Receivers.begin(); it != Receivers.end(); it++)
|
||||||
{
|
{
|
||||||
it->second->OnLogMessage(sender, TempTextBuf, level, messageTime);
|
it->second->OnLogMessage(sender, TempTextBuf, level, messageTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool cLogger::registerLogReceiver(ILogReceiver* receiver, const char* name)
|
bool cLogger::registerLogReceiver(ILogReceiver* receiver, const char* name)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
cAudioString logName = safeCStr(name);
|
cAudioString logName = fromUTF8(name);
|
||||||
Receivers[logName] = receiver;
|
Receivers[logName] = receiver;
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cLogger::unRegisterLogReceiver(const char* name)
|
void cLogger::unRegisterLogReceiver(const char* name)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
cAudioString logName = safeCStr(name);
|
cAudioString logName = fromUTF8(name);
|
||||||
ReceiversIterator it = Receivers.find(logName);
|
ReceiversIterator it = Receivers.find(logName);
|
||||||
if(it != Receivers.end())
|
if(it != Receivers.end())
|
||||||
{
|
{
|
||||||
Receivers.erase(it);
|
Receivers.erase(it);
|
||||||
}
|
}
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cLogger::isLogReceiverRegistered(const char* name)
|
bool cLogger::isLogReceiverRegistered(const char* name)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
cAudioString logName = safeCStr(name);
|
cAudioString logName = fromUTF8(name);
|
||||||
ReceiversIterator it = Receivers.find(logName);
|
ReceiversIterator it = Receivers.find(logName);
|
||||||
bool result = (it != Receivers.end());
|
bool result = (it != Receivers.end());
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ILogReceiver* cLogger::getLogReceiver(const char* name)
|
ILogReceiver* cLogger::getLogReceiver(const char* name)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock();
|
||||||
cAudioString logName = safeCStr(name);
|
cAudioString logName = fromUTF8(name);
|
||||||
ReceiversIterator it = Receivers.find(logName);
|
ReceiversIterator it = Receivers.find(logName);
|
||||||
if(it != Receivers.end())
|
if(it != Receivers.end())
|
||||||
{
|
{
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
Mutex.unlock();
|
Mutex.unlock();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -176,9 +176,9 @@ namespace cAudio
|
||||||
return ov_raw_tell(&oggStream);
|
return ov_raw_tell(&oggStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
cAudioString cOggDecoder::getType() const
|
cAudioString cOggDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cOggDecoder");
|
return cAudioString(_CTEXT("cOggDecoder"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cOpenALAudioDeviceList.h"
|
#include "cOpenALAudioDeviceList.h"
|
||||||
#include <al.h>
|
#include <al.h>
|
||||||
#include <alc.h>
|
#include <alc.h>
|
||||||
|
|
||||||
namespace cAudio
|
namespace cAudio
|
||||||
|
@ -15,41 +15,41 @@ namespace cAudio
|
||||||
DeviceType = deviceType;
|
DeviceType = deviceType;
|
||||||
ALCenum specifier = 0;
|
ALCenum specifier = 0;
|
||||||
ALCenum defaultDevice = 0;
|
ALCenum defaultDevice = 0;
|
||||||
|
|
||||||
if(DeviceType == DT_RECORDING)
|
if(DeviceType == DT_RECORDING)
|
||||||
{
|
{
|
||||||
specifier = ALC_CAPTURE_DEVICE_SPECIFIER;
|
specifier = ALC_CAPTURE_DEVICE_SPECIFIER;
|
||||||
defaultDevice = ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER;
|
defaultDevice = ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE )
|
if( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE )
|
||||||
{
|
{
|
||||||
specifier = ALC_ALL_DEVICES_SPECIFIER;
|
specifier = ALC_ALL_DEVICES_SPECIFIER;
|
||||||
defaultDevice = ALC_DEFAULT_ALL_DEVICES_SPECIFIER;
|
defaultDevice = ALC_DEFAULT_ALL_DEVICES_SPECIFIER;
|
||||||
}
|
}
|
||||||
else if( alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE )
|
else if( alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE )
|
||||||
{
|
{
|
||||||
specifier = ALC_DEVICE_SPECIFIER;
|
specifier = ALC_DEVICE_SPECIFIER;
|
||||||
defaultDevice = ALC_DEFAULT_DEVICE_SPECIFIER;
|
defaultDevice = ALC_DEFAULT_DEVICE_SPECIFIER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specifier != 0 && defaultDevice != 0)
|
if (specifier != 0 && defaultDevice != 0)
|
||||||
{
|
{
|
||||||
const char* deviceList = alcGetString(NULL, specifier);
|
const char* deviceList = alcGetString(NULL, specifier);
|
||||||
if (deviceList)
|
if (deviceList)
|
||||||
{
|
{
|
||||||
while(*deviceList)
|
while(*deviceList)
|
||||||
{
|
{
|
||||||
cAudioString device(deviceList);
|
cAudioString device(fromUTF8(deviceList));
|
||||||
AvailableDevices.push_back(device);
|
AvailableDevices.push_back(device);
|
||||||
deviceList += strlen(deviceList) + 1;
|
deviceList += strlen(deviceList) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the name of the 'default' capture device
|
// Get the name of the 'default' capture device
|
||||||
DefaultDevice = alcGetString(NULL, defaultDevice);
|
DefaultDevice = fromUTF8(alcGetString(NULL, defaultDevice));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ namespace cAudio
|
||||||
{
|
{
|
||||||
return AvailableDevices[idx];
|
return AvailableDevices[idx];
|
||||||
}
|
}
|
||||||
return cAudioString("");
|
return cAudioString(_CTEXT(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
cAudioString cOpenALAudioDeviceList::getDeviceDescription(unsigned int idx)
|
cAudioString cOpenALAudioDeviceList::getDeviceDescription(unsigned int idx)
|
||||||
|
|
|
@ -1,119 +1,119 @@
|
||||||
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
||||||
// This file is part of the "cAudio Engine"
|
// This file is part of the "cAudio Engine"
|
||||||
// For conditions of distribution and use, see copyright notice in cAudio.h
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
||||||
|
|
||||||
#include "cRawDecoder.h"
|
#include "cRawDecoder.h"
|
||||||
|
|
||||||
namespace cAudio{
|
namespace cAudio{
|
||||||
|
|
||||||
cRawDecoder::cRawDecoder(IDataSource* stream, unsigned int frequency, AudioFormats format) : IAudioDecoder(stream), Frequency(frequency), Format(format)
|
cRawDecoder::cRawDecoder(IDataSource* stream, unsigned int frequency, AudioFormats format) : IAudioDecoder(stream), Frequency(frequency), Format(format)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cRawDecoder::~cRawDecoder()
|
cRawDecoder::~cRawDecoder()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioFormats cRawDecoder::getFormat()
|
AudioFormats cRawDecoder::getFormat()
|
||||||
{
|
{
|
||||||
return Format;
|
return Format;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::getFrequency()
|
int cRawDecoder::getFrequency()
|
||||||
{
|
{
|
||||||
return Frequency;
|
return Frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cRawDecoder::isSeekingSupported()
|
bool cRawDecoder::isSeekingSupported()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cRawDecoder::isValid()
|
bool cRawDecoder::isValid()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::readAudioData(void* output, int amount)
|
int cRawDecoder::readAudioData(void* output, int amount)
|
||||||
{
|
{
|
||||||
return Stream->read(output,amount);
|
return Stream->read(output,amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cRawDecoder::setPosition(int position, bool relative)
|
bool cRawDecoder::setPosition(int position, bool relative)
|
||||||
{
|
{
|
||||||
Stream->seek(position,relative);
|
Stream->seek(position,relative);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cRawDecoder::seek(float seconds,bool relative)
|
bool cRawDecoder::seek(float seconds,bool relative)
|
||||||
{
|
{
|
||||||
int SampleSize = 1;
|
int SampleSize = 1;
|
||||||
if(Format == EAF_8BIT_MONO)
|
if(Format == EAF_8BIT_MONO)
|
||||||
SampleSize = 1;
|
SampleSize = 1;
|
||||||
else if(Format == EAF_8BIT_STEREO)
|
else if(Format == EAF_8BIT_STEREO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else if(Format == EAF_16BIT_MONO)
|
else if(Format == EAF_16BIT_MONO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else
|
else
|
||||||
SampleSize = 4;
|
SampleSize = 4;
|
||||||
|
|
||||||
int amountToSeek = seconds * (float)Frequency * (float)SampleSize;
|
int amountToSeek = seconds * (float)Frequency * (float)SampleSize;
|
||||||
return setPosition(amountToSeek, relative);
|
return setPosition(amountToSeek, relative);
|
||||||
}
|
}
|
||||||
|
|
||||||
float cRawDecoder::getTotalTime()
|
float cRawDecoder::getTotalTime()
|
||||||
{
|
{
|
||||||
int SampleSize = 0;
|
int SampleSize = 0;
|
||||||
if(Format == EAF_8BIT_MONO)
|
if(Format == EAF_8BIT_MONO)
|
||||||
SampleSize = 1;
|
SampleSize = 1;
|
||||||
else if(Format == EAF_8BIT_STEREO)
|
else if(Format == EAF_8BIT_STEREO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else if(Format == EAF_16BIT_MONO)
|
else if(Format == EAF_16BIT_MONO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else
|
else
|
||||||
SampleSize = 4;
|
SampleSize = 4;
|
||||||
return (float)Stream->getSize() / ((float)Frequency * (float)SampleSize);
|
return (float)Stream->getSize() / ((float)Frequency * (float)SampleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::getTotalSize()
|
int cRawDecoder::getTotalSize()
|
||||||
{
|
{
|
||||||
return Stream->getSize();
|
return Stream->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::getCompressedSize()
|
int cRawDecoder::getCompressedSize()
|
||||||
{
|
{
|
||||||
return Stream->getSize();
|
return Stream->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
float cRawDecoder::getCurrentTime()
|
float cRawDecoder::getCurrentTime()
|
||||||
{
|
{
|
||||||
int SampleSize = 0;
|
int SampleSize = 0;
|
||||||
if(Format == EAF_8BIT_MONO)
|
if(Format == EAF_8BIT_MONO)
|
||||||
SampleSize = 1;
|
SampleSize = 1;
|
||||||
else if(Format == EAF_8BIT_STEREO)
|
else if(Format == EAF_8BIT_STEREO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else if(Format == EAF_16BIT_MONO)
|
else if(Format == EAF_16BIT_MONO)
|
||||||
SampleSize = 2;
|
SampleSize = 2;
|
||||||
else
|
else
|
||||||
SampleSize = 4;
|
SampleSize = 4;
|
||||||
|
|
||||||
return (float)Stream->getCurrentPos() / ((float)Frequency * (float)SampleSize);
|
return (float)Stream->getCurrentPos() / ((float)Frequency * (float)SampleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::getCurrentPosition()
|
int cRawDecoder::getCurrentPosition()
|
||||||
{
|
{
|
||||||
return Stream->getCurrentPos();
|
return Stream->getCurrentPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cRawDecoder::getCurrentCompressedPosition()
|
int cRawDecoder::getCurrentCompressedPosition()
|
||||||
{
|
{
|
||||||
return Stream->getCurrentPos();
|
return Stream->getCurrentPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
cAudioString cRawDecoder::getType() const
|
cAudioString cRawDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cRawDecoder");
|
return cAudioString(_CTEXT("cRawDecoder"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,237 +1,237 @@
|
||||||
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
||||||
// This file is part of the "cAudio Engine"
|
// This file is part of the "cAudio Engine"
|
||||||
// For conditions of distribution and use, see copyright notice in cAudio.h
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
||||||
|
|
||||||
#include "cWavDecoder.h"
|
#include "cWavDecoder.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if CAUDIO_COMPILE_WITH_WAV_DECODER == 1
|
#if CAUDIO_COMPILE_WITH_WAV_DECODER == 1
|
||||||
|
|
||||||
namespace cAudio
|
namespace cAudio
|
||||||
{
|
{
|
||||||
cWavDecoder::cWavDecoder(IDataSource* stream) : IAudioDecoder(stream), Valid(false)
|
cWavDecoder::cWavDecoder(IDataSource* stream) : IAudioDecoder(stream), Valid(false)
|
||||||
{
|
{
|
||||||
const char* RIFFTAG = "RIFF";
|
const char* RIFFTAG = "RIFF";
|
||||||
const char* WAVETAG = "WAVE";
|
const char* WAVETAG = "WAVE";
|
||||||
const char* FORMATTAG = "fmt ";
|
const char* FORMATTAG = "fmt ";
|
||||||
const char* DATATAG = "data";
|
const char* DATATAG = "data";
|
||||||
|
|
||||||
char ident[4];
|
char ident[4];
|
||||||
int tempint32 = 0;
|
int tempint32 = 0;
|
||||||
short tempint16 = 0;
|
short tempint16 = 0;
|
||||||
char tempint8 = 0;
|
char tempint8 = 0;
|
||||||
|
|
||||||
unsigned int startOffset = 0;
|
unsigned int startOffset = 0;
|
||||||
|
|
||||||
//Read the first 4 bytes
|
//Read the first 4 bytes
|
||||||
Stream->seek(0, false);
|
Stream->seek(0, false);
|
||||||
Stream->read(ident, 4);
|
Stream->read(ident, 4);
|
||||||
//Check to see if it is a valid RIFF file
|
//Check to see if it is a valid RIFF file
|
||||||
if(strncmp(ident, RIFFTAG, 4) == 0)
|
if(strncmp(ident, RIFFTAG, 4) == 0)
|
||||||
{
|
{
|
||||||
Stream->read(&tempint32, 4);
|
Stream->read(&tempint32, 4);
|
||||||
//Check to see if the file is big enough to be valid (not completely accurate)
|
//Check to see if the file is big enough to be valid (not completely accurate)
|
||||||
if(tempint32 >= 44)
|
if(tempint32 >= 44)
|
||||||
{
|
{
|
||||||
Stream->read(ident, 4);
|
Stream->read(ident, 4);
|
||||||
//Check that it is a wave file
|
//Check that it is a wave file
|
||||||
if(strncmp(ident, WAVETAG, 4) == 0)
|
if(strncmp(ident, WAVETAG, 4) == 0)
|
||||||
{
|
{
|
||||||
//Save our position
|
//Save our position
|
||||||
startOffset = Stream->getCurrentPos();
|
startOffset = Stream->getCurrentPos();
|
||||||
|
|
||||||
//Scan for the first fmt chuck (not necessarily right after)
|
//Scan for the first fmt chuck (not necessarily right after)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Stream->read(ident, 4);
|
Stream->read(ident, 4);
|
||||||
}
|
}
|
||||||
while((strncmp(ident, FORMATTAG, 4) != 0) && (Stream->getCurrentPos() < Stream->getSize()));
|
while((strncmp(ident, FORMATTAG, 4) != 0) && (Stream->getCurrentPos() < Stream->getSize()));
|
||||||
|
|
||||||
//Did we find it?
|
//Did we find it?
|
||||||
if(Stream->getCurrentPos() < (Stream->getSize() - 16))
|
if(Stream->getCurrentPos() < (Stream->getSize() - 16))
|
||||||
{
|
{
|
||||||
//Yes, read it in
|
//Yes, read it in
|
||||||
Stream->read(&tempint32, 4);
|
Stream->read(&tempint32, 4);
|
||||||
if(tempint32 >= 16)
|
if(tempint32 >= 16)
|
||||||
{
|
{
|
||||||
//Check that it is in PCM format, we don't support compressed wavs
|
//Check that it is in PCM format, we don't support compressed wavs
|
||||||
Stream->read(&tempint16, 2);
|
Stream->read(&tempint16, 2);
|
||||||
if(tempint16 == 1)
|
if(tempint16 == 1)
|
||||||
{
|
{
|
||||||
Stream->read(&tempint16, 2);
|
Stream->read(&tempint16, 2);
|
||||||
Channels = tempint16;
|
Channels = tempint16;
|
||||||
//We only support mono or stereo wavs
|
//We only support mono or stereo wavs
|
||||||
if(Channels == 1 || Channels == 2)
|
if(Channels == 1 || Channels == 2)
|
||||||
{
|
{
|
||||||
Stream->read(&tempint32, 4);
|
Stream->read(&tempint32, 4);
|
||||||
SampleRate = tempint32;
|
SampleRate = tempint32;
|
||||||
Stream->read(&tempint32, 4);
|
Stream->read(&tempint32, 4);
|
||||||
ByteRate = tempint32;
|
ByteRate = tempint32;
|
||||||
Stream->read(&tempint16, 2);
|
Stream->read(&tempint16, 2);
|
||||||
BlockAlign = tempint16;
|
BlockAlign = tempint16;
|
||||||
Stream->read(&tempint16, 2);
|
Stream->read(&tempint16, 2);
|
||||||
BitsPerSample = tempint16;
|
BitsPerSample = tempint16;
|
||||||
|
|
||||||
//We only support 8 bit or 16 bit wavs
|
//We only support 8 bit or 16 bit wavs
|
||||||
if(BitsPerSample == 8 || BitsPerSample == 16)
|
if(BitsPerSample == 8 || BitsPerSample == 16)
|
||||||
{
|
{
|
||||||
//Reset our pointer to start scanning for the data block
|
//Reset our pointer to start scanning for the data block
|
||||||
Stream->seek(startOffset, false);
|
Stream->seek(startOffset, false);
|
||||||
//Scan for the first data chuck (not necessarily right after)
|
//Scan for the first data chuck (not necessarily right after)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Stream->read(ident, 4);
|
Stream->read(ident, 4);
|
||||||
}
|
}
|
||||||
while((strncmp(ident, DATATAG, 4) != 0) && (Stream->getCurrentPos() < Stream->getSize()));
|
while((strncmp(ident, DATATAG, 4) != 0) && (Stream->getCurrentPos() < Stream->getSize()));
|
||||||
|
|
||||||
//Did we find it?
|
//Did we find it?
|
||||||
if(Stream->getCurrentPos() < Stream->getSize())
|
if(Stream->getCurrentPos() < Stream->getSize())
|
||||||
{
|
{
|
||||||
//Get size of data block
|
//Get size of data block
|
||||||
Stream->read(&tempint32, 4);
|
Stream->read(&tempint32, 4);
|
||||||
DataSize = tempint32;
|
DataSize = tempint32;
|
||||||
DataOffset = Stream->getCurrentPos();
|
DataOffset = Stream->getCurrentPos();
|
||||||
|
|
||||||
Valid = true;
|
Valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cWavDecoder::~cWavDecoder()
|
cWavDecoder::~cWavDecoder()
|
||||||
{
|
{
|
||||||
Channels = 0;
|
Channels = 0;
|
||||||
SampleRate = 0;
|
SampleRate = 0;
|
||||||
ByteRate = 0;
|
ByteRate = 0;
|
||||||
BlockAlign = 0;
|
BlockAlign = 0;
|
||||||
BitsPerSample = 0;
|
BitsPerSample = 0;
|
||||||
DataSize = 0;
|
DataSize = 0;
|
||||||
DataOffset = 0;
|
DataOffset = 0;
|
||||||
Valid = false;
|
Valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioFormats cWavDecoder::getFormat()
|
AudioFormats cWavDecoder::getFormat()
|
||||||
{
|
{
|
||||||
if(Channels == 1 && BitsPerSample == 8)
|
if(Channels == 1 && BitsPerSample == 8)
|
||||||
return EAF_8BIT_MONO;
|
return EAF_8BIT_MONO;
|
||||||
else if(Channels == 1 && BitsPerSample == 16)
|
else if(Channels == 1 && BitsPerSample == 16)
|
||||||
return EAF_16BIT_MONO;
|
return EAF_16BIT_MONO;
|
||||||
else if(Channels == 2 && BitsPerSample == 8)
|
else if(Channels == 2 && BitsPerSample == 8)
|
||||||
return EAF_8BIT_STEREO;
|
return EAF_8BIT_STEREO;
|
||||||
else
|
else
|
||||||
return EAF_16BIT_STEREO;
|
return EAF_16BIT_STEREO;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::getFrequency()
|
int cWavDecoder::getFrequency()
|
||||||
{
|
{
|
||||||
return SampleRate;
|
return SampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cWavDecoder::isSeekingSupported()
|
bool cWavDecoder::isSeekingSupported()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cWavDecoder::isValid()
|
bool cWavDecoder::isValid()
|
||||||
{
|
{
|
||||||
return Valid;
|
return Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::readAudioData(void* output, int amount)
|
int cWavDecoder::readAudioData(void* output, int amount)
|
||||||
{
|
{
|
||||||
int currentPos = Stream->getCurrentPos();
|
int currentPos = Stream->getCurrentPos();
|
||||||
int startPos = DataOffset;
|
int startPos = DataOffset;
|
||||||
int endPos = DataOffset + DataSize;
|
int endPos = DataOffset + DataSize;
|
||||||
int amountToRead = amount;
|
int amountToRead = amount;
|
||||||
|
|
||||||
//Bounds checks (and adjustments if possible)
|
//Bounds checks (and adjustments if possible)
|
||||||
if(currentPos > endPos)
|
if(currentPos > endPos)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(currentPos < startPos)
|
if(currentPos < startPos)
|
||||||
{
|
{
|
||||||
Stream->seek(startPos, false);
|
Stream->seek(startPos, false);
|
||||||
currentPos = Stream->getCurrentPos();
|
currentPos = Stream->getCurrentPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((currentPos + amountToRead) > endPos)
|
if((currentPos + amountToRead) > endPos)
|
||||||
amountToRead = endPos - currentPos;
|
amountToRead = endPos - currentPos;
|
||||||
|
|
||||||
if(amountToRead < 0)
|
if(amountToRead < 0)
|
||||||
amountToRead = 0;
|
amountToRead = 0;
|
||||||
|
|
||||||
return Stream->read(output,amountToRead);
|
return Stream->read(output,amountToRead);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cWavDecoder::setPosition(int position, bool relative)
|
bool cWavDecoder::setPosition(int position, bool relative)
|
||||||
{
|
{
|
||||||
int currentPos = Stream->getCurrentPos();
|
int currentPos = Stream->getCurrentPos();
|
||||||
int startPos = DataOffset;
|
int startPos = DataOffset;
|
||||||
int endPos = DataOffset + DataSize;
|
int endPos = DataOffset + DataSize;
|
||||||
|
|
||||||
//Bounds checks (and adjustments if possible)
|
//Bounds checks (and adjustments if possible)
|
||||||
if(!relative && position < startPos)
|
if(!relative && position < startPos)
|
||||||
position = startPos;
|
position = startPos;
|
||||||
if(!relative && position > endPos)
|
if(!relative && position > endPos)
|
||||||
position = endPos;
|
position = endPos;
|
||||||
if(relative && currentPos + position < startPos)
|
if(relative && currentPos + position < startPos)
|
||||||
position = startPos - currentPos;
|
position = startPos - currentPos;
|
||||||
if(relative && currentPos + position > startPos)
|
if(relative && currentPos + position > startPos)
|
||||||
position = endPos - currentPos;
|
position = endPos - currentPos;
|
||||||
|
|
||||||
Stream->seek(position,relative);
|
Stream->seek(position,relative);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cWavDecoder::seek(float seconds,bool relative)
|
bool cWavDecoder::seek(float seconds,bool relative)
|
||||||
{
|
{
|
||||||
int amountToSeek = seconds * (float)SampleRate * (float)Channels * (float)(BitsPerSample/8);
|
int amountToSeek = seconds * (float)SampleRate * (float)Channels * (float)(BitsPerSample/8);
|
||||||
return setPosition(amountToSeek, relative);
|
return setPosition(amountToSeek, relative);
|
||||||
}
|
}
|
||||||
|
|
||||||
float cWavDecoder::getTotalTime()
|
float cWavDecoder::getTotalTime()
|
||||||
{
|
{
|
||||||
return (float)Stream->getSize() / ((float)SampleRate * (float)Channels * (float)(BitsPerSample/8));
|
return (float)Stream->getSize() / ((float)SampleRate * (float)Channels * (float)(BitsPerSample/8));
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::getTotalSize()
|
int cWavDecoder::getTotalSize()
|
||||||
{
|
{
|
||||||
return Stream->getSize();
|
return Stream->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::getCompressedSize()
|
int cWavDecoder::getCompressedSize()
|
||||||
{
|
{
|
||||||
return Stream->getSize();
|
return Stream->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
float cWavDecoder::getCurrentTime()
|
float cWavDecoder::getCurrentTime()
|
||||||
{
|
{
|
||||||
return (float)Stream->getCurrentPos() / ((float)SampleRate * (float)Channels * (float)(BitsPerSample/8));
|
return (float)Stream->getCurrentPos() / ((float)SampleRate * (float)Channels * (float)(BitsPerSample/8));
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::getCurrentPosition()
|
int cWavDecoder::getCurrentPosition()
|
||||||
{
|
{
|
||||||
return Stream->getCurrentPos();
|
return Stream->getCurrentPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cWavDecoder::getCurrentCompressedPosition()
|
int cWavDecoder::getCurrentCompressedPosition()
|
||||||
{
|
{
|
||||||
return Stream->getCurrentPos();
|
return Stream->getCurrentPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
cAudioString cWavDecoder::getType() const
|
cAudioString cWavDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cWavDecoder");
|
return cAudioString(_CTEXT("cWavDecoder"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue