Addressed some criticism

getRecordingDevices internal function is now returns constant reference,
also re-enumerates devices every time it is called; this is a slow operation
getID removed for not being useful

--HG--
branch : minor-mic-input
This commit is contained in:
Raidho
2016-11-03 06:31:31 +03:00
parent a99c757652
commit 57d02dec2b
12 changed files with 39 additions and 64 deletions
+30 -30
View File
@@ -313,41 +313,41 @@ void Audio::setDistanceModel(DistanceModel distanceModel)
}
}
std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices()
const std::vector<love::audio::RecordingDevice*> &Audio::getRecordingDevices()
{
if (capture.size() == 0)
capture.clear();
std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
//no device name obtained from AL, fallback to reading from device
if (defaultname.length() == 0)
{
std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
//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)
{
//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));
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;
defaultname = alcGetString(defaultdevice, ALC_CAPTURE_DEVICE_SPECIFIER);
alcCaptureCloseDevice(defaultdevice);
}
else
//failed to open default recording device - bail, return empty list
return capture;
}
return &capture;
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;
}
return capture;
}
} // openal
+1 -1
View File
@@ -105,7 +105,7 @@ public:
void setDopplerScale(float scale);
float getDopplerScale() const;
std::vector<love::audio::RecordingDevice*> *getRecordingDevices();
const std::vector<love::audio::RecordingDevice*> &getRecordingDevices();
DistanceModel getDistanceModel() const;
void setDistanceModel(DistanceModel distanceModel);
@@ -148,11 +148,6 @@ const char *RecordingDevice::getName() const
return name.c_str();
}
int RecordingDevice::getID() const
{
return id;
}
bool RecordingDevice::isRecording() const
{
return device != nullptr;
@@ -54,7 +54,6 @@ public:
virtual void stopRecording();
virtual love::sound::SoundData *getData();
virtual const char *getName() const;
virtual int getID() const;
virtual int getSampleCount() const;
virtual int getSampleRate() const;
virtual int getBitDepth() const;