From 62f6179abe24339c2e5b7350528afbcad4c52067 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 15 Feb 2024 16:12:07 +1100 Subject: Added offset for track seeking, wav impl. only rn --- src/codecs/include/codec.hpp | 2 +- src/codecs/include/mad.hpp | 2 +- src/codecs/include/miniflac.hpp | 2 +- src/codecs/include/opus.hpp | 2 +- src/codecs/include/vorbis.hpp | 2 +- src/codecs/include/wav.hpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/codecs/include') diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index 8aa391b6..fb1ec771 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -117,7 +117,7 @@ class ICodec { * Decodes metadata or headers from the given input stream, and returns the * format for the samples that will be decoded from it. */ - virtual auto OpenStream(std::shared_ptr input) + virtual auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result = 0; struct OutputInfo { diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index 813aa86d..35e3284d 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -26,7 +26,7 @@ class MadMp3Decoder : public ICodec { MadMp3Decoder(); ~MadMp3Decoder(); - auto OpenStream(std::shared_ptr input) + auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; auto DecodeTo(cpp::span destination) diff --git a/src/codecs/include/miniflac.hpp b/src/codecs/include/miniflac.hpp index d57b08a3..d1daca2f 100644 --- a/src/codecs/include/miniflac.hpp +++ b/src/codecs/include/miniflac.hpp @@ -28,7 +28,7 @@ class MiniFlacDecoder : public ICodec { MiniFlacDecoder(); ~MiniFlacDecoder(); - auto OpenStream(std::shared_ptr input) + auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; auto DecodeTo(cpp::span destination) diff --git a/src/codecs/include/opus.hpp b/src/codecs/include/opus.hpp index 45b1b07a..1431fa54 100644 --- a/src/codecs/include/opus.hpp +++ b/src/codecs/include/opus.hpp @@ -26,7 +26,7 @@ class XiphOpusDecoder : public ICodec { XiphOpusDecoder(); ~XiphOpusDecoder(); - auto OpenStream(std::shared_ptr input) + auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; auto DecodeTo(cpp::span destination) diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp index 2f93c37e..b32ef8d5 100644 --- a/src/codecs/include/vorbis.hpp +++ b/src/codecs/include/vorbis.hpp @@ -28,7 +28,7 @@ class TremorVorbisDecoder : public ICodec { TremorVorbisDecoder(); ~TremorVorbisDecoder(); - auto OpenStream(std::shared_ptr input) + auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; auto DecodeTo(cpp::span destination) diff --git a/src/codecs/include/wav.hpp b/src/codecs/include/wav.hpp index 896976dd..e884a9bb 100644 --- a/src/codecs/include/wav.hpp +++ b/src/codecs/include/wav.hpp @@ -31,7 +31,7 @@ class WavDecoder : public ICodec { WavDecoder(); ~WavDecoder(); - auto OpenStream(std::shared_ptr input) + auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; auto DecodeTo(cpp::span destination) -- cgit v1.2.3 From f54347794f45261e0c0fde1104a70d1063c77305 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 22 Feb 2024 14:37:14 +1100 Subject: WIP: Flac not working-- coming back to this later --- src/codecs/include/source_buffer.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/codecs/include') diff --git a/src/codecs/include/source_buffer.hpp b/src/codecs/include/source_buffer.hpp index d0d7635a..7834834d 100644 --- a/src/codecs/include/source_buffer.hpp +++ b/src/codecs/include/source_buffer.hpp @@ -24,6 +24,7 @@ class SourceBuffer { auto Refill(IStream* src) -> bool; auto AddBytes(std::function)> writer) -> void; auto ConsumeBytes(std::function)> reader) -> void; + auto Empty() -> void; SourceBuffer(const SourceBuffer&) = delete; SourceBuffer& operator=(const SourceBuffer&) = delete; -- cgit v1.2.3 From d41f9f703375171d5766840c9edec32ff47bb25d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 29 Feb 2024 12:08:12 +1100 Subject: Use drflac instead of miniflac This one is fast as hell! Does seeking really good too. Thank u Doctor Flac. --- src/codecs/include/dr_flac.hpp | 46 +++++++++++++++++++++++++++++++++++++ src/codecs/include/miniflac.hpp | 51 ----------------------------------------- 2 files changed, 46 insertions(+), 51 deletions(-) create mode 100644 src/codecs/include/dr_flac.hpp delete mode 100644 src/codecs/include/miniflac.hpp (limited to 'src/codecs/include') diff --git a/src/codecs/include/dr_flac.hpp b/src/codecs/include/dr_flac.hpp new file mode 100644 index 00000000..8dcfdaf5 --- /dev/null +++ b/src/codecs/include/dr_flac.hpp @@ -0,0 +1,46 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "dr_flac.h" +#include "sample.hpp" +#include "source_buffer.hpp" +#include "span.hpp" + +#include "codec.hpp" + +namespace codecs { + +class DrFlacDecoder : public ICodec { + public: + DrFlacDecoder(); + ~DrFlacDecoder(); + + auto OpenStream(std::shared_ptr input,uint32_t offset) + -> cpp::result override; + + auto DecodeTo(cpp::span destination) + -> cpp::result override; + + auto SeekTo(std::size_t target_sample) -> cpp::result override; + + DrFlacDecoder(const DrFlacDecoder&) = delete; + DrFlacDecoder& operator=(const DrFlacDecoder&) = delete; + + private: + std::shared_ptr input_; + drflac *flac_; +}; + +} // namespace codecs diff --git a/src/codecs/include/miniflac.hpp b/src/codecs/include/miniflac.hpp deleted file mode 100644 index d1daca2f..00000000 --- a/src/codecs/include/miniflac.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "miniflac.h" -#include "sample.hpp" -#include "source_buffer.hpp" -#include "span.hpp" - -#include "codec.hpp" - -namespace codecs { - -class MiniFlacDecoder : public ICodec { - public: - MiniFlacDecoder(); - ~MiniFlacDecoder(); - - auto OpenStream(std::shared_ptr input,uint32_t offset) - -> cpp::result override; - - auto DecodeTo(cpp::span destination) - -> cpp::result override; - - auto SeekTo(std::size_t target_sample) -> cpp::result override; - - MiniFlacDecoder(const MiniFlacDecoder&) = delete; - MiniFlacDecoder& operator=(const MiniFlacDecoder&) = delete; - - private: - std::shared_ptr input_; - SourceBuffer buffer_; - - std::unique_ptr flac_; - std::array samples_by_channel_; - std::optional current_sample_; -}; - -} // namespace codecs -- cgit v1.2.3 From e7e6c70fb31d33ae1e79f9841f5b6fe227f6ebf3 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 29 Feb 2024 12:18:17 +1100 Subject: Remove unused 'SeekTo' method on codecs --- src/codecs/include/codec.hpp | 2 -- src/codecs/include/dr_flac.hpp | 2 -- src/codecs/include/mad.hpp | 2 -- src/codecs/include/opus.hpp | 2 -- src/codecs/include/vorbis.hpp | 2 -- src/codecs/include/wav.hpp | 2 -- 6 files changed, 12 deletions(-) (limited to 'src/codecs/include') diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index fb1ec771..e48e3c58 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -130,8 +130,6 @@ class ICodec { */ virtual auto DecodeTo(cpp::span destination) -> cpp::result = 0; - - virtual auto SeekTo(size_t target_sample) -> cpp::result = 0; }; auto CreateCodecForType(StreamType type) -> std::optional; diff --git a/src/codecs/include/dr_flac.hpp b/src/codecs/include/dr_flac.hpp index 8dcfdaf5..547876f4 100644 --- a/src/codecs/include/dr_flac.hpp +++ b/src/codecs/include/dr_flac.hpp @@ -33,8 +33,6 @@ class DrFlacDecoder : public ICodec { auto DecodeTo(cpp::span destination) -> cpp::result override; - auto SeekTo(std::size_t target_sample) -> cpp::result override; - DrFlacDecoder(const DrFlacDecoder&) = delete; DrFlacDecoder& operator=(const DrFlacDecoder&) = delete; diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index 35e3284d..ead0b2a2 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -32,8 +32,6 @@ class MadMp3Decoder : public ICodec { auto DecodeTo(cpp::span destination) -> cpp::result override; - auto SeekTo(std::size_t target_sample) -> cpp::result override; - MadMp3Decoder(const MadMp3Decoder&) = delete; MadMp3Decoder& operator=(const MadMp3Decoder&) = delete; diff --git a/src/codecs/include/opus.hpp b/src/codecs/include/opus.hpp index 1431fa54..de2f7131 100644 --- a/src/codecs/include/opus.hpp +++ b/src/codecs/include/opus.hpp @@ -32,8 +32,6 @@ class XiphOpusDecoder : public ICodec { auto DecodeTo(cpp::span destination) -> cpp::result override; - auto SeekTo(std::size_t target_sample) -> cpp::result override; - XiphOpusDecoder(const XiphOpusDecoder&) = delete; XiphOpusDecoder& operator=(const XiphOpusDecoder&) = delete; diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp index 94868c1a..3cf0f9ce 100644 --- a/src/codecs/include/vorbis.hpp +++ b/src/codecs/include/vorbis.hpp @@ -32,8 +32,6 @@ class TremorVorbisDecoder : public ICodec { auto DecodeTo(cpp::span destination) -> cpp::result override; - auto SeekTo(std::size_t target_sample) -> cpp::result override; - TremorVorbisDecoder(const TremorVorbisDecoder&) = delete; TremorVorbisDecoder& operator=(const TremorVorbisDecoder&) = delete; diff --git a/src/codecs/include/wav.hpp b/src/codecs/include/wav.hpp index e884a9bb..40138968 100644 --- a/src/codecs/include/wav.hpp +++ b/src/codecs/include/wav.hpp @@ -37,8 +37,6 @@ class WavDecoder : public ICodec { auto DecodeTo(cpp::span destination) -> cpp::result override; - auto SeekTo(std::size_t target_sample) -> cpp::result override; - WavDecoder(const WavDecoder&) = delete; WavDecoder& operator=(const WavDecoder&) = delete; -- cgit v1.2.3