mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
made device enumeration lazy
made enumerator to first attempt aquire default device name by standard means, then to fall back to read name from opened device getRecordingDeviceCount removed for being redundant --HG-- branch : minor-mic-input
This commit is contained in:
@@ -110,29 +110,6 @@ Audio::Audio()
|
||||
if (!alcMakeContextCurrent(context) || alcGetError(device) != ALC_NO_ERROR)
|
||||
throw love::Exception("Could not make context current.");
|
||||
|
||||
//find and push default capture device
|
||||
//AL may not return actual device name string when asked directly
|
||||
std::string defaultname;
|
||||
ALCdevice *defaultdevice = alcCaptureOpenDevice(NULL, 8000, 8, 1);
|
||||
if (alGetError() == AL_NO_ERROR)
|
||||
{
|
||||
defaultname = alcGetString(defaultdevice, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
alcCaptureCloseDevice(defaultdevice);
|
||||
capture.push_back(new RecordingDevice(defaultname.c_str(), 0));
|
||||
}
|
||||
|
||||
const ALCchar *devstr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
if (devstr[offset] == '\0')
|
||||
break;
|
||||
std::string str((ALCchar*)&devstr[offset]);
|
||||
if (str != defaultname)
|
||||
capture.push_back(new RecordingDevice(str.c_str(), capture.size()));
|
||||
offset += str.length() + 1;
|
||||
}
|
||||
|
||||
// pool must be allocated after AL context.
|
||||
try
|
||||
{
|
||||
@@ -336,26 +313,41 @@ void Audio::setDistanceModel(DistanceModel distanceModel)
|
||||
}
|
||||
}
|
||||
|
||||
int Audio::getRecordingDeviceCount() const
|
||||
std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices()
|
||||
{
|
||||
return capture.size();
|
||||
}
|
||||
if (capture.size() == 0)
|
||||
{
|
||||
std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
|
||||
|
||||
love::audio::RecordingDevice *Audio::getRecordingDevice(int index) const
|
||||
{
|
||||
if (index < 0 || (unsigned int)index >= capture.size())
|
||||
return nullptr;
|
||||
//no device name obtained from AL, fallback to reading from device
|
||||
if (defaultname.length() == 0)
|
||||
{
|
||||
//use some safe basic parameters - 8 kHz, 8 bits, 1 channel
|
||||
ALCdevice *defaultdevice = alcCaptureOpenDevice(NULL, 8000, 8, 1);
|
||||
if (alGetError() == AL_NO_ERROR)
|
||||
{
|
||||
defaultname = alcGetString(defaultdevice, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
alcCaptureCloseDevice(defaultdevice);
|
||||
}
|
||||
else
|
||||
//failed to open default recording device - bail, return empty list
|
||||
return &capture;
|
||||
}
|
||||
capture.push_back(new RecordingDevice(defaultname.c_str(), 0));
|
||||
|
||||
return capture[index];
|
||||
}
|
||||
|
||||
int Audio::getRecordingDeviceIndex(love::audio::RecordingDevice *device) const
|
||||
{
|
||||
for (unsigned int i = 0; i < capture.size(); i++)
|
||||
if (device == capture[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
const ALCchar *devstr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
size_t offset = 0;
|
||||
while (true)
|
||||
{
|
||||
if (devstr[offset] == '\0')
|
||||
break;
|
||||
std::string str((ALCchar*)&devstr[offset]);
|
||||
if (str != defaultname)
|
||||
capture.push_back(new RecordingDevice(str.c_str(), capture.size()));
|
||||
offset += str.length() + 1;
|
||||
}
|
||||
}
|
||||
return &capture;
|
||||
}
|
||||
|
||||
} // openal
|
||||
|
||||
@@ -105,9 +105,7 @@ public:
|
||||
void setDopplerScale(float scale);
|
||||
float getDopplerScale() const;
|
||||
|
||||
int getRecordingDeviceCount() const;
|
||||
love::audio::RecordingDevice *getRecordingDevice(int index) const;
|
||||
int getRecordingDeviceIndex(love::audio::RecordingDevice *device) const;
|
||||
std::vector<love::audio::RecordingDevice*> *getRecordingDevices();
|
||||
|
||||
DistanceModel getDistanceModel() const;
|
||||
void setDistanceModel(DistanceModel distanceModel);
|
||||
|
||||
@@ -155,7 +155,7 @@ int RecordingDevice::getID() const
|
||||
|
||||
bool RecordingDevice::isRecording() const
|
||||
{
|
||||
return device == nullptr ? false : true;
|
||||
return device != nullptr;
|
||||
}
|
||||
|
||||
} //openal
|
||||
|
||||
Reference in New Issue
Block a user