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);
|
||||
}
|
||||
|
||||
//! 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.
|
||||
static cAudioVector<cAudioString>::Type getFilesInDirectory(cAudioString path)
|
||||
{
|
||||
|
|
|
@ -60,15 +60,7 @@ namespace cAudio
|
|||
|
||||
static const TCHAR* toWINSTR(const wchar_t* 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];
|
||||
return str;
|
||||
}
|
||||
|
||||
static const char* toUTF8(const cAudioString& str)
|
||||
|
@ -90,7 +82,6 @@ namespace cAudio
|
|||
if (buff_size == 0)
|
||||
return cAudioString();
|
||||
|
||||
|
||||
buffer = new 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);
|
||||
|
@ -102,7 +93,15 @@ namespace cAudio
|
|||
#else
|
||||
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)
|
||||
|
|
|
@ -39,10 +39,10 @@ namespace cAudio
|
|||
if(DeviceName.empty())
|
||||
CaptureDevice = alcCaptureOpenDevice(NULL, Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
||||
else
|
||||
CaptureDevice = alcCaptureOpenDevice(DeviceName.c_str(), Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
||||
CaptureDevice = alcCaptureOpenDevice(toUTF8(DeviceName), Frequency, convertAudioFormatEnum(Format), InternalBufferSize / SampleSize);
|
||||
if(CaptureDevice)
|
||||
{
|
||||
DeviceName = alcGetString(CaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
DeviceName = fromUTF8(alcGetString(CaptureDevice, ALC_CAPTURE_DEVICE_SPECIFIER));
|
||||
Ready = true;
|
||||
checkError();
|
||||
getLogger()->logDebug("AudioCapture", "OpenAL Capture Device Opened.");
|
||||
|
@ -214,7 +214,7 @@ namespace cAudio
|
|||
bool cAudioCapture::setDevice(const char* deviceName)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
DeviceName = safeCStr(deviceName);
|
||||
DeviceName = fromUTF8(deviceName);
|
||||
|
||||
shutdownOpenALDevice();
|
||||
return initOpenALDevice();
|
||||
|
@ -223,7 +223,7 @@ namespace cAudio
|
|||
bool cAudioCapture::initialize(const char* deviceName, unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
DeviceName = safeCStr(deviceName);
|
||||
DeviceName = fromUTF8(deviceName);
|
||||
Frequency = frequency;
|
||||
InternalBufferSize = internalBufferSize;
|
||||
|
||||
|
|
|
@ -258,10 +258,10 @@ namespace cAudio
|
|||
if(!Initialized) return NULL;
|
||||
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString audioName = safeCStr(name);
|
||||
cAudioString path = safeCStr(filename);
|
||||
cAudioString audioName = fromUTF8(name);
|
||||
cAudioString path = fromUTF8(filename);
|
||||
cAudioString ext = getExt(path);
|
||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
|
||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext));
|
||||
|
||||
if(!factory) {
|
||||
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;
|
||||
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString audioName = safeCStr(name);
|
||||
cAudioString ext = safeCStr(extension);
|
||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
|
||||
cAudioString audioName = fromUTF8(name);
|
||||
cAudioString ext = fromUTF8(extension);
|
||||
IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext));
|
||||
|
||||
if(!factory) {
|
||||
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);
|
||||
source->drop();
|
||||
|
||||
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
|
||||
IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
|
||||
if(audio != NULL)
|
||||
return audio;
|
||||
|
||||
|
@ -334,7 +334,7 @@ namespace cAudio
|
|||
if(!Initialized) return NULL;
|
||||
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString audioName = safeCStr(name);
|
||||
cAudioString audioName = fromUTF8(name);
|
||||
IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");
|
||||
|
||||
if(!factory) {
|
||||
|
@ -348,7 +348,7 @@ namespace cAudio
|
|||
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
|
||||
source->drop();
|
||||
|
||||
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
|
||||
IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
|
||||
if(audio != NULL)
|
||||
return audio;
|
||||
|
||||
|
@ -361,7 +361,7 @@ namespace cAudio
|
|||
bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString ext = safeCStr(extension);
|
||||
cAudioString ext = fromUTF8(extension);
|
||||
decodermap[ext] = factory;
|
||||
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", ext.c_str());
|
||||
return true;
|
||||
|
@ -370,7 +370,7 @@ namespace cAudio
|
|||
void cAudioManager::unRegisterAudioDecoder(const char* extension)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString ext = safeCStr(extension);
|
||||
cAudioString ext = fromUTF8(extension);
|
||||
decodermapIterator it = decodermap.find(ext);
|
||||
if(it != decodermap.end())
|
||||
{
|
||||
|
@ -382,7 +382,7 @@ namespace cAudio
|
|||
bool cAudioManager::isAudioDecoderRegistered(const char* extension)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString ext = safeCStr(extension);
|
||||
cAudioString ext = fromUTF8(extension);
|
||||
decodermapIterator it = decodermap.find(ext);
|
||||
return (it != decodermap.end());
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ namespace cAudio
|
|||
IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString ext = safeCStr(extension);
|
||||
cAudioString ext = fromUTF8(extension);
|
||||
decodermapIterator it = decodermap.find(ext);
|
||||
if(it != decodermap.end())
|
||||
{
|
||||
|
@ -413,7 +413,7 @@ namespace cAudio
|
|||
bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString safeName = safeCStr(name);
|
||||
cAudioString safeName = fromUTF8(name);
|
||||
datasourcemap[safeName] = factory;
|
||||
dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
|
||||
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
|
||||
|
@ -425,7 +425,7 @@ namespace cAudio
|
|||
void cAudioManager::unRegisterDataSource(const char* name)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString safeName = safeCStr(name);
|
||||
cAudioString safeName = fromUTF8(name);
|
||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||
if(it != datasourcemap.end())
|
||||
{
|
||||
|
@ -448,7 +448,7 @@ namespace cAudio
|
|||
bool cAudioManager::isDataSourceRegistered(const char* name)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString safeName = safeCStr(name);
|
||||
cAudioString safeName = fromUTF8(name);
|
||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||
return (it != datasourcemap.end());
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ namespace cAudio
|
|||
IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString safeName = safeCStr(name);
|
||||
cAudioString safeName = fromUTF8(name);
|
||||
datasourcemapIterator it = datasourcemap.find(safeName);
|
||||
if(it != datasourcemap.end())
|
||||
{
|
||||
|
@ -562,7 +562,7 @@ namespace cAudio
|
|||
IAudioSource* cAudioManager::getSoundByName(const char* name)
|
||||
{
|
||||
cAudioMutexBasicLock lock(Mutex);
|
||||
cAudioString audioName = safeCStr(name);
|
||||
cAudioString audioName = fromUTF8(name);
|
||||
audioIndexIterator i = audioIndex.find(audioName);
|
||||
if (i == audioIndex.end())
|
||||
{
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace cAudio
|
|||
|
||||
cFileSource::cFileSource(const char* filename) : pFile(NULL), Valid(false), Filesize(0)
|
||||
{
|
||||
cAudioString safeFilename = safeCStr(filename);
|
||||
cAudioString safeFilename = fromUTF8(filename);
|
||||
if(safeFilename.length() != 0)
|
||||
{
|
||||
pFile = fopen(safeFilename.c_str(),"rb");
|
||||
pFile = fopen(toUTF8(safeFilename),"rb");
|
||||
if(pFile)
|
||||
Valid = true;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace cAudio
|
|||
bool cLogger::registerLogReceiver(ILogReceiver* receiver, const char* name)
|
||||
{
|
||||
Mutex.lock();
|
||||
cAudioString logName = safeCStr(name);
|
||||
cAudioString logName = fromUTF8(name);
|
||||
Receivers[logName] = receiver;
|
||||
Mutex.unlock();
|
||||
return true;
|
||||
|
@ -105,7 +105,7 @@ namespace cAudio
|
|||
void cLogger::unRegisterLogReceiver(const char* name)
|
||||
{
|
||||
Mutex.lock();
|
||||
cAudioString logName = safeCStr(name);
|
||||
cAudioString logName = fromUTF8(name);
|
||||
ReceiversIterator it = Receivers.find(logName);
|
||||
if(it != Receivers.end())
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ namespace cAudio
|
|||
bool cLogger::isLogReceiverRegistered(const char* name)
|
||||
{
|
||||
Mutex.lock();
|
||||
cAudioString logName = safeCStr(name);
|
||||
cAudioString logName = fromUTF8(name);
|
||||
ReceiversIterator it = Receivers.find(logName);
|
||||
bool result = (it != Receivers.end());
|
||||
Mutex.unlock();
|
||||
|
@ -127,7 +127,7 @@ namespace cAudio
|
|||
ILogReceiver* cLogger::getLogReceiver(const char* name)
|
||||
{
|
||||
Mutex.lock();
|
||||
cAudioString logName = safeCStr(name);
|
||||
cAudioString logName = fromUTF8(name);
|
||||
ReceiversIterator it = Receivers.find(logName);
|
||||
if(it != Receivers.end())
|
||||
{
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace cAudio
|
|||
|
||||
cAudioString cOggDecoder::getType() const
|
||||
{
|
||||
return cAudioString("cOggDecoder");
|
||||
return cAudioString(_CTEXT("cOggDecoder"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -42,14 +42,14 @@ namespace cAudio
|
|||
{
|
||||
while(*deviceList)
|
||||
{
|
||||
cAudioString device(deviceList);
|
||||
cAudioString device(fromUTF8(deviceList));
|
||||
AvailableDevices.push_back(device);
|
||||
deviceList += strlen(deviceList) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 cAudioString("");
|
||||
return cAudioString(_CTEXT(""));
|
||||
}
|
||||
|
||||
cAudioString cOpenALAudioDeviceList::getDeviceDescription(unsigned int idx)
|
||||
|
|
|
@ -114,6 +114,6 @@ namespace cAudio{
|
|||
|
||||
cAudioString cRawDecoder::getType() const
|
||||
{
|
||||
return cAudioString("cRawDecoder");
|
||||
return cAudioString(_CTEXT("cRawDecoder"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ namespace cAudio
|
|||
|
||||
cAudioString cWavDecoder::getType() const
|
||||
{
|
||||
return cAudioString("cWavDecoder");
|
||||
return cAudioString(_CTEXT("cWavDecoder"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue