mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
made device enumeration lazy
made enumerator to first attempt aquire default device name by standard means, then to fall back to read name from opened device getRecordingDeviceCount removed for being redundant --HG-- branch : minor-mic-input
This commit is contained in:
@@ -190,20 +190,9 @@ public:
|
|||||||
virtual float getDopplerScale() const = 0;
|
virtual float getDopplerScale() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Number of recording devices.
|
* @return Reference to a vector of pointers to recording devices. May be empty.
|
||||||
**/
|
**/
|
||||||
virtual int getRecordingDeviceCount() const = 0;
|
virtual std::vector<RecordingDevice*> *getRecordingDevices() = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param index Index number of recording device. 0 is default device.
|
|
||||||
* @return Selected recording device.
|
|
||||||
**/
|
|
||||||
virtual RecordingDevice *getRecordingDevice(int index) const = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Index number of a recording device, -1 if not present.
|
|
||||||
**/
|
|
||||||
virtual int getRecordingDeviceIndex(RecordingDevice *device) const = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the distance model used for attenuation.
|
* Gets the distance model used for attenuation.
|
||||||
|
|||||||
@@ -144,19 +144,9 @@ float Audio::getDopplerScale() const
|
|||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Audio::getRecordingDeviceCount() const
|
std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices()
|
||||||
{
|
{
|
||||||
return 0;
|
return &capture;
|
||||||
}
|
|
||||||
|
|
||||||
love::audio::RecordingDevice *Audio::getRecordingDevice(int index) const
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Audio::getRecordingDeviceIndex(love::audio::RecordingDevice *device) const
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::DistanceModel Audio::getDistanceModel() const
|
Audio::DistanceModel Audio::getDistanceModel() const
|
||||||
|
|||||||
@@ -71,9 +71,7 @@ public:
|
|||||||
void setDopplerScale(float scale);
|
void setDopplerScale(float scale);
|
||||||
float getDopplerScale() const;
|
float getDopplerScale() const;
|
||||||
|
|
||||||
int getRecordingDeviceCount() const;
|
std::vector<love::audio::RecordingDevice*> *getRecordingDevices();
|
||||||
love::audio::RecordingDevice *getRecordingDevice(int index) const;
|
|
||||||
int getRecordingDeviceIndex(love::audio::RecordingDevice *device) const;
|
|
||||||
|
|
||||||
DistanceModel getDistanceModel() const;
|
DistanceModel getDistanceModel() const;
|
||||||
void setDistanceModel(DistanceModel distanceModel);
|
void setDistanceModel(DistanceModel distanceModel);
|
||||||
@@ -81,6 +79,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
float volume;
|
float volume;
|
||||||
DistanceModel distanceModel;
|
DistanceModel distanceModel;
|
||||||
|
std::vector<love::audio::RecordingDevice*> capture;
|
||||||
|
|
||||||
}; // Audio
|
}; // Audio
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
std::vector<love::audio::RecordingDevice*> *Audio::getRecordingDevices()
|
||||||
{
|
{
|
||||||
return capture.size();
|
if (capture.size() == 0)
|
||||||
}
|
{
|
||||||
|
std::string defaultname(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
|
||||||
|
|
||||||
love::audio::RecordingDevice *Audio::getRecordingDevice(int index) const
|
//no device name obtained from AL, fallback to reading from device
|
||||||
{
|
if (defaultname.length() == 0)
|
||||||
if (index < 0 || (unsigned int)index >= capture.size())
|
{
|
||||||
return nullptr;
|
//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 capture[index];
|
const ALCchar *devstr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||||
}
|
size_t offset = 0;
|
||||||
|
while (true)
|
||||||
int Audio::getRecordingDeviceIndex(love::audio::RecordingDevice *device) const
|
{
|
||||||
{
|
if (devstr[offset] == '\0')
|
||||||
for (unsigned int i = 0; i < capture.size(); i++)
|
break;
|
||||||
if (device == capture[i])
|
std::string str((ALCchar*)&devstr[offset]);
|
||||||
return i;
|
if (str != defaultname)
|
||||||
|
capture.push_back(new RecordingDevice(str.c_str(), capture.size()));
|
||||||
return -1;
|
offset += str.length() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // openal
|
} // openal
|
||||||
|
|||||||
@@ -105,9 +105,7 @@ public:
|
|||||||
void setDopplerScale(float scale);
|
void setDopplerScale(float scale);
|
||||||
float getDopplerScale() const;
|
float getDopplerScale() const;
|
||||||
|
|
||||||
int getRecordingDeviceCount() const;
|
std::vector<love::audio::RecordingDevice*> *getRecordingDevices();
|
||||||
love::audio::RecordingDevice *getRecordingDevice(int index) const;
|
|
||||||
int getRecordingDeviceIndex(love::audio::RecordingDevice *device) const;
|
|
||||||
|
|
||||||
DistanceModel getDistanceModel() const;
|
DistanceModel getDistanceModel() const;
|
||||||
void setDistanceModel(DistanceModel distanceModel);
|
void setDistanceModel(DistanceModel distanceModel);
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ int RecordingDevice::getID() const
|
|||||||
|
|
||||||
bool RecordingDevice::isRecording() const
|
bool RecordingDevice::isRecording() const
|
||||||
{
|
{
|
||||||
return device == nullptr ? false : true;
|
return device != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //openal
|
} //openal
|
||||||
|
|||||||
@@ -277,21 +277,15 @@ int w_getDistanceModel(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_getRecordingDeviceCount(lua_State *L)
|
|
||||||
{
|
|
||||||
lua_pushnumber(L, instance()->getRecordingDeviceCount());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_getRecordingDevices(lua_State *L)
|
int w_getRecordingDevices(lua_State *L)
|
||||||
{
|
{
|
||||||
int count = instance()->getRecordingDeviceCount();
|
std::vector<RecordingDevice*> *devices = instance()->getRecordingDevices();
|
||||||
lua_createtable(L, count, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
lua_createtable(L, (*devices).size(), 0);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < (*devices).size(); i++)
|
||||||
{
|
{
|
||||||
RecordingDevice *device = instance()->getRecordingDevice(i);
|
luax_pushtype(L, AUDIO_RECORDING_DEVICE_ID, (*devices)[i]);
|
||||||
luax_pushtype(L, AUDIO_RECORDING_DEVICE_ID, device);
|
|
||||||
lua_rawseti(L, -2, i + 1);
|
lua_rawseti(L, -2, i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +313,6 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getDopplerScale", w_getDopplerScale },
|
{ "getDopplerScale", w_getDopplerScale },
|
||||||
{ "setDistanceModel", w_setDistanceModel },
|
{ "setDistanceModel", w_setDistanceModel },
|
||||||
{ "getDistanceModel", w_getDistanceModel },
|
{ "getDistanceModel", w_getDistanceModel },
|
||||||
{ "getRecordingDeviceCount", w_getRecordingDeviceCount },
|
|
||||||
{ "getRecordingDevices", w_getRecordingDevices },
|
{ "getRecordingDevices", w_getRecordingDevices },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user