Skip to content

Commit

Permalink
fixup! Migrate audio pipeline to float from 16-bit int
Browse files Browse the repository at this point in the history
  • Loading branch information
ns6089 committed Jul 16, 2024
1 parent c4ad1af commit 9945e02
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/platform/linux/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace platf {
to_string(const char *name, const std::uint8_t *mapping, int channels) {
std::stringstream ss;

ss << "rate=48000 sink_name="sv << name << " format=s16le channels="sv << channels << " channel_map="sv;
ss << "rate=48000 sink_name="sv << name << " format=float channels="sv << channels << " channel_map="sv;
std::for_each_n(mapping, channels - 1, [&ss](std::uint8_t pos) {
ss << pa_channel_position_to_string(position_mapping[pos]) << ',';
});
Expand All @@ -54,12 +54,12 @@ namespace platf {
util::safe_ptr<pa_simple, pa_simple_free> mic;

capture_e
sample(std::vector<std::int16_t> &sample_buf) override {
sample(std::vector<float> &sample_buf) override {
auto sample_size = sample_buf.size();

auto buf = sample_buf.data();
int status;
if (pa_simple_read(mic.get(), buf, sample_size * 2, &status)) {
if (pa_simple_read(mic.get(), buf, sample_size * sizeof(float), &status)) {
BOOST_LOG(error) << "pa_simple_read() failed: "sv << pa_strerror(status);

return capture_e::error;
Expand All @@ -73,7 +73,7 @@ namespace platf {
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, std::string source_name) {
auto mic = std::make_unique<mic_attr_t>();

pa_sample_spec ss { PA_SAMPLE_S16LE, sample_rate, (std::uint8_t) channels };
pa_sample_spec ss { PA_SAMPLE_FLOAT32, sample_rate, (std::uint8_t) channels };
pa_channel_map pa_map;

pa_map.channels = channels;
Expand All @@ -82,7 +82,10 @@ namespace platf {
});

pa_buffer_attr pa_attr = {};
pa_attr.maxlength = frame_size * 8;

// Unsure about this one, but previous value of "frame_size * 8" made
// no sense even for 16-bit capture.
pa_attr.maxlength = frame_size * channels * sizeof(float);

int status;

Expand Down

0 comments on commit 9945e02

Please sign in to comment.