add audio.get_input_info()
This commit is contained in:
parent
001c1b430b
commit
6c558eb3d5
@ -68,9 +68,17 @@ std::unique_ptr<Speaker> ALSound::newInstance(int priority, int channel) const {
|
||||
}
|
||||
|
||||
ALInputDevice::ALInputDevice(
|
||||
ALAudio* al, ALCdevice* device, uint channels, uint bitsPerSample
|
||||
ALAudio* al,
|
||||
ALCdevice* device,
|
||||
uint channels,
|
||||
uint bitsPerSample,
|
||||
uint sampleRate
|
||||
)
|
||||
: al(al), device(device), channels(channels), bitsPerSample(bitsPerSample) {
|
||||
: al(al),
|
||||
device(device),
|
||||
channels(channels),
|
||||
bitsPerSample(bitsPerSample),
|
||||
sampleRate(sampleRate) {
|
||||
}
|
||||
|
||||
ALInputDevice::~ALInputDevice() {
|
||||
@ -92,6 +100,14 @@ uint ALInputDevice::getChannels() const {
|
||||
return channels;
|
||||
}
|
||||
|
||||
uint ALInputDevice::getSampleRate() const {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
uint ALInputDevice::getBitsPerSample() const {
|
||||
return bitsPerSample;
|
||||
}
|
||||
|
||||
size_t ALInputDevice::read(char* buffer, size_t bufferSize) {
|
||||
ALCint samplesCount = 0;
|
||||
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, sizeof(samplesCount), &samplesCount);
|
||||
@ -546,7 +562,7 @@ std::unique_ptr<InputDevice> ALAudio::openInputDevice(
|
||||
return nullptr;
|
||||
|
||||
return std::make_unique<ALInputDevice>(
|
||||
this, device, channels, bitsPerSample
|
||||
this, device, channels, bitsPerSample, sampleRate
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,11 @@ namespace audio {
|
||||
class ALInputDevice : public InputDevice {
|
||||
public:
|
||||
ALInputDevice(
|
||||
ALAudio* al, ALCdevice* device, uint channels, uint bitsPerSample
|
||||
ALAudio* al,
|
||||
ALCdevice* device,
|
||||
uint channels,
|
||||
uint bitsPerSample,
|
||||
uint sampleRate
|
||||
);
|
||||
~ALInputDevice() override;
|
||||
|
||||
@ -93,6 +97,8 @@ namespace audio {
|
||||
void stopCapture() override;
|
||||
|
||||
uint getChannels() const override;
|
||||
uint getSampleRate() const override;
|
||||
uint getBitsPerSample() const override;
|
||||
|
||||
size_t read(char* buffer, size_t bufferSize) override;
|
||||
private:
|
||||
@ -100,6 +106,7 @@ namespace audio {
|
||||
ALCdevice* device;
|
||||
uint channels;
|
||||
uint bitsPerSample;
|
||||
uint sampleRate;
|
||||
};
|
||||
|
||||
/// @brief AL source adapter
|
||||
|
||||
@ -120,6 +120,12 @@ namespace audio {
|
||||
/// @brief Get number of audio channels
|
||||
/// @return 1 if mono, 2 if stereo
|
||||
virtual uint getChannels() const = 0;
|
||||
/// @brief Get audio sampling frequency
|
||||
/// @return number of mono samples per second
|
||||
virtual uint getSampleRate() const = 0;
|
||||
/// @brief Get number of bits per mono sample
|
||||
/// @return 8 or 16
|
||||
virtual uint getBitsPerSample() const = 0;
|
||||
|
||||
virtual size_t read(char* buffer, size_t bufferSize) = 0;
|
||||
};
|
||||
|
||||
@ -442,6 +442,21 @@ static int l_audio_set_output_device(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_audio_get_input_info(lua::State* L) {
|
||||
auto device = audio::get_input_device();
|
||||
if (device == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
lua::createtable(L, 0, 3);
|
||||
lua::pushinteger(L, device->getChannels());
|
||||
lua::setfield(L, "channels");
|
||||
lua::pushinteger(L, device->getSampleRate());
|
||||
lua::setfield(L, "sample_rate");
|
||||
lua::pushinteger(L, device->getBitsPerSample());
|
||||
lua::setfield(L, "bits_per_sample");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg audiolib[] = {
|
||||
{"play_sound", lua::wrap<l_audio_play_sound>},
|
||||
{"play_sound_2d", lua::wrap<l_audio_play_sound_2d>},
|
||||
@ -472,5 +487,6 @@ const luaL_Reg audiolib[] = {
|
||||
{"get_output_devices_names", lua::wrap<l_audio_get_output_devices_names>},
|
||||
{"set_input_device", lua::wrap<l_audio_set_input_device>},
|
||||
{"set_output_device", lua::wrap<l_audio_set_output_device>},
|
||||
{"get_input_info", lua::wrap<l_audio_get_input_info>},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user