mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +02:00
Add love.audio.setOutputDevice
This commit is contained in:
@@ -98,7 +98,7 @@ static const char *getDeviceSpecifier(ALCdevice *device)
|
||||
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
||||
constexpr ALCenum ALC_ALL_DEVICES_SPECIFIER = 0x1013;
|
||||
#endif
|
||||
static ALCenum deviceEnum = alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT")
|
||||
static ALCenum deviceEnum = alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT") == ALC_TRUE
|
||||
? ALC_ALL_DEVICES_SPECIFIER
|
||||
: ALC_DEVICE_SPECIFIER;
|
||||
|
||||
@@ -112,6 +112,9 @@ Audio::Audio()
|
||||
, poolThread(nullptr)
|
||||
, distanceModel(DISTANCE_INVERSE_CLAMPED)
|
||||
{
|
||||
attribs.push_back(0);
|
||||
attribs.push_back(0);
|
||||
|
||||
// Before opening new device, check if recording
|
||||
// is requested.
|
||||
if (getRequestRecordingPermission())
|
||||
@@ -134,12 +137,11 @@ Audio::Audio()
|
||||
throw love::Exception("Could not open device.");
|
||||
|
||||
#ifdef ALC_EXT_EFX
|
||||
ALint attribs[4] = { ALC_MAX_AUXILIARY_SENDS, MAX_SOURCE_EFFECTS, 0, 0 };
|
||||
#else
|
||||
ALint *attribs = nullptr;
|
||||
attribs.insert(attribs.begin(), ALC_MAX_AUXILIARY_SENDS);
|
||||
attribs.insert(attribs.begin() + 1, MAX_SOURCE_EFFECTS);
|
||||
#endif
|
||||
|
||||
context = alcCreateContext(device, attribs);
|
||||
context = alcCreateContext(device, attribs.data());
|
||||
|
||||
if (context == nullptr)
|
||||
throw love::Exception("Could not create context.");
|
||||
@@ -350,6 +352,29 @@ void Audio::getOutputDevices(std::vector<std::string> &list)
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::setOutputDevice(const char* name)
|
||||
{
|
||||
#undef ALC_SOFT_reopen_device
|
||||
#ifndef ALC_SOFT_reopen_device
|
||||
typedef ALCboolean (ALC_APIENTRY*LPALCREOPENDEVICESOFT)(ALCdevice *device,
|
||||
const ALCchar *deviceName, const ALCint *attribs);
|
||||
#endif
|
||||
static LPALCREOPENDEVICESOFT alcReopenDeviceSOFT = alcIsExtensionPresent(device, "ALC_SOFT_reopen_device") == ALC_TRUE
|
||||
? (LPALCREOPENDEVICESOFT) alcGetProcAddress(device, "alcReopenDeviceSOFT")
|
||||
: nullptr;
|
||||
|
||||
if (alcReopenDeviceSOFT == nullptr)
|
||||
{
|
||||
// Default implementation throws exception. To make
|
||||
// error message consistent, call the base class.
|
||||
love::audio::Audio::setOutputDevice(name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (alcReopenDeviceSOFT(device, (const ALCchar *) name, attribs.data()) == ALC_FALSE)
|
||||
throw love::Exception("Cannot set output device: %s", alcGetString(device, alcGetError(device)));
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
alListenerf(AL_GAIN, volume);
|
||||
|
||||
@@ -129,6 +129,7 @@ public:
|
||||
|
||||
std::string getOutputDevice();
|
||||
void getOutputDevices(std::vector<std::string> &list);
|
||||
void setOutputDevice(const char *name);
|
||||
|
||||
private:
|
||||
void initializeEFX();
|
||||
@@ -140,6 +141,7 @@ private:
|
||||
|
||||
// The OpenAL context.
|
||||
ALCcontext *context;
|
||||
std::vector<ALCint> attribs;
|
||||
|
||||
// The OpenAL effects
|
||||
struct EffectMapStorage
|
||||
|
||||
Reference in New Issue
Block a user