|
@@ -110,29 +110,6 @@ Audio::Audio()
|
|
if (!alcMakeContextCurrent(context) || alcGetError(device) != ALC_NO_ERROR)
|
|
if (!alcMakeContextCurrent(context) || alcGetError(device) != ALC_NO_ERROR)
|
|
throw love::Exception("Could not make context current.");
|
|
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.
|
|
// pool must be allocated after AL context.
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -336,26 +313,41 @@ void Audio::setDistanceModel(DistanceModel distanceModel)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-int Audio::getRecordingDeviceCount() const
|
|
|
|
-{
|
|
|
|
- return capture.size();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-love::audio::RecordingDevice *Audio::getRecordingDevice(int index) const
|
|
|
|
|
|
+std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices()
|
|
{
|
|
{
|
|
- if (index < 0 || (unsigned int)index >= capture.size())
|
|
|
|
- return nullptr;
|
|
|
|
-
|
|
|
|
- return capture[index];
|
|
|
|
-}
|
|
|
|
|
|
+ if (capture.size() == 0)
|
|
|
|
+ {
|
|
|
|
+ std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
|
|
|
|
|
|
-int Audio::getRecordingDeviceIndex(love::audio::RecordingDevice *device) const
|
|
|
|
-{
|
|
|
|
- for (unsigned int i = 0; i < capture.size(); i++)
|
|
|
|
- if (device == capture[i])
|
|
|
|
- return i;
|
|
|
|
|
|
+ //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 -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
|
|
} // openal
|