feat(audio): allow sending continuous audio (#4261)
This commit is contained in:
@@ -432,7 +432,11 @@ namespace platf::audio {
|
||||
// Refill the sample buffer if needed
|
||||
while (sample_buf_pos - std::begin(sample_buf) < sample_size) {
|
||||
auto capture_result = _fill_buffer();
|
||||
if (capture_result != capture_e::ok) {
|
||||
if (capture_result == capture_e::timeout && continuous_audio) {
|
||||
// Write silence to sample_buf
|
||||
std::fill_n(sample_buf_pos, sample_size, 0.0f);
|
||||
sample_buf_pos += sample_size;
|
||||
} else if (capture_result != capture_e::ok) {
|
||||
return capture_result;
|
||||
}
|
||||
}
|
||||
@@ -447,7 +451,7 @@ namespace platf::audio {
|
||||
return capture_e::ok;
|
||||
}
|
||||
|
||||
int init(std::uint32_t sample_rate, std::uint32_t frame_size, std::uint32_t channels_out) {
|
||||
int init(std::uint32_t sample_rate, std::uint32_t frame_size, std::uint32_t channels_out, bool continuous) {
|
||||
audio_event.reset(CreateEventA(nullptr, FALSE, FALSE, nullptr));
|
||||
if (!audio_event) {
|
||||
BOOST_LOG(error) << "Couldn't create Event handle"sv;
|
||||
@@ -508,6 +512,7 @@ namespace platf::audio {
|
||||
REFERENCE_TIME default_latency;
|
||||
audio_client->GetDevicePeriod(&default_latency, nullptr);
|
||||
default_latency_ms = default_latency / 1000;
|
||||
continuous_audio = continuous;
|
||||
|
||||
std::uint32_t frames;
|
||||
status = audio_client->GetBufferSize(&frames);
|
||||
@@ -678,6 +683,7 @@ namespace platf::audio {
|
||||
util::buffer_t<float> sample_buf;
|
||||
float *sample_buf_pos;
|
||||
int channels;
|
||||
bool continuous_audio;
|
||||
|
||||
HANDLE mmcss_task_handle = nullptr;
|
||||
};
|
||||
@@ -761,10 +767,10 @@ namespace platf::audio {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::unique_ptr<mic_t> microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size) override {
|
||||
std::unique_ptr<mic_t> microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous_audio) override {
|
||||
auto mic = std::make_unique<mic_wasapi_t>();
|
||||
|
||||
if (mic->init(sample_rate, frame_size, channels)) {
|
||||
if (mic->init(sample_rate, frame_size, channels, continuous_audio)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user