diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-08-07 18:22:15 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-08-07 18:22:15 +1000 |
| commit | c38754401b95642b5e61fd273c2adf7d76a829fe (patch) | |
| tree | 2dc23008f6b2b471ce54fbc61d96b7b8c508b0dd /src/audio/sink_mixer.cpp | |
| parent | a66c3428063017f2233b6b15d5ce6c920d5c9095 (diff) | |
| download | tangara-fw-c38754401b95642b5e61fd273c2adf7d76a829fe.tar.gz | |
Downscaling working!
Diffstat (limited to 'src/audio/sink_mixer.cpp')
| -rw-r--r-- | src/audio/sink_mixer.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/audio/sink_mixer.cpp b/src/audio/sink_mixer.cpp index 176fb4a3..a2bf229b 100644 --- a/src/audio/sink_mixer.cpp +++ b/src/audio/sink_mixer.cpp @@ -137,7 +137,7 @@ auto SinkMixer::HandleBytes() -> void { return; } - while (!input_stream_->empty()) { + while (input_stream_->info().bytes_in_stream() >= sizeof(sample::Sample)) { RawStream* output_source; if (pcm->sample_rate != target_format_.sample_rate) { OutputStream resampled_writer{resampled_stream_.get()}; @@ -150,6 +150,9 @@ auto SinkMixer::HandleBytes() -> void { output_source = input_stream_.get(); } + size_t bytes_consumed = output_source->info().bytes_in_stream(); + size_t bytes_to_send = output_source->info().bytes_in_stream(); + if (target_format_.bits_per_sample == 16) { // This is slightly scary; we're basically reaching into the internals of // the stream buffer to do in-place conversion of samples. Saving an @@ -163,19 +166,20 @@ auto SinkMixer::HandleBytes() -> void { ApplyDither(src, 16); Downscale(src, dest); - output_source->info().bytes_in_stream() = dest.size_bytes(); + bytes_consumed = src.size_bytes(); + bytes_to_send = src.size_bytes() / 2; } InputStream output{output_source}; cpp::span<const std::byte> buf = output.data(); size_t bytes_sent = 0; - while (bytes_sent < buf.size_bytes()) { - auto cropped = buf.subspan(bytes_sent); + while (bytes_sent < bytes_to_send) { + auto cropped = buf.subspan(bytes_sent, bytes_to_send - bytes_sent); bytes_sent += xStreamBufferSend(sink_, cropped.data(), cropped.size_bytes(), portMAX_DELAY); } - output.consume(bytes_sent); + output.consume(bytes_consumed); } } |
