2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2017-06-26 00:52:51 -06:00
|
|
|
#ifdef _WIN32
|
2017-06-26 00:02:57 -06:00
|
|
|
|
2017-06-26 00:47:15 -06:00
|
|
|
#include <windows.h>
|
2017-01-23 18:44:10 -07:00
|
|
|
#include <climits>
|
2015-09-28 09:57:16 -06:00
|
|
|
#include <cstring>
|
2014-08-13 23:14:35 -06:00
|
|
|
#include <thread>
|
|
|
|
|
2014-02-18 18:11:52 -07:00
|
|
|
#include "AudioCommon/OpenALStream.h"
|
2015-09-26 15:13:07 -06:00
|
|
|
#include "Common/Logging/Log.h"
|
2016-10-07 14:55:13 -06:00
|
|
|
#include "Common/MsgHandler.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Common/Thread.h"
|
2014-09-08 22:24:49 -06:00
|
|
|
#include "Core/ConfigManager.h"
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2017-06-26 00:47:15 -06:00
|
|
|
static HMODULE s_openal_dll = nullptr;
|
|
|
|
|
|
|
|
#define OPENAL_API_VISIT(X) \
|
|
|
|
X(alBufferData) \
|
|
|
|
X(alcCloseDevice) \
|
|
|
|
X(alcCreateContext) \
|
|
|
|
X(alcDestroyContext) \
|
|
|
|
X(alcGetContextsDevice) \
|
|
|
|
X(alcGetCurrentContext) \
|
|
|
|
X(alcGetString) \
|
|
|
|
X(alcIsExtensionPresent) \
|
|
|
|
X(alcMakeContextCurrent) \
|
|
|
|
X(alcOpenDevice) \
|
|
|
|
X(alDeleteBuffers) \
|
|
|
|
X(alDeleteSources) \
|
|
|
|
X(alGenBuffers) \
|
|
|
|
X(alGenSources) \
|
|
|
|
X(alGetError) \
|
|
|
|
X(alGetSourcei) \
|
|
|
|
X(alGetString) \
|
|
|
|
X(alIsExtensionPresent) \
|
|
|
|
X(alSourcef) \
|
|
|
|
X(alSourcei) \
|
|
|
|
X(alSourcePlay) \
|
|
|
|
X(alSourceQueueBuffers) \
|
|
|
|
X(alSourceStop) \
|
|
|
|
X(alSourceUnqueueBuffers)
|
|
|
|
|
|
|
|
// Create func_t function pointer type and declare a nullptr-initialized static variable of that
|
|
|
|
// type named "pfunc".
|
|
|
|
#define DYN_FUNC_DECLARE(func) \
|
|
|
|
typedef decltype(&func) func##_t; \
|
|
|
|
static func##_t p##func = nullptr;
|
|
|
|
|
|
|
|
// Attempt to load the function from the given module handle.
|
|
|
|
#define OPENAL_FUNC_LOAD(func) \
|
|
|
|
p##func = (func##_t)::GetProcAddress(s_openal_dll, #func); \
|
|
|
|
if (!p##func) \
|
|
|
|
{ \
|
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
|
|
|
|
OPENAL_API_VISIT(DYN_FUNC_DECLARE);
|
|
|
|
|
|
|
|
static bool InitFunctions()
|
|
|
|
{
|
|
|
|
OPENAL_API_VISIT(OPENAL_FUNC_LOAD);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool InitLibrary()
|
|
|
|
{
|
|
|
|
if (s_openal_dll)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
s_openal_dll = ::LoadLibrary(TEXT("openal32.dll"));
|
|
|
|
if (!s_openal_dll)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!InitFunctions())
|
|
|
|
{
|
|
|
|
::FreeLibrary(s_openal_dll);
|
|
|
|
s_openal_dll = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenALStream::isValid()
|
|
|
|
{
|
|
|
|
return InitLibrary();
|
|
|
|
}
|
2014-08-31 06:51:38 -06:00
|
|
|
|
2009-12-20 06:54:14 -07:00
|
|
|
//
|
|
|
|
// AyuanX: Spec says OpenAL1.1 is thread safe already
|
|
|
|
//
|
2017-10-21 17:23:40 -06:00
|
|
|
bool OpenALStream::Init()
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
2017-06-26 00:47:15 -06:00
|
|
|
if (!palcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-06-26 00:12:44 -06:00
|
|
|
PanicAlertT("OpenAL: can't find sound devices");
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
const char* default_device_dame = palcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
|
|
|
|
INFO_LOG(AUDIO, "Found OpenAL device %s", default_device_dame);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
ALCdevice* device = palcOpenDevice(default_device_dame);
|
|
|
|
if (!device)
|
2017-06-26 00:12:44 -06:00
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
PanicAlertT("OpenAL: can't open device %s", default_device_dame);
|
2017-06-26 00:12:44 -06:00
|
|
|
return false;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-06-26 00:12:44 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
ALCcontext* context = palcCreateContext(device, nullptr);
|
|
|
|
if (!context)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
palcCloseDevice(device);
|
|
|
|
PanicAlertT("OpenAL: can't create context for device %s", default_device_dame);
|
2017-06-26 00:12:44 -06:00
|
|
|
return false;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
palcMakeContextCurrent(context);
|
2017-06-26 00:12:44 -06:00
|
|
|
m_run_thread.Set();
|
2017-06-17 14:16:32 -06:00
|
|
|
m_thread = std::thread(&OpenALStream::SoundLoop, this);
|
2017-06-26 00:12:44 -06:00
|
|
|
return true;
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
2017-10-21 17:23:40 -06:00
|
|
|
OpenALStream::~OpenALStream()
|
2009-07-05 20:10:26 -06:00
|
|
|
{
|
2016-08-05 08:04:39 -06:00
|
|
|
m_run_thread.Clear();
|
2016-06-24 02:43:46 -06:00
|
|
|
// kick the thread if it's waiting
|
2017-06-17 14:16:32 -06:00
|
|
|
m_sound_sync_event.Set();
|
2009-12-18 12:52:04 -07:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
m_thread.join();
|
2009-12-18 12:52:04 -07:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
palSourceStop(m_source);
|
|
|
|
palSourcei(m_source, AL_BUFFER, 0);
|
2009-12-18 12:52:04 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Clean up buffers and sources
|
2017-06-17 14:16:32 -06:00
|
|
|
palDeleteSources(1, &m_source);
|
|
|
|
m_source = 0;
|
|
|
|
palDeleteBuffers(OAL_BUFFERS, m_buffers.data());
|
2009-12-18 12:52:04 -07:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
ALCcontext* context = palcGetCurrentContext();
|
|
|
|
ALCdevice* device = palcGetContextsDevice(context);
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2017-06-26 00:47:15 -06:00
|
|
|
palcMakeContextCurrent(nullptr);
|
2017-06-17 14:16:32 -06:00
|
|
|
palcDestroyContext(context);
|
|
|
|
palcCloseDevice(device);
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
2009-12-20 06:54:14 -07:00
|
|
|
void OpenALStream::SetVolume(int volume)
|
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
m_volume = (float)volume / 100.0f;
|
2009-12-20 06:54:14 -07:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
if (m_source)
|
|
|
|
palSourcef(m_source, AL_GAIN, m_volume);
|
2009-12-20 06:54:14 -07:00
|
|
|
}
|
|
|
|
|
2009-07-05 20:10:26 -06:00
|
|
|
void OpenALStream::Update()
|
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
m_sound_sync_event.Set();
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
2017-10-21 17:23:40 -06:00
|
|
|
bool OpenALStream::SetRunning(bool running)
|
2009-11-07 13:01:39 -07:00
|
|
|
{
|
2017-10-21 13:37:39 -06:00
|
|
|
if (running)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-10-21 13:37:39 -06:00
|
|
|
palSourcePlay(m_source);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 13:37:39 -06:00
|
|
|
palSourceStop(m_source);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-10-21 17:23:40 -06:00
|
|
|
return true;
|
2009-11-07 13:01:39 -07:00
|
|
|
}
|
|
|
|
|
2016-10-04 18:57:36 -06:00
|
|
|
static ALenum CheckALError(const char* desc)
|
|
|
|
{
|
2017-06-26 00:47:15 -06:00
|
|
|
ALenum err = palGetError();
|
2016-10-04 18:57:36 -06:00
|
|
|
|
|
|
|
if (err != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
std::string type;
|
|
|
|
|
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case AL_INVALID_NAME:
|
|
|
|
type = "AL_INVALID_NAME";
|
|
|
|
break;
|
|
|
|
case AL_INVALID_ENUM:
|
|
|
|
type = "AL_INVALID_ENUM";
|
|
|
|
break;
|
|
|
|
case AL_INVALID_VALUE:
|
|
|
|
type = "AL_INVALID_VALUE";
|
|
|
|
break;
|
|
|
|
case AL_INVALID_OPERATION:
|
|
|
|
type = "AL_INVALID_OPERATION";
|
|
|
|
break;
|
|
|
|
case AL_OUT_OF_MEMORY:
|
|
|
|
type = "AL_OUT_OF_MEMORY";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "UNKNOWN_ERROR";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERROR_LOG(AUDIO, "Error %s: %08x %s", desc, err, type.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-06-06 16:21:22 -06:00
|
|
|
static bool IsCreativeXFi()
|
|
|
|
{
|
2017-06-26 00:47:15 -06:00
|
|
|
return strstr(palGetString(AL_RENDERER), "X-Fi") != nullptr;
|
2017-06-06 16:21:22 -06:00
|
|
|
}
|
|
|
|
|
2009-07-05 20:10:26 -06:00
|
|
|
void OpenALStream::SoundLoop()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
Common::SetCurrentThreadName("Audio thread - openal");
|
2011-12-30 21:22:48 -07:00
|
|
|
|
2017-06-26 00:47:15 -06:00
|
|
|
bool float32_capable = palIsExtensionPresent("AL_EXT_float32") != 0;
|
|
|
|
bool surround_capable = palIsExtensionPresent("AL_EXT_MCFORMATS") || IsCreativeXFi();
|
2017-06-06 16:21:22 -06:00
|
|
|
bool use_surround = SConfig::GetInstance().bDPL2Decoder && surround_capable;
|
2016-10-27 14:47:13 -06:00
|
|
|
|
2017-03-30 14:52:38 -06:00
|
|
|
// As there is no extension to check for 32-bit fixed point support
|
|
|
|
// and we know that only a X-Fi with hardware OpenAL supports it,
|
|
|
|
// we just check if one is being used.
|
2017-06-06 16:21:22 -06:00
|
|
|
bool fixed32_capable = IsCreativeXFi();
|
2013-06-09 01:43:27 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
u32 frequency = m_mixer->GetSampleRate();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-17 04:43:37 -06:00
|
|
|
u32 frames_per_buffer;
|
|
|
|
// Can't have zero samples per buffer
|
|
|
|
if (SConfig::GetInstance().iLatency > 0)
|
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
frames_per_buffer = frequency / 1000 * SConfig::GetInstance().iLatency / OAL_BUFFERS;
|
2017-06-17 04:43:37 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
frames_per_buffer = frequency / 1000 * 1 / OAL_BUFFERS;
|
2017-06-17 04:43:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (frames_per_buffer > OAL_MAX_FRAMES)
|
|
|
|
{
|
|
|
|
frames_per_buffer = OAL_MAX_FRAMES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DPL2 needs a minimum number of samples to work (FWRDURATION)
|
|
|
|
if (use_surround && frames_per_buffer < 240)
|
|
|
|
{
|
|
|
|
frames_per_buffer = 240;
|
|
|
|
}
|
|
|
|
|
|
|
|
INFO_LOG(AUDIO, "Using %d buffers, each with %d audio frames for a total of %d.", OAL_BUFFERS,
|
|
|
|
frames_per_buffer, frames_per_buffer * OAL_BUFFERS);
|
|
|
|
|
|
|
|
// Should we make these larger just in case the mixer ever sends more samples
|
|
|
|
// than what we request?
|
2017-06-17 14:16:32 -06:00
|
|
|
m_realtime_buffer.resize(frames_per_buffer * STEREO_CHANNELS);
|
|
|
|
m_source = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-10-04 18:57:36 -06:00
|
|
|
// Clear error state before querying or else we get false positives.
|
2017-06-26 00:47:15 -06:00
|
|
|
ALenum err = palGetError();
|
2016-10-04 18:57:36 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Generate some AL Buffers for streaming
|
2017-06-17 14:16:32 -06:00
|
|
|
palGenBuffers(OAL_BUFFERS, (ALuint*)m_buffers.data());
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("generating buffers");
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Generate a Source to playback the Buffers
|
2017-06-17 14:16:32 -06:00
|
|
|
palGenSources(1, &m_source);
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("generating sources");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Set the default sound volume as saved in the config file.
|
2017-06-17 14:16:32 -06:00
|
|
|
palSourcef(m_source, AL_GAIN, m_volume);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// TODO: Error handling
|
|
|
|
// ALenum err = alGetError();
|
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
unsigned int next_buffer = 0;
|
|
|
|
unsigned int num_buffers_queued = 0;
|
|
|
|
ALint state = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-05 08:04:39 -06:00
|
|
|
while (m_run_thread.IsSet())
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-10-01 21:55:40 -06:00
|
|
|
// Block until we have a free buffer
|
2017-06-17 14:16:32 -06:00
|
|
|
int num_buffers_processed;
|
|
|
|
palGetSourcei(m_source, AL_BUFFERS_PROCESSED, &num_buffers_processed);
|
|
|
|
if (num_buffers_queued == OAL_BUFFERS && !num_buffers_processed)
|
2016-10-01 21:55:40 -06:00
|
|
|
{
|
2017-06-17 14:21:29 -06:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
2016-10-01 21:55:40 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the Buffer from the Queue.
|
2017-06-17 14:16:32 -06:00
|
|
|
if (num_buffers_processed)
|
2016-10-01 21:55:40 -06:00
|
|
|
{
|
2017-06-16 15:54:38 -06:00
|
|
|
std::array<ALuint, OAL_BUFFERS> unqueued_buffer_ids;
|
|
|
|
palSourceUnqueueBuffers(m_source, num_buffers_processed, unqueued_buffer_ids.data());
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("unqueuing buffers");
|
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
num_buffers_queued -= num_buffers_processed;
|
2016-10-01 21:55:40 -06:00
|
|
|
}
|
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
unsigned int min_frames = frames_per_buffer;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-06 16:21:22 -06:00
|
|
|
if (use_surround)
|
2016-10-01 21:56:25 -06:00
|
|
|
{
|
2017-06-16 15:54:38 -06:00
|
|
|
std::array<float, OAL_MAX_FRAMES * SURROUND_CHANNELS> dpl2;
|
|
|
|
u32 rendered_frames = m_mixer->MixSurround(dpl2.data(), min_frames);
|
2017-04-23 19:05:21 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
if (rendered_frames < min_frames)
|
2017-04-23 19:05:21 -06:00
|
|
|
continue;
|
2016-10-01 21:56:25 -06:00
|
|
|
|
|
|
|
// zero-out the subwoofer channel - DPL2Decode generates a pretty
|
|
|
|
// good 5.0 but not a good 5.1 output. Sadly there is not a 5.0
|
|
|
|
// AL_FORMAT_50CHN32 to make this super-explicit.
|
|
|
|
// DPL2Decode output: LEFTFRONT, RIGHTFRONT, CENTREFRONT, (sub), LEFTREAR, RIGHTREAR
|
2017-06-17 14:16:32 -06:00
|
|
|
for (u32 i = 0; i < rendered_frames; ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-10-01 21:56:25 -06:00
|
|
|
dpl2[i * SURROUND_CHANNELS + 3 /*sub/lfe*/] = 0.0f;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2016-10-01 21:56:25 -06:00
|
|
|
if (float32_capable)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-06-16 15:54:38 -06:00
|
|
|
palBufferData(m_buffers[next_buffer], AL_FORMAT_51CHN32, dpl2.data(),
|
2017-06-17 14:16:32 -06:00
|
|
|
rendered_frames * FRAME_SURROUND_FLOAT, frequency);
|
2016-10-01 21:56:25 -06:00
|
|
|
}
|
2016-10-27 14:47:13 -06:00
|
|
|
else if (fixed32_capable)
|
|
|
|
{
|
2017-06-16 15:54:38 -06:00
|
|
|
std::array<int, OAL_MAX_FRAMES * SURROUND_CHANNELS> surround_int32;
|
2016-10-27 14:47:13 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
for (u32 i = 0; i < rendered_frames * SURROUND_CHANNELS; ++i)
|
2016-10-27 14:47:13 -06:00
|
|
|
{
|
|
|
|
// For some reason the ffdshow's DPL2 decoder outputs samples bigger than 1.
|
|
|
|
// Most are close to 2.5 and some go up to 8. Hard clamping here, we need to
|
|
|
|
// fix the decoder or implement a limiter.
|
|
|
|
dpl2[i] = dpl2[i] * (INT64_C(1) << 31);
|
|
|
|
if (dpl2[i] > INT_MAX)
|
|
|
|
surround_int32[i] = INT_MAX;
|
|
|
|
else if (dpl2[i] < INT_MIN)
|
|
|
|
surround_int32[i] = INT_MIN;
|
|
|
|
else
|
2017-06-16 15:54:38 -06:00
|
|
|
surround_int32[i] = static_cast<int>(dpl2[i]);
|
2016-10-27 14:47:13 -06:00
|
|
|
}
|
|
|
|
|
2017-06-16 15:54:38 -06:00
|
|
|
palBufferData(m_buffers[next_buffer], AL_FORMAT_51CHN32, surround_int32.data(),
|
2017-06-17 14:16:32 -06:00
|
|
|
rendered_frames * FRAME_SURROUND_INT32, frequency);
|
2016-10-27 14:47:13 -06:00
|
|
|
}
|
2016-10-01 21:56:25 -06:00
|
|
|
else
|
|
|
|
{
|
2017-06-16 15:54:38 -06:00
|
|
|
std::array<short, OAL_MAX_FRAMES * SURROUND_CHANNELS> surround_short;
|
2016-10-27 14:47:13 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
for (u32 i = 0; i < rendered_frames * SURROUND_CHANNELS; ++i)
|
2016-10-27 14:47:13 -06:00
|
|
|
{
|
|
|
|
dpl2[i] = dpl2[i] * (1 << 15);
|
|
|
|
if (dpl2[i] > SHRT_MAX)
|
|
|
|
surround_short[i] = SHRT_MAX;
|
|
|
|
else if (dpl2[i] < SHRT_MIN)
|
|
|
|
surround_short[i] = SHRT_MIN;
|
|
|
|
else
|
2017-06-16 15:54:38 -06:00
|
|
|
surround_short[i] = static_cast<int>(dpl2[i]);
|
2016-10-27 14:47:13 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-16 15:54:38 -06:00
|
|
|
palBufferData(m_buffers[next_buffer], AL_FORMAT_51CHN16, surround_short.data(),
|
2017-06-17 14:16:32 -06:00
|
|
|
rendered_frames * FRAME_SURROUND_SHORT, frequency);
|
2016-10-01 21:56:25 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("buffering data");
|
2016-10-01 21:56:25 -06:00
|
|
|
if (err == AL_INVALID_ENUM)
|
|
|
|
{
|
|
|
|
// 5.1 is not supported by the host, fallback to stereo
|
|
|
|
WARN_LOG(AUDIO,
|
|
|
|
"Unable to set 5.1 surround mode. Updating OpenAL Soft might fix this issue.");
|
2017-06-06 16:21:22 -06:00
|
|
|
use_surround = false;
|
2016-10-01 21:56:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-17 14:16:32 -06:00
|
|
|
u32 rendered_frames = m_mixer->Mix(m_realtime_buffer.data(), min_frames);
|
2017-04-23 19:05:21 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
if (!rendered_frames)
|
2017-04-23 19:05:21 -06:00
|
|
|
continue;
|
|
|
|
|
2017-06-16 15:54:19 -06:00
|
|
|
palBufferData(m_buffers[next_buffer], AL_FORMAT_STEREO16, m_realtime_buffer.data(),
|
|
|
|
rendered_frames * FRAME_STEREO_SHORT, frequency);
|
2016-10-01 21:56:25 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
palSourceQueueBuffers(m_source, 1, &m_buffers[next_buffer]);
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("queuing buffers");
|
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
num_buffers_queued++;
|
|
|
|
next_buffer = (next_buffer + 1) % OAL_BUFFERS;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-06-17 14:16:32 -06:00
|
|
|
palGetSourcei(m_source, AL_SOURCE_STATE, &state);
|
|
|
|
if (state != AL_PLAYING)
|
2016-10-01 21:56:25 -06:00
|
|
|
{
|
|
|
|
// Buffer underrun occurred, resume playback
|
2017-06-17 14:16:32 -06:00
|
|
|
palSourcePlay(m_source);
|
2016-10-04 18:57:36 -06:00
|
|
|
err = CheckALError("occurred resuming playback");
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
2009-07-05 20:10:26 -06:00
|
|
|
}
|
|
|
|
|
2017-06-26 00:52:51 -06:00
|
|
|
#endif // _WIN32
|