From 958160aa545e3d91b2a4f1a367817e73d298e8a9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 10 Aug 2023 19:12:38 +1000 Subject: Use the libspeexdsp resampler AFAICT it runs a little slower? but it's fixed point, and has much better understood audio characteristics. --- src/codecs/vorbis.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/codecs/vorbis.cpp') diff --git a/src/codecs/vorbis.cpp b/src/codecs/vorbis.cpp index 6fa3256a..aa367e02 100644 --- a/src/codecs/vorbis.cpp +++ b/src/codecs/vorbis.cpp @@ -126,14 +126,9 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr input) auto TremorVorbisDecoder::DecodeTo(cpp::span output) -> cpp::result { - cpp::span staging_buffer{ - reinterpret_cast(output.subspan(output.size() / 2).data()), - output.size_bytes() / 2}; - - int bitstream; - long bytes_written = - ov_read(&vorbis_, reinterpret_cast(staging_buffer.data()), - staging_buffer.size_bytes(), &bitstream); + int bitstream = 0; + long bytes_written = ov_read(&vorbis_, reinterpret_cast(output.data()), + output.size_bytes(), &bitstream); if (bytes_written == OV_HOLE) { ESP_LOGE(kTag, "got OV_HOLE"); return cpp::fail(Error::kMalformedData); @@ -142,12 +137,9 @@ auto TremorVorbisDecoder::DecodeTo(cpp::span output) return cpp::fail(Error::kMalformedData); } - for (int i = 0; i < bytes_written / 2; i++) { - output[i] = sample::FromSigned(staging_buffer[i], 16); - } - return OutputInfo{ - .samples_written = static_cast(bytes_written / 2), + .samples_written = + static_cast(bytes_written / sizeof(sample::Sample)), .is_stream_finished = bytes_written == 0, }; } -- cgit v1.2.3