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)
|
||||||
|
@ -90,7 +82,6 @@ namespace cAudio
|
||||||
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,7 +93,15 @@ 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)
|
||||||
|
|
|
@ -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())
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,10 +14,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace cAudio
|
||||||
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;
|
||||||
|
@ -105,7 +105,7 @@ namespace cAudio
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ namespace cAudio
|
||||||
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();
|
||||||
|
@ -127,7 +127,7 @@ namespace cAudio
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
|
|
@ -178,7 +178,7 @@ namespace cAudio
|
||||||
|
|
||||||
cAudioString cOggDecoder::getType() const
|
cAudioString cOggDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cOggDecoder");
|
return cAudioString(_CTEXT("cOggDecoder"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,14 @@ namespace cAudio
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
|
|
@ -114,6 +114,6 @@ namespace cAudio{
|
||||||
|
|
||||||
cAudioString cRawDecoder::getType() const
|
cAudioString cRawDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cRawDecoder");
|
return cAudioString(_CTEXT("cRawDecoder"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ namespace cAudio
|
||||||
|
|
||||||
cAudioString cWavDecoder::getType() const
|
cAudioString cWavDecoder::getType() const
|
||||||
{
|
{
|
||||||
return cAudioString("cWavDecoder");
|
return cAudioString(_CTEXT("cWavDecoder"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue