Browse Source

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
Raidho 8 years ago
parent
commit
57d02dec2b

+ 1 - 1
src/modules/audio/Audio.h

@@ -192,7 +192,7 @@ public:
 	/**
 	 * @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.

+ 0 - 5
src/modules/audio/RecordingDevice.h

@@ -69,11 +69,6 @@ public:
 	 **/ 
 	virtual const char *getName() const = 0;
 
-	/**
-	 * @return Unique ID number.
-	 **/ 
-	virtual int getID() const = 0;
-
 	/**
 	 * @return Number of samples currently recorded.
 	 **/

+ 2 - 2
src/modules/audio/null/Audio.cpp

@@ -144,9 +144,9 @@ float Audio::getDopplerScale() const
 	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

+ 1 - 1
src/modules/audio/null/Audio.h

@@ -71,7 +71,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);

+ 0 - 5
src/modules/audio/null/RecordingDevice.cpp

@@ -82,11 +82,6 @@ const char *RecordingDevice::getName() const
 	return name;
 }
 
-int RecordingDevice::getID() const
-{
-	return 0;
-}
-
 bool RecordingDevice::isRecording() const
 {
 	return false;

+ 0 - 1
src/modules/audio/null/RecordingDevice.h

@@ -41,7 +41,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;

+ 29 - 29
src/modules/audio/openal/Audio.cpp

@@ -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)
-	{
-		std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
+	capture.clear();
 
-		//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));
+	std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
 
-		const ALCchar *devstr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
-		size_t offset = 0;
-		while (true)
+	//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)
 		{
-			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
src/modules/audio/openal/Audio.h

@@ -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);

+ 0 - 5
src/modules/audio/openal/RecordingDevice.cpp

@@ -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;

+ 0 - 1
src/modules/audio/openal/RecordingDevice.h

@@ -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;

+ 4 - 4
src/modules/audio/wrap_Audio.cpp

@@ -279,13 +279,13 @@ int w_getDistanceModel(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);
 	}
 

+ 0 - 8
src/modules/audio/wrap_RecordingDevice.cpp

@@ -128,13 +128,6 @@ int w_RecordingDevice_getName(lua_State *L)
 	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)
 {
 	RecordingDevice *d = luax_checkrecordingdevice(L, 1);
@@ -152,7 +145,6 @@ static const luaL_Reg w_RecordingDevice_functions[] =
 	{ "getBitDepth", w_RecordingDevice_getBitDepth },
 	{ "getChannels", w_RecordingDevice_getChannels },
 	{ "getName", w_RecordingDevice_getName },
-	{ "getID", w_RecordingDevice_getID },
 	{ "isRecording", w_RecordingDevice_isRecording },
 	{ 0, 0 }
 };