add audio.get_input_devices_names()
This commit is contained in:
parent
6b9a408e6d
commit
b11bdf0bcc
@ -479,6 +479,27 @@ std::unique_ptr<Stream> ALAudio::openStream(
|
|||||||
return std::make_unique<ALStream>(this, stream, keepSource);
|
return std::make_unique<ALStream>(this, stream, keepSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ALAudio::getInputDeviceNames() {
|
||||||
|
std::vector<std::string> devices;
|
||||||
|
|
||||||
|
if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT")) {
|
||||||
|
auto deviceList = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||||
|
if (deviceList == nullptr) {
|
||||||
|
logger.warning() << "no input devices found";
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
while (*deviceList) {
|
||||||
|
std::string deviceName(deviceList);
|
||||||
|
devices.push_back(deviceName);
|
||||||
|
deviceList += deviceName.length() + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warning() << "enumeration extension is not available";
|
||||||
|
}
|
||||||
|
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<InputDevice> ALAudio::openInputDevice(
|
std::unique_ptr<InputDevice> ALAudio::openInputDevice(
|
||||||
uint sampleRate, uint channels, uint bitsPerSample
|
uint sampleRate, uint channels, uint bitsPerSample
|
||||||
) {
|
) {
|
||||||
@ -490,6 +511,7 @@ std::unique_ptr<InputDevice> ALAudio::openInputDevice(
|
|||||||
sampleRate * channels * bps / 8
|
sampleRate * channels * bps / 8
|
||||||
);
|
);
|
||||||
check_alc_errors(device, "alcCaptureOpenDevice");
|
check_alc_errors(device, "alcCaptureOpenDevice");
|
||||||
|
|
||||||
return std::make_unique<ALInputDevice>(
|
return std::make_unique<ALInputDevice>(
|
||||||
this, device, channels, bitsPerSample
|
this, device, channels, bitsPerSample
|
||||||
);
|
);
|
||||||
|
|||||||
@ -186,6 +186,8 @@ namespace audio {
|
|||||||
uint sampleRate, uint channels, uint bitsPerSample
|
uint sampleRate, uint channels, uint bitsPerSample
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
|
std::vector<std::string> getInputDeviceNames() override;
|
||||||
|
|
||||||
void setListener(
|
void setListener(
|
||||||
glm::vec3 position,
|
glm::vec3 position,
|
||||||
glm::vec3 velocity,
|
glm::vec3 velocity,
|
||||||
|
|||||||
@ -82,6 +82,10 @@ namespace audio {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> getInputDeviceNames() override {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void setListener(
|
void setListener(
|
||||||
glm::vec3 position, glm::vec3 velocity, glm::vec3 at, glm::vec3 up
|
glm::vec3 position, glm::vec3 velocity, glm::vec3 at, glm::vec3 up
|
||||||
) override {
|
) override {
|
||||||
|
|||||||
@ -253,6 +253,16 @@ std::unique_ptr<Stream> audio::open_stream(
|
|||||||
return backend->openStream(std::move(stream), keepSource);
|
return backend->openStream(std::move(stream), keepSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<InputDevice> audio::open_input_device(
|
||||||
|
uint sampleRate, uint channels, uint bitsPerSample
|
||||||
|
) {
|
||||||
|
return backend->openInputDevice(sampleRate, channels, bitsPerSample);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> audio::get_input_devices_names() {
|
||||||
|
return backend->getInputDeviceNames();
|
||||||
|
}
|
||||||
|
|
||||||
void audio::set_listener(
|
void audio::set_listener(
|
||||||
glm::vec3 position, glm::vec3 velocity, glm::vec3 lookAt, glm::vec3 up
|
glm::vec3 position, glm::vec3 velocity, glm::vec3 lookAt, glm::vec3 up
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -370,6 +370,7 @@ namespace audio {
|
|||||||
glm::vec3 lookAt,
|
glm::vec3 lookAt,
|
||||||
glm::vec3 up
|
glm::vec3 up
|
||||||
) = 0;
|
) = 0;
|
||||||
|
virtual std::vector<std::string> getInputDeviceNames() = 0;
|
||||||
virtual void update(double delta) = 0;
|
virtual void update(double delta) = 0;
|
||||||
|
|
||||||
/// @brief Check if backend is an abstraction that does not internally
|
/// @brief Check if backend is an abstraction that does not internally
|
||||||
@ -434,6 +435,10 @@ namespace audio {
|
|||||||
uint sampleRate, uint channels, uint bitsPerSample
|
uint sampleRate, uint channels, uint bitsPerSample
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// @brief Retrieve names of available audio input devices
|
||||||
|
/// @return list of device names
|
||||||
|
std::vector<std::string> get_input_devices_names();
|
||||||
|
|
||||||
/// @brief Configure 3D listener
|
/// @brief Configure 3D listener
|
||||||
/// @param position listener position
|
/// @param position listener position
|
||||||
/// @param velocity listener velocity (used for Doppler effect)
|
/// @param velocity listener velocity (used for Doppler effect)
|
||||||
|
|||||||
@ -408,6 +408,17 @@ static int l_audio_fetch_input(lua::State* L) {
|
|||||||
return lua::create_bytearray(L, std::move(bytes));
|
return lua::create_bytearray(L, std::move(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_audio_get_input_devices_names(lua::State* L) {
|
||||||
|
auto device_names = audio::get_input_devices_names();
|
||||||
|
lua::createtable(L, device_names.size(), 0);
|
||||||
|
int index = 1;
|
||||||
|
for (const auto& name : device_names) {
|
||||||
|
lua::pushstring(L, name.c_str());
|
||||||
|
lua::rawseti(L, index++);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg audiolib[] = {
|
const luaL_Reg audiolib[] = {
|
||||||
{"play_sound", lua::wrap<l_audio_play_sound>},
|
{"play_sound", lua::wrap<l_audio_play_sound>},
|
||||||
{"play_sound_2d", lua::wrap<l_audio_play_sound_2d>},
|
{"play_sound_2d", lua::wrap<l_audio_play_sound_2d>},
|
||||||
@ -434,5 +445,6 @@ const luaL_Reg audiolib[] = {
|
|||||||
{"count_speakers", lua::wrap<l_audio_count_speakers>},
|
{"count_speakers", lua::wrap<l_audio_count_speakers>},
|
||||||
{"count_streams", lua::wrap<l_audio_count_streams>},
|
{"count_streams", lua::wrap<l_audio_count_streams>},
|
||||||
{"fetch_input", lua::wrap<l_audio_fetch_input>},
|
{"fetch_input", lua::wrap<l_audio_fetch_input>},
|
||||||
|
{"get_input_devices_names", lua::wrap<l_audio_get_input_devices_names>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user