Add love.audio.getOutputDevice(s).

This commit is contained in:
Miku AuahDark
2022-05-03 19:29:24 +08:00
parent 5dd7902175
commit 65b898903c
6 changed files with 88 additions and 0 deletions
+36
View File
@@ -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);
+3
View File
@@ -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.