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
+1 -1
View File
@@ -192,7 +192,7 @@ public:
/** /**
* @return Reference to a vector of pointers to recording devices. May be empty. * @return Reference to a vector of pointers to recording devices. May be empty.
**/ **/
virtual std::vector<RecordingDevice*> *getRecordingDevices() = 0; virtual const std::vector<RecordingDevice*> &getRecordingDevices() = 0;
/** /**
* Gets the distance model used for attenuation. * Gets the distance model used for attenuation.
-5
View File
@@ -69,11 +69,6 @@ public:
**/ **/
virtual const char *getName() const = 0; virtual const char *getName() const = 0;
/**
* @return Unique ID number.
**/
virtual int getID() const = 0;
/** /**
* @return Number of samples currently recorded. * @return Number of samples currently recorded.
**/ **/
+2 -2
View File
@@ -144,9 +144,9 @@ float Audio::getDopplerScale() const
return 1.0f; return 1.0f;
} }
std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices() const std::vector<love::audio::RecordingDevice*> &Audio::getRecordingDevices()
{ {
return &capture; return capture;
} }
Audio::DistanceModel Audio::getDistanceModel() const Audio::DistanceModel Audio::getDistanceModel() const
+1 -1
View File
@@ -71,7 +71,7 @@ public:
void setDopplerScale(float scale); void setDopplerScale(float scale);
float getDopplerScale() const; float getDopplerScale() const;
std::vector<love::audio::RecordingDevice*> *getRecordingDevices(); const std::vector<love::audio::RecordingDevice*> &getRecordingDevices();
DistanceModel getDistanceModel() const; DistanceModel getDistanceModel() const;
void setDistanceModel(DistanceModel distanceModel); void setDistanceModel(DistanceModel distanceModel);
@@ -82,11 +82,6 @@ const char *RecordingDevice::getName() const
return name; return name;
} }
int RecordingDevice::getID() const
{
return 0;
}
bool RecordingDevice::isRecording() const bool RecordingDevice::isRecording() const
{ {
return false; return false;
-1
View File
@@ -41,7 +41,6 @@ public:
virtual void stopRecording(); virtual void stopRecording();
virtual love::sound::SoundData *getData(); virtual love::sound::SoundData *getData();
virtual const char *getName() const; virtual const char *getName() const;
virtual int getID() const;
virtual int getSampleCount() const; virtual int getSampleCount() const;
virtual int getSampleRate() const; virtual int getSampleRate() const;
virtual int getBitDepth() const; virtual int getBitDepth() const;
+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)); //use some safe basic parameters - 8 kHz, 8 bits, 1 channel
ALCdevice *defaultdevice = alcCaptureOpenDevice(NULL, 8000, 8, 1);
//no device name obtained from AL, fallback to reading from device if (alGetError() == AL_NO_ERROR)
if (defaultname.length() == 0)
{ {
//use some safe basic parameters - 8 kHz, 8 bits, 1 channel defaultname = alcGetString(defaultdevice, ALC_CAPTURE_DEVICE_SPECIFIER);
ALCdevice *defaultdevice = alcCaptureOpenDevice(NULL, 8000, 8, 1); alcCaptureCloseDevice(defaultdevice);
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;
} }
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 } // openal
+1 -1
View File
@@ -105,7 +105,7 @@ public:
void setDopplerScale(float scale); void setDopplerScale(float scale);
float getDopplerScale() const; float getDopplerScale() const;
std::vector<love::audio::RecordingDevice*> *getRecordingDevices(); const std::vector<love::audio::RecordingDevice*> &getRecordingDevices();
DistanceModel getDistanceModel() const; DistanceModel getDistanceModel() const;
void setDistanceModel(DistanceModel distanceModel); void setDistanceModel(DistanceModel distanceModel);
@@ -148,11 +148,6 @@ const char *RecordingDevice::getName() const
return name.c_str(); return name.c_str();
} }
int RecordingDevice::getID() const
{
return id;
}
bool RecordingDevice::isRecording() const bool RecordingDevice::isRecording() const
{ {
return device != nullptr; return device != nullptr;
@@ -54,7 +54,6 @@ public:
virtual void stopRecording(); virtual void stopRecording();
virtual love::sound::SoundData *getData(); virtual love::sound::SoundData *getData();
virtual const char *getName() const; virtual const char *getName() const;
virtual int getID() const;
virtual int getSampleCount() const; virtual int getSampleCount() const;
virtual int getSampleRate() const; virtual int getSampleRate() const;
virtual int getBitDepth() const; virtual int getBitDepth() const;
+4 -4
View File
@@ -279,13 +279,13 @@ int w_getDistanceModel(lua_State *L)
int w_getRecordingDevices(lua_State *L) int w_getRecordingDevices(lua_State *L)
{ {
std::vector<RecordingDevice*> *devices = instance()->getRecordingDevices(); const std::vector<RecordingDevice*> &devices = instance()->getRecordingDevices();
lua_createtable(L, (*devices).size(), 0); lua_createtable(L, devices.size(), 0);
for (unsigned int i = 0; i < (*devices).size(); i++) for (unsigned int i = 0; i < devices.size(); i++)
{ {
luax_pushtype(L, AUDIO_RECORDING_DEVICE_ID, (*devices)[i]); luax_pushtype(L, AUDIO_RECORDING_DEVICE_ID, devices[i]);
lua_rawseti(L, -2, i + 1); lua_rawseti(L, -2, i + 1);
} }
@@ -128,13 +128,6 @@ int w_RecordingDevice_getName(lua_State *L)
return 1; return 1;
} }
int w_RecordingDevice_getID(lua_State *L)
{
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
lua_pushnumber(L, d->getID());
return 1;
}
int w_RecordingDevice_isRecording(lua_State *L) int w_RecordingDevice_isRecording(lua_State *L)
{ {
RecordingDevice *d = luax_checkrecordingdevice(L, 1); RecordingDevice *d = luax_checkrecordingdevice(L, 1);
@@ -152,7 +145,6 @@ static const luaL_Reg w_RecordingDevice_functions[] =
{ "getBitDepth", w_RecordingDevice_getBitDepth }, { "getBitDepth", w_RecordingDevice_getBitDepth },
{ "getChannels", w_RecordingDevice_getChannels }, { "getChannels", w_RecordingDevice_getChannels },
{ "getName", w_RecordingDevice_getName }, { "getName", w_RecordingDevice_getName },
{ "getID", w_RecordingDevice_getID },
{ "isRecording", w_RecordingDevice_isRecording }, { "isRecording", w_RecordingDevice_isRecording },
{ 0, 0 } { 0, 0 }
}; };