mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
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:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
**/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -82,11 +82,6 @@ const char *RecordingDevice::getName() const
|
||||
return name;
|
||||
}
|
||||
|
||||
int RecordingDevice::getID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RecordingDevice::isRecording() const
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user