mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Add love.audio.getOutputDevice(s).
This commit is contained in:
@@ -93,6 +93,18 @@ ALenum Audio::getFormat(int bitDepth, int channels)
|
||||
return AL_NONE;
|
||||
}
|
||||
|
||||
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")
|
||||
? ALC_ALL_DEVICES_SPECIFIER
|
||||
: ALC_DEVICE_SPECIFIER;
|
||||
|
||||
return alcGetString(device, deviceEnum);
|
||||
}
|
||||
|
||||
Audio::Audio()
|
||||
: device(nullptr)
|
||||
, context(nullptr)
|
||||
@@ -314,6 +326,30 @@ void Audio::resumeContext()
|
||||
alcMakeContextCurrent(context);
|
||||
}
|
||||
|
||||
std::string Audio::getOutputDevice()
|
||||
{
|
||||
const char *dev = getDeviceSpecifier(device);
|
||||
|
||||
if (dev == nullptr)
|
||||
throw Exception("Failed to get current device: %s", alcGetString(device, alcGetError(device)));
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void Audio::getOutputDevices(std::vector<std::string> &list)
|
||||
{
|
||||
const char *devices = getDeviceSpecifier(nullptr);
|
||||
|
||||
if (devices == nullptr)
|
||||
throw Exception("Failed to enumerate devices: %s", alcGetString(nullptr, alcGetError(nullptr)));
|
||||
|
||||
for (const char *device = devices; *device; device++)
|
||||
{
|
||||
list.emplace_back(device);
|
||||
device += list.back().length();
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
alListenerf(AL_GAIN, volume);
|
||||
|
||||
@@ -127,6 +127,9 @@ public:
|
||||
|
||||
bool getEffectID(const char *name, ALuint &id);
|
||||
|
||||
std::string getOutputDevice();
|
||||
void getOutputDevices(std::vector<std::string> &list);
|
||||
|
||||
private:
|
||||
void initializeEFX();
|
||||
// The OpenAL device.
|
||||
|
||||
Reference in New Issue
Block a user