Enumerate audio devices, add multi-audio rendering

This commit is contained in:
2016-07-27 16:52:10 +10:00
parent 9c3df0c488
commit 54dd5c84fa
3 changed files with 60 additions and 3 deletions
+42 -3
View File
@@ -5,12 +5,12 @@
#include "Dengine/Assets.h"
#include "Dengine/Audio.h"
#include "Dengine/Common.h"
#include "Dengine/Debug.h"
#define AL_CHECK_ERROR() alCheckError_(__FILE__, __LINE__);
void alCheckError_(const char *file, int line)
{
// NOTE(doyle): OpenAL error stack is 1 deep
ALenum errorCode;
while ((errorCode = alGetError()) != AL_NO_ERROR)
{
@@ -40,16 +40,50 @@ void alCheckError_(const char *file, int line)
}
};
const i32 audio_rendererInit(AudioRenderer *audioRenderer)
const i32 audio_init()
{
/* Clear error stack */
alGetError();
ALCdevice *deviceAL = alcOpenDevice(NULL);
ALboolean enumerateAudioDevice =
alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT");
const ALCchar *device = NULL;
if (enumerateAudioDevice == AL_TRUE)
{
// TODO(doyle): Actually allow users to choose device to output
/*
The OpenAL specification says that the list of devices is organized as
a string devices are separated with a NULL character and the list is
terminated by two NULL characters.
alcGetString with NULL = get all device spcifiers not a particular one
*/
device = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
const ALCchar *next = device + 1;
size_t len = 0;
printf("Devices list:\n");
printf("----------\n");
while (device && *device != '\0' && next && *next != '\0')
{
printf("%s\n", device);
len = common_strlen(device);
device += (len + 1);
next += (len + 2);
}
printf("----------\n");
}
/* Get audio device */
ALCdevice *deviceAL = alcOpenDevice(device);
if (!deviceAL)
{
printf("alcOpenDevice() failed: Failed to init OpenAL device.\n");
return -1;
}
/* Set device context */
ALCcontext *contextAL = alcCreateContext(deviceAL, NULL);
alcMakeContextCurrent(contextAL);
if (!contextAL)
@@ -59,6 +93,11 @@ const i32 audio_rendererInit(AudioRenderer *audioRenderer)
}
AL_CHECK_ERROR();
return 0;
}
const i32 audio_rendererInit(AudioRenderer *audioRenderer)
{
/* Generate number of concurrent audio file listeners */
alGenSources(ARRAY_COUNT(audioRenderer->sourceId), audioRenderer->sourceId);
AL_CHECK_ERROR();