OpenAL: continue work on it

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2799 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hyperiris 2009-03-30 14:22:31 +00:00
parent b2ed842e03
commit d9e0e89725
4 changed files with 437 additions and 10 deletions

View File

@ -15,25 +15,54 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "aldlist.h"
#include "OpenALStream.h"
#define AUDIO_NUMBUFFERS (4)
bool OpenALStream::Start()
{
return false;
}
ALDeviceList *pDeviceList = NULL;
ALCcontext *pContext = NULL;
ALCdevice *pDevice = NULL;
bool bReturn = false;
void OpenALStream::SoundLoop()
pDeviceList = new ALDeviceList();
if ((pDeviceList) && (pDeviceList->GetNumDevices()))
{
pDevice = alcOpenDevice(pDeviceList->GetDeviceName(pDeviceList->GetDefaultDevice()));
if (pDevice)
{
pContext = alcCreateContext(pDevice, NULL);
if (pContext)
{
alcMakeContextCurrent(pContext);
thread = new Common::Thread(OpenALStream::ThreadFunc, (void *)this);
bReturn = true;
}
else
{
alcCloseDevice(pDevice);
}
}
delete pDeviceList;
}
return bReturn;
}
void OpenALStream::Stop()
{
ALCcontext *pContext;
ALCdevice *pDevice;
delete thread;
pContext = alcGetCurrentContext();
pDevice = alcGetContextsDevice(pContext);
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
}
void OpenALStream::Update()
@ -41,7 +70,18 @@ void OpenALStream::Update()
}
void OpenALStream::SoundThread()
// The audio thread.
#ifdef _WIN32
DWORD WINAPI OpenALStream::ThreadFunc(void* args)
#else
void* OpenALStream::soundThread(void* args)
#endif
{
(reinterpret_cast<OpenALStream *>(args))->SoundLoop();
return 0;
}
void OpenALStream::SoundLoop()
{
}

View File

@ -42,8 +42,13 @@ public:
static bool isValid() { return true; }
virtual bool usesMixer() const { return true; }
virtual void Update();
private:
virtual void SoundThread();
#ifdef _WIN32
static DWORD WINAPI ThreadFunc(void* args);
#else
static void* soundThread(void* args);
#endif
private:
Common::Thread *thread;
Common::CriticalSection soundCriticalSection;

View File

