11#pragma once
22#include " AudioLogger.h"
3+ #include " AudioTools/AudioCodecs/AudioCodecsBase.h"
34#include " AudioTools/CoreAudio/AudioOutput.h"
45#include " AudioTools/CoreAudio/Buffers.h"
56
@@ -19,9 +20,13 @@ class MetaDataFilter : public AudioOutput {
1920
2021 // / Constructor which assigns the decoder
2122 MetaDataFilter (Print &out) { setOutput (out); }
23+ // / Constructor which assigns the decoder
24+ MetaDataFilter (AudioWriter &out) { setOutput (out); }
2225
2326 // / Defines the decoder to which we write the data
2427 void setOutput (Print &out) { p_out = &out; }
28+ // / Defines the decoder to which we write the data
29+ void setOutput (AudioWriter &out) { p_writer = &out; }
2530
2631 // / (Re)starts the processing
2732 bool begin () override {
@@ -35,7 +40,9 @@ class MetaDataFilter : public AudioOutput {
3540 TRACEI ();
3641 size_t result = len;
3742 // prevent npe
38- if ((p_out == nullptr ) || (data == nullptr ) || (len == 0 )) return 0 ;
43+ if ((p_out == nullptr && p_writer == nullptr ) || (data == nullptr ) ||
44+ (len == 0 ))
45+ return 0 ;
3946
4047 // find tag
4148 int meta_len = 0 ;
@@ -48,7 +55,8 @@ class MetaDataFilter : public AudioOutput {
4855
4956 // nothing to ignore
5057 if (!metadata_range.isDefined ()) {
51- return p_out->write (data, len);
58+ if (p_out) return p_out->write (data, len);
59+ if (p_writer) return p_writer->write (data, len);
5260 }
5361
5462 // ignore data in metadata range
@@ -61,7 +69,10 @@ class MetaDataFilter : public AudioOutput {
6169 }
6270
6371 // write partial data
64- if (tmp.available () > 0 ) p_out->write (tmp.data (), tmp.available ());
72+ if (tmp.available () > 0 ) {
73+ if (p_out) p_out->write (tmp.data (), tmp.available ());
74+ if (p_writer) p_writer->write (tmp.data (), tmp.available ());
75+ }
6576
6677 // reset for next run
6778 if (current_pos > metadata_range.to ) {
@@ -74,6 +85,7 @@ class MetaDataFilter : public AudioOutput {
7485
7586 protected:
7687 Print *p_out = nullptr ;
88+ AudioWriter *p_writer = nullptr ;
7789 int current_pos = 0 ;
7890 enum MetaType { TAG, TAG_PLUS, ID3 };
7991 int start = 0 ;
@@ -151,4 +163,43 @@ class MetaDataFilter : public AudioOutput {
151163 }
152164};
153165
166+ /* **
167+ * MetaDataFiler applied to the indicated decoder: Class which filters out ID3v1
168+ * and ID3v2 Metadata and provides only the audio data to the decoder
169+ * @ingroup metadata
170+ * @ingroup codecs
171+ * @author Phil Schatzmann
172+ * @copyright GPLv3
173+ */
174+ class MetaDataFilterDecoder : public AudioDecoder {
175+ public:
176+ MetaDataFilterDecoder (AudioDecoder &decoder) {
177+ p_decoder = &decoder;
178+ filter.setOutput (decoder);
179+ }
180+
181+ bool begin () override {
182+ is_active = true ;
183+ filter.begin ();
184+ return AudioDecoder::begin ();
185+ }
186+
187+ void end () override {
188+ is_active = false ;
189+ filter.end ();
190+ AudioDecoder::begin ();
191+ }
192+
193+ size_t write (const uint8_t *data, size_t len) override {
194+ return filter.write (data, len);
195+ }
196+
197+ operator bool () override { return p_print != nullptr && is_active; }
198+
199+ protected:
200+ AudioDecoder *p_decoder = nullptr ;
201+ MetaDataFilter filter;
202+ bool is_active = false ;
203+ };
204+
154205} // namespace audio_tools
0 commit comments