diff options
| author | Tom Kirchner <git@halffull.org> | 2025-01-11 21:57:26 -0800 |
|---|---|---|
| committer | Tom Kirchner <git@halffull.org> | 2025-01-11 22:10:26 -0800 |
| commit | 1f1059843fa9ea7e8b6d9c288626dac9e2df67f2 (patch) | |
| tree | 8c783d9afc220870f014f647b7a0a793995bd150 | |
| parent | 430742c29776931a66658735e76f574dbf486330 (diff) | |
| download | tangara-fw-1f1059843fa9ea7e8b6d9c288626dac9e2df67f2.tar.gz | |
Rename VbrInfo to Mp3Info
It can apply to CBR files too, when the marker is "Info"
| -rw-r--r-- | src/codecs/include/mad.hpp | 4 | ||||
| -rw-r--r-- | src/codecs/mad.cpp | 22 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index e28e32c8..274862f7 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -38,13 +38,13 @@ class MadMp3Decoder : public ICodec { private: auto SkipID3Tags(IStream& stream) -> std::optional<uint32_t>; - struct VbrInfo { + struct Mp3Info { uint32_t length; std::optional<uint32_t> bytes; std::optional<std::span<const unsigned char, 100>> toc; }; - auto GetVbrInfo(const mad_header& header) -> std::optional<VbrInfo>; + auto GetMp3Info(const mad_header& header) -> std::optional<Mp3Info>; auto GetBytesUsed() -> std::size_t; diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index d823d99d..2aa3766a 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -107,10 +107,10 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset) .sample_rate_hz = header.samplerate, }; - auto vbr_info = GetVbrInfo(header); + auto mp3_info = GetMp3Info(header); uint64_t cbr_length = 0; - if (vbr_info) { - output.total_samples = vbr_info->length * channels; + if (mp3_info) { + output.total_samples = mp3_info->length * channels; } else if (input->Size() && header.bitrate > 0) { cbr_length = (input->Size().value() * 8) / header.bitrate; output.total_samples = cbr_length * output.sample_rate_hz * channels; @@ -130,22 +130,22 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset) input->SeekTo(skip_bytes, IStream::SeekFrom::kCurrentPosition); // Reset the offset so the next part will seek to the next second offset = 1; - } else if (offset > 1 && vbr_info && vbr_info->toc && vbr_info->bytes) { + } else if (offset > 1 && mp3_info && mp3_info->toc && mp3_info->bytes) { // VBR seeking double percent = - ((offset - 1) * output.sample_rate_hz) / (double)vbr_info->length * 100; + ((offset - 1) * output.sample_rate_hz) / (double)mp3_info->length * 100; percent = std::clamp(percent, 0., 100.); int index = (int)percent; if (index > 99) index = 99; - uint8_t first_val = (*vbr_info->toc)[index]; + uint8_t first_val = (*mp3_info->toc)[index]; uint8_t second_val = 255; if (index < 99) { - second_val = (*vbr_info->toc)[index + 1]; + second_val = (*mp3_info->toc)[index + 1]; } double interp = first_val + (second_val - first_val) * (percent - index); uint32_t bytes_to_skip = - (uint32_t)((1.0 / 255.0) * interp * vbr_info->bytes.value()); + (uint32_t)((1.0 / 255.0) * interp * mp3_info->bytes.value()); input->SeekTo(bytes_to_skip, IStream::SeekFrom::kCurrentPosition); offset = 1; } @@ -304,8 +304,8 @@ auto MadMp3Decoder::SkipID3Tags(IStream& stream) -> std::optional<uint32_t> { * Implementation taken from SDL_mixer and modified. Original is * zlib-licensed, copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org> */ -auto MadMp3Decoder::GetVbrInfo(const mad_header& header) - -> std::optional<VbrInfo> { +auto MadMp3Decoder::GetMp3Info(const mad_header& header) + -> std::optional<Mp3Info> { if (!stream_->this_frame || !stream_->next_frame || stream_->next_frame <= stream_->this_frame || (stream_->next_frame - stream_->this_frame) < 48) { @@ -383,7 +383,7 @@ auto MadMp3Decoder::GetVbrInfo(const mad_header& header) } } - return VbrInfo{ + return Mp3Info{ .length = (frames_count * samples_per_frame), .bytes = bytes, .toc = toc, |