@ -0,0 +1,333 @@
/*
* Copyright (c) 2006, Creative Labs Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of Creative Labs Inc. nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "aldlist.h"
#include "../../../../Externals/OpenAL/al/al.h"
#include "../../../../Externals/OpenAL/al/alc.h"
/*
* Init call
*/
ALDeviceList::ALDeviceList()
{
ALDEVICEINFO ALDeviceInfo;
char *devices;
s32 index;
const char *defaultDeviceName;
const char *actualDeviceName;
// DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support
vDeviceInfo.empty();
vDeviceInfo.reserve(10);
defaultDeviceIndex = 0;
// grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices
//if (LoadOAL10Library(NULL, &ALFunction) == TRUE) {
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) {
devices = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
defaultDeviceName = (char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
index = 0;
// go through device list (each device terminated with a single NULL, list terminated with double NULL)
while (*devices != NULL) {
if (strcmp(defaultDeviceName, devices) == 0) {
defaultDeviceIndex = index;
}
ALCdevice *device = alcOpenDevice(devices);
if (device) {
ALCcontext *context = alcCreateContext(device, NULL);
if (context) {
alcMakeContextCurrent(context);
// if new actual device name isn't already in the list, then add it...
actualDeviceName = alcGetString(device, ALC_DEVICE_SPECIFIER);
bool bNewName = true;
for (s32 i = 0; i < GetNumDevices(); i++) {
if (strcmp(GetDeviceName(i), actualDeviceName) == 0) {
bNewName = false;
}
}
if ((bNewName) && (actualDeviceName != NULL) && (strlen(actualDeviceName) > 0)) {
//memset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO)); // the creative was brain broken.
ALDeviceInfo.bSelected = true;
ALDeviceInfo.strDeviceName = actualDeviceName;
alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(s32), &ALDeviceInfo.iMajorVersion);
alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(s32), &ALDeviceInfo.iMinorVersion);
ALDeviceInfo.pvstrExtensions = new vector<string>;
// Check for ALC Extensions
if (alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_CAPTURE");
if (alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_EFX");
// Check for AL Extensions
if (alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_OFFSET");
if (alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_LINEAR_DISTANCE");
if (alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_EXPONENT_DISTANCE");
if (alIsExtensionPresent("EAX2.0") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("EAX2.0");
if (alIsExtensionPresent("EAX3.0") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("EAX3.0");
if (alIsExtensionPresent("EAX4.0") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("EAX4.0");
if (alIsExtensionPresent("EAX5.0") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("EAX5.0");
if (alIsExtensionPresent("EAX-RAM") == AL_TRUE)
ALDeviceInfo.pvstrExtensions->push_back("EAX-RAM");
// Get Source Count
ALDeviceInfo.uiSourceCount = GetMaxNumSources();
vDeviceInfo.push_back(ALDeviceInfo);
}
alcMakeContextCurrent(NULL);
alcDestroyContext(context);
}
alcCloseDevice(device);
}
devices += strlen(devices) + 1;
index += 1;
}
}
//}
ResetFilters();
}
/*
* Exit call
*/
ALDeviceList::~ALDeviceList()
{
for (u32 i = 0; i < vDeviceInfo.size(); i++) {
if (vDeviceInfo[i].pvstrExtensions) {
vDeviceInfo[i].pvstrExtensions->empty();
delete vDeviceInfo[i].pvstrExtensions;
}
}
vDeviceInfo.empty();
}
/*
* Returns the number of devices in the complete device list
*/
s32 ALDeviceList::GetNumDevices()
{
return (s32)vDeviceInfo.size();
}
/*
* Returns the device name at an index in the complete device list
*/
char * ALDeviceList::GetDeviceName(s32 index)
{
if (index < GetNumDevices())
return (char *)vDeviceInfo[index].strDeviceName.c_str();
else
return NULL;
}
/*
* Returns the major and minor version numbers for a device at a specified index in the complete list
*/
void ALDeviceList::GetDeviceVersion(s32 index, s32 *major, s32 *minor)
{
if (index < GetNumDevices()) {
if (major)
*major = vDeviceInfo[index].iMajorVersion;
if (minor)
*minor = vDeviceInfo[index].iMinorVersion;
}
return;
}
/*
* Returns the maximum number of Sources that can be generate on the given device
*/
u32 ALDeviceList::GetMaxNumSources(s32 index)
{
if (index < GetNumDevices())
return vDeviceInfo[index].uiSourceCount;
else
return 0;
}
/*
* Checks if the extension is supported on the given device
*/
bool ALDeviceList::IsExtensionSupported(s32 index, char *szExtName)
{
bool bReturn = false;
if (index < GetNumDevices()) {
for (u32 i = 0; i < vDeviceInfo[index].pvstrExtensions->size(); i++) {
if (!_stricmp(vDeviceInfo[index].pvstrExtensions->at(i).c_str(), szExtName)) {
bReturn = true;
break;
}
}
}
return bReturn;
}
/*
* returns the index of the default device in the complete device list
*/
s32 ALDeviceList::GetDefaultDevice()
{
return defaultDeviceIndex;
}
/*
* Deselects devices which don't have the specified minimum version
*/
void ALDeviceList::FilterDevicesMinVer(s32 major, s32 minor)
{
s32 dMajor, dMinor;
for (u32 i = 0; i < vDeviceInfo.size(); i++) {
GetDeviceVersion(i, &dMajor, &dMinor);
if ((dMajor < major) || ((dMajor == major) && (dMinor < minor))) {
vDeviceInfo[i].bSelected = false;
}
}
}
/*
* Deselects devices which don't have the specified maximum version
*/
void ALDeviceList::FilterDevicesMaxVer(s32 major, s32 minor)
{
s32 dMajor, dMinor;
for (u32 i = 0; i < vDeviceInfo.size(); i++) {
GetDeviceVersion(i, &dMajor, &dMinor);
if ((dMajor > major) || ((dMajor == major) && (dMinor > minor))) {
vDeviceInfo[i].bSelected = false;
}
}
}
/*
* Deselects device which don't support the given extension name
*/
void ALDeviceList::FilterDevicesExtension(char *szExtName)
{
bool bFound;
for (u32 i = 0; i < vDeviceInfo.size(); i++) {
bFound = false;
for (u32 j = 0; j < vDeviceInfo[i].pvstrExtensions->size(); j++) {
if (!_stricmp(vDeviceInfo[i].pvstrExtensions->at(j).c_str(), szExtName)) {
bFound = true;
break;
}
}
if (!bFound)
vDeviceInfo[i].bSelected = false;
}
}
/*
* Resets all filtering, such that all devices are in the list
*/
void ALDeviceList::ResetFilters()
{
for (s32 i = 0; i < GetNumDevices(); i++) {
vDeviceInfo[i].bSelected = true;
}
filterIndex = 0;
}
/*
* Gets index of first filtered device
*/
s32 ALDeviceList::GetFirstFilteredDevice()
{
s32 i;
for (i = 0; i < GetNumDevices(); i++) {
if (vDeviceInfo[i].bSelected == true) {
break;
}
}
filterIndex = i + 1;
return i;
}
/*
* Gets index of next filtered device
*/
s32 ALDeviceList::GetNextFilteredDevice()
{
s32 i;
for (i = filterIndex; i < GetNumDevices(); i++) {
if (vDeviceInfo[i].bSelected == true) {
break;
}
}
filterIndex = i + 1;
return i;
}
/*
* Internal function to detemine max number of Sources that can be generated
*/
u32 ALDeviceList::GetMaxNumSources()
{
ALuint uiSources[256];
u32 iSourceCount = 0;
// Clear AL Error Code
alGetError();
// Generate up to 256 Sources, checking for any errors
for (iSourceCount = 0; iSourceCount < 256; iSourceCount++)
{
alGenSources(1, &uiSources[iSourceCount]);
if (alGetError() != AL_NO_ERROR)
break;
}
// Release the Sources
alDeleteSources(iSourceCount, uiSources);
if (alGetError() != AL_NO_ERROR)
{
for (u32 i = 0; i < 256; i++)
{
alDeleteSources(1, &uiSources[i]);
}
}
return iSourceCount;
}

View File

@ -0,0 +1,49 @@
#ifndef ALDEVICELIST_H
#define ALDEVICELIST_H
#include "CommonTypes.h"
#pragma warning(disable: 4786) //disable warning "identifier was truncated to '255' characters in the browser information"
#include <vector>
#include <string>
using namespace std;
typedef struct
{
string strDeviceName;
s32 iMajorVersion;
s32 iMinorVersion;
u32 uiSourceCount;
vector<string> *pvstrExtensions;
bool bSelected;
} ALDEVICEINFO, *LPALDEVICEINFO;
class ALDeviceList
{
private:
vector<ALDEVICEINFO> vDeviceInfo;
s32 defaultDeviceIndex;
s32 filterIndex;
public:
ALDeviceList ();
~ALDeviceList ();
s32 GetNumDevices();
char *GetDeviceName(s32 index);
void GetDeviceVersion(s32 index, s32 *major, s32 *minor);
u32 GetMaxNumSources(s32 index);
bool IsExtensionSupported(s32 index, char *szExtName);
s32 GetDefaultDevice();
void FilterDevicesMinVer(s32 major, s32 minor);
void FilterDevicesMaxVer(s32 major, s32 minor);
void FilterDevicesExtension(char *szExtName);
void ResetFilters();
s32 GetFirstFilteredDevice();
s32 GetNextFilteredDevice();
private:
u32 GetMaxNumSources();
};
#endif // ALDEVICELIST_H