diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-02-16 17:02:54 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-02-16 17:02:54 +1100 |
| commit | 19f60e33c4ba7eda86c709a8d73ca5e8ab100952 (patch) | |
| tree | 3181edfa09dc38c5cd52a07bcd3f64dfe05a4439 /src/codecs | |
| parent | 0baad11b188e7bac6b968017716186d9da0e492f (diff) | |
| parent | 4509ab8d6e341f7f7d92ac6e9d63ad822fe3441b (diff) | |
| download | tangara-fw-19f60e33c4ba7eda86c709a8d73ca5e8ab100952.tar.gz | |
Merge branch 'main' into seek-support
Diffstat (limited to 'src/codecs')
| -rw-r--r-- | src/codecs/include/vorbis.hpp | 4 | ||||
| -rw-r--r-- | src/codecs/miniflac.cpp | 11 | ||||
| -rw-r--r-- | src/codecs/vorbis.cpp | 46 |
3 files changed, 30 insertions, 31 deletions
diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp index b32ef8d5..94868c1a 100644 --- a/src/codecs/include/vorbis.hpp +++ b/src/codecs/include/vorbis.hpp @@ -14,8 +14,6 @@ #include <utility> #include "ivorbisfile.h" -#include "ogg/ogg.h" -#include "opus.h" #include "sample.hpp" #include "span.hpp" @@ -41,7 +39,7 @@ class TremorVorbisDecoder : public ICodec { private: std::shared_ptr<IStream> input_; - OggVorbis_File vorbis_; + std::unique_ptr<TremorOggVorbis_File> vorbis_; }; } // namespace codecs diff --git a/src/codecs/miniflac.cpp b/src/codecs/miniflac.cpp index d15410fe..d0b40f96 100644 --- a/src/codecs/miniflac.cpp +++ b/src/codecs/miniflac.cpp @@ -30,9 +30,16 @@ MiniFlacDecoder::MiniFlacDecoder() current_sample_() { miniflac_init(flac_.get(), MINIFLAC_CONTAINER_UNKNOWN); for (int i = 0; i < samples_by_channel_.size(); i++) { - // Full decoded frames too big to fit in internal ram :( + uint32_t caps; + if (i == 0) { + caps = MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL; + } else { + // FIXME: We can *almost* fit two channels into internal ram, but we're a + // few KiB shy of being able to do it safely. + caps = MALLOC_CAP_SPIRAM; + } samples_by_channel_[i] = reinterpret_cast<int32_t*>( - heap_caps_malloc(kMaxFrameSize * sizeof(int32_t), MALLOC_CAP_SPIRAM)); + heap_caps_malloc(kMaxFrameSize * sizeof(int32_t), caps)); } } diff --git a/src/codecs/vorbis.cpp b/src/codecs/vorbis.cpp index 65783dac..e51c6bca 100644 --- a/src/codecs/vorbis.cpp +++ b/src/codecs/vorbis.cpp @@ -4,31 +4,20 @@ * SPDX-License-Identifier: GPL-3.0-only */ -#include "ivorbiscodec.h" -#include "ivorbisfile.h" -#include "ogg/config_types.h" -#include "opus.hpp" - -#include <stdint.h> -#include <sys/_stdint.h> +#include "vorbis.hpp" #include <cstdint> #include <cstring> #include <optional> #include "esp_heap_caps.h" -#include "mad.h" +#include "esp_log.h" +#include "ivorbiscodec.h" +#include "ivorbisfile.h" #include "codec.hpp" -#include "esp_log.h" -#include "ogg/ogg.h" -#include "opus.h" -#include "opus_defines.h" -#include "opus_types.h" -#include "result.hpp" #include "sample.hpp" #include "types.hpp" -#include "vorbis.hpp" namespace codecs { @@ -39,7 +28,7 @@ static size_t read_cb(void* ptr, size_t size, size_t nmemb, void* instance) { return source->Read({reinterpret_cast<std::byte*>(ptr), size * nmemb}); } -static int seek_cb(void* instance, ogg_int64_t offset, int whence) { +static int seek_cb(void* instance, tremor_ogg_int64_t offset, int whence) { IStream* source = reinterpret_cast<IStream*>(instance); if (!source->CanSeek()) { return -1; @@ -78,17 +67,21 @@ static const ov_callbacks kCallbacks{ .tell_func = tell_cb, // Not seekable }; -TremorVorbisDecoder::TremorVorbisDecoder() : input_(), vorbis_() {} +TremorVorbisDecoder::TremorVorbisDecoder() + : input_(), + vorbis_(reinterpret_cast<TremorOggVorbis_File*>( + heap_caps_malloc(sizeof(TremorOggVorbis_File), + MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT))) {} TremorVorbisDecoder::~TremorVorbisDecoder() { - ov_clear(&vorbis_); + ov_clear(vorbis_.get()); } auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset) -> 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 +105,13 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t off 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; @@ -137,9 +130,10 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t off 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); @@ -156,7 +150,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 {}; |
