diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-13 16:39:56 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-13 16:39:56 +1100 |
| commit | b31bc07555fdd862181d8d6ed551163cea89bc62 (patch) | |
| tree | 5991e940d4a3f80675fa493fd11a79450011f5a6 | |
| parent | 3bb002b6b81851e98fa906a02e3aa25381b9d6b9 (diff) | |
| download | tangara-fw-b31bc07555fdd862181d8d6ed551163cea89bc62.tar.gz | |
fix (improve?) libtremor strangeness
something fucky
| -rw-r--r-- | lib/tremor/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/codecs/include/vorbis.hpp | 2 | ||||
| -rw-r--r-- | 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<IStream> input_; - OggVorbis_File vorbis_; + std::unique_ptr<OggVorbis_File> 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<OggVorbis_File*>( + 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<IStream> input) -> cpp::result<OutputFormat, Error> { - 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<IStream> 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<uint32_t> length; if (l > 0) { length = l * info->channels; @@ -133,9 +137,10 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input) auto TremorVorbisDecoder::DecodeTo(cpp::span<sample::Sample> output) -> cpp::result<OutputInfo, Error> { - int bitstream = 0; - long bytes_written = ov_read(&vorbis_, reinterpret_cast<char*>(output.data()), - output.size_bytes(), &bitstream); + int unused = 0; + long bytes_written = + ov_read(vorbis_.get(), reinterpret_cast<char*>(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<sample::Sample> output) } auto TremorVorbisDecoder::SeekTo(size_t target) -> cpp::result<void, Error> { - if (ov_pcm_seek(&vorbis_, target) != 0) { + if (ov_pcm_seek(vorbis_.get(), target) != 0) { return cpp::fail(Error::kInternalError); } return {}; |
