From b31bc07555fdd862181d8d6ed551163cea89bc62 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 13 Feb 2024 16:39:56 +1100 Subject: [PATCH] fix (improve?) libtremor strangeness something fucky --- lib/tremor/CMakeLists.txt | 2 ++ src/codecs/include/vorbis.hpp | 2 +- src/codecs/vorbis.cpp | 25 +++++++++++++++---------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/tremor/CMakeLists.txt b/lib/tremor/CMakeLists.txt index 296dd4cc..1000fe5f 100644 --- a/lib/tremor/CMakeLists.txt +++ b/lib/tremor/CMakeLists.txt @@ -6,3 +6,5 @@ idf_component_register( res012.c sharedbook.c synthesis.c vorbisfile.c window.c INCLUDE_DIRS "." REQUIRES "ogg") + +target_compile_options("${COMPONENT_LIB}" PRIVATE -Og) diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp index 2f93c37e..673b67a0 100644 --- a/src/codecs/include/vorbis.hpp +++ b/src/codecs/include/vorbis.hpp @@ -41,7 +41,7 @@ class TremorVorbisDecoder : public ICodec { private: std::shared_ptr input_; - OggVorbis_File vorbis_; + std::unique_ptr vorbis_; }; } // namespace codecs diff --git a/src/codecs/vorbis.cpp b/src/codecs/vorbis.cpp index 3b3798cb..c373ebf5 100644 --- a/src/codecs/vorbis.cpp +++ b/src/codecs/vorbis.cpp @@ -78,17 +78,21 @@ static const ov_callbacks kCallbacks{ .tell_func = tell_cb, // Not seekable }; -TremorVorbisDecoder::TremorVorbisDecoder() : input_(), vorbis_() {} +TremorVorbisDecoder::TremorVorbisDecoder() + : input_(), + vorbis_(reinterpret_cast( + heap_caps_malloc(sizeof(OggVorbis_File), + MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT))) {} TremorVorbisDecoder::~TremorVorbisDecoder() { - ov_clear(&vorbis_); + ov_clear(vorbis_.get()); } auto TremorVorbisDecoder::OpenStream(std::shared_ptr input) -> cpp::result { - int res = ov_open_callbacks(input.get(), &vorbis_, NULL, 0, kCallbacks); + int res = ov_open_callbacks(input.get(), vorbis_.get(), NULL, 0, kCallbacks); if (res < 0) { - std::pmr::string err; + std::string err; switch (res) { case OV_EREAD: err = "OV_EREAD"; @@ -112,13 +116,13 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr input) return cpp::fail(Error::kMalformedData); } - vorbis_info* info = ov_info(&vorbis_, -1); + vorbis_info* info = ov_info(vorbis_.get(), -1); if (info == NULL) { ESP_LOGE(kTag, "failed to get stream info"); return cpp::fail(Error::kMalformedData); } - auto l = ov_pcm_total(&vorbis_, -1); + auto l = ov_pcm_total(vorbis_.get(), -1); std::optional length; if (l > 0) { length = l * info->channels; @@ -133,9 +137,10 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr input) auto TremorVorbisDecoder::DecodeTo(cpp::span output) -> cpp::result { - int bitstream = 0; - long bytes_written = ov_read(&vorbis_, reinterpret_cast(output.data()), - output.size_bytes(), &bitstream); + int unused = 0; + long bytes_written = + ov_read(vorbis_.get(), reinterpret_cast(output.data()), + ((output.size() - 1) * sizeof(sample::Sample)), &unused); if (bytes_written == OV_HOLE) { ESP_LOGE(kTag, "got OV_HOLE"); return cpp::fail(Error::kMalformedData); @@ -152,7 +157,7 @@ auto TremorVorbisDecoder::DecodeTo(cpp::span output) } auto TremorVorbisDecoder::SeekTo(size_t target) -> cpp::result { - if (ov_pcm_seek(&vorbis_, target) != 0) { + if (ov_pcm_seek(vorbis_.get(), target) != 0) { return cpp::fail(Error::kInternalError); } return {};