diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-07 15:39:28 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-07 15:39:28 +1000 |
| commit | e12ac1d9632856237388614bf393c7338500e00a (patch) | |
| tree | 9f353c516427225906eafa9704f312dd12174a46 /src/codecs | |
| parent | 7e96482087632278c3d9e4a5db6bad25374ada8f (diff) | |
| download | tangara-fw-e12ac1d9632856237388614bf393c7338500e00a.tar.gz | |
Do some prep cleanup for multiple filetypes
Diffstat (limited to 'src/codecs')
| -rw-r--r-- | src/codecs/codec.cpp | 12 | ||||
| -rw-r--r-- | src/codecs/include/codec.hpp | 9 | ||||
| -rw-r--r-- | src/codecs/include/mad.hpp | 2 | ||||
| -rw-r--r-- | src/codecs/include/types.hpp | 8 | ||||
| -rw-r--r-- | src/codecs/mad.cpp | 8 |
5 files changed, 15 insertions, 24 deletions
diff --git a/src/codecs/codec.cpp b/src/codecs/codec.cpp index 4f9e8892..73bc9032 100644 --- a/src/codecs/codec.cpp +++ b/src/codecs/codec.cpp @@ -7,13 +7,19 @@ #include "codec.hpp" #include <memory> +#include <optional> #include "mad.hpp" +#include "types.hpp" namespace codecs { -auto CreateCodecForType(StreamType type) - -> cpp::result<std::unique_ptr<ICodec>, CreateCodecError> { - return std::make_unique<MadMp3Decoder>(); // TODO. +auto CreateCodecForType(StreamType type) -> std::optional<ICodec*> { + switch (type) { + case StreamType::kMp3: + return new MadMp3Decoder(); + default: + return {}; + } } } // namespace codecs diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index c8a68ff3..31c67e13 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -25,8 +25,6 @@ class ICodec { public: virtual ~ICodec() {} - virtual auto CanHandleType(StreamType type) -> bool = 0; - struct OutputFormat { uint8_t num_channels; uint8_t bits_per_sample; @@ -37,8 +35,6 @@ class ICodec { enum ProcessingError { MALFORMED_DATA }; - virtual auto ResetForNewStream() -> void = 0; - virtual auto SetInput(cpp::span<const std::byte> input) -> void = 0; /* @@ -69,9 +65,6 @@ class ICodec { -> std::pair<std::size_t, bool> = 0; }; -enum CreateCodecError { UNKNOWN_EXTENSION }; - -auto CreateCodecForType(StreamType type) - -> cpp::result<std::unique_ptr<ICodec>, CreateCodecError>; +auto CreateCodecForType(StreamType type) -> std::optional<ICodec*>; } // namespace codecs diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index ea16cdc8..5ba4db84 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -24,9 +24,7 @@ class MadMp3Decoder : public ICodec { MadMp3Decoder(); ~MadMp3Decoder(); - auto CanHandleType(StreamType type) -> bool override; auto GetOutputFormat() -> std::optional<OutputFormat> override; - auto ResetForNewStream() -> void override; auto SetInput(cpp::span<const std::byte> input) -> void override; auto GetInputPosition() -> std::size_t override; auto ProcessNextFrame() -> cpp::result<bool, ProcessingError> override; diff --git a/src/codecs/include/types.hpp b/src/codecs/include/types.hpp index 66f0c840..61d36a28 100644 --- a/src/codecs/include/types.hpp +++ b/src/codecs/include/types.hpp @@ -10,9 +10,11 @@ namespace codecs { -enum StreamType { - STREAM_MP3, +enum class StreamType { + kMp3, + kPcm, + kOgg, + kFlac, }; -auto GetStreamTypeFromFilename(std::string filename); } // namespace codecs diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 5044c22f..fbe85213 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -42,10 +42,6 @@ MadMp3Decoder::~MadMp3Decoder() { mad_synth_finish(&synth_); } -auto MadMp3Decoder::CanHandleType(StreamType type) -> bool { - return type == STREAM_MP3; -} - auto MadMp3Decoder::GetOutputFormat() -> std::optional<OutputFormat> { if (synth_.pcm.channels == 0 || synth_.pcm.samplerate == 0) { return {}; @@ -57,8 +53,6 @@ auto MadMp3Decoder::GetOutputFormat() -> std::optional<OutputFormat> { }); } -auto MadMp3Decoder::ResetForNewStream() -> void {} - auto MadMp3Decoder::SetInput(cpp::span<const std::byte> input) -> void { mad_stream_buffer(&stream_, reinterpret_cast<const unsigned char*>(input.data()), @@ -115,8 +109,6 @@ auto MadMp3Decoder::WriteOutputSamples(cpp::span<std::byte> output) } for (int channel = 0; channel < synth_.pcm.channels; channel++) { - // TODO(jacqueline): output 24 bit samples when (if?) we have a downmix - // step in the pipeline. uint32_t sample_24 = scaleToBits(synth_.pcm.samples[channel][current_sample_], 24); output[output_byte++] = static_cast<std::byte>((sample_24 >> 16) & 0xFF); |
