summaryrefslogtreecommitdiff
path: root/src/codecs
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-07-07 15:29:47 +1000
committerjacqueline <me@jacqueline.id.au>2023-07-07 15:29:47 +1000
commit39f7545cd5ef7a30bbd482f3579df7744c6b688d (patch)
treea760a50cc17365fbcd69eb89ca627ad7feb8c0b6 /src/codecs
parent2f16d230025c3173cfbecc58b38d6a52b6b0f5f2 (diff)
downloadtangara-fw-39f7545cd5ef7a30bbd482f3579df7744c6b688d.tar.gz
wire up the playing screen with some real data
Includes implementing song duration calculation for CBR MP3 files
Diffstat (limited to 'src/codecs')
-rw-r--r--src/codecs/foxenflac.cpp1
-rw-r--r--src/codecs/include/codec.hpp4
-rw-r--r--src/codecs/mad.cpp20
3 files changed, 19 insertions, 6 deletions
diff --git a/src/codecs/foxenflac.cpp b/src/codecs/foxenflac.cpp
index a2d6f000..ee21da65 100644
--- a/src/codecs/foxenflac.cpp
+++ b/src/codecs/foxenflac.cpp
@@ -43,6 +43,7 @@ auto FoxenFlacDecoder::BeginStream(const cpp::span<const std::byte> input)
.num_channels = static_cast<uint8_t>(channels),
.bits_per_sample = 32, // libfoxenflac output is fixed-size.
.sample_rate_hz = static_cast<uint32_t>(fs),
+ .duration_seconds = {},
}};
}
diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp
index 4b5ab47f..299b16e4 100644
--- a/src/codecs/include/codec.hpp
+++ b/src/codecs/include/codec.hpp
@@ -7,6 +7,7 @@
#pragma once
#include <stdint.h>
+#include <sys/_stdint.h>
#include <cstddef>
#include <cstdint>
@@ -50,6 +51,9 @@ class ICodec {
uint8_t num_channels;
uint8_t bits_per_sample;
uint32_t sample_rate_hz;
+
+ std::optional<uint32_t> duration_seconds;
+ std::optional<uint32_t> bits_per_second;
};
/*
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp
index 23b4ccf6..81daeb9f 100644
--- a/src/codecs/mad.cpp
+++ b/src/codecs/mad.cpp
@@ -6,6 +6,7 @@
#include "mad.hpp"
#include <stdint.h>
+#include <sys/_stdint.h>
#include <cstdint>
#include <optional>
@@ -79,12 +80,19 @@ auto MadMp3Decoder::BeginStream(const cpp::span<const std::byte> input)
}
uint8_t channels = MAD_NCHANNELS(&header);
- return {GetBytesUsed(input.size_bytes()),
- OutputFormat{
- .num_channels = channels,
- .bits_per_sample = 24, // We always scale to 24 bits
- .sample_rate_hz = header.samplerate,
- }};
+ OutputFormat output{
+ .num_channels = channels,
+ .bits_per_sample = 24, // We always scale to 24 bits
+ .sample_rate_hz = header.samplerate,
+ .duration_seconds = {},
+ .bits_per_second = {},
+ };
+
+ // TODO(jacqueline): Support VBR. Although maybe libtags is the better place
+ // to handle this?
+ output.bits_per_second = header.bitrate;
+
+ return {GetBytesUsed(input.size_bytes()), output};
}
auto MadMp3Decoder::ContinueStream(cpp::span<const std::byte> input,