1
1
#pragma once
2
2
#include " AudioLogger.h"
3
+ #include " AudioTools/AudioCodecs/AudioCodecsBase.h"
3
4
#include " AudioTools/CoreAudio/AudioOutput.h"
4
5
#include " AudioTools/CoreAudio/Buffers.h"
5
6
@@ -19,9 +20,13 @@ class MetaDataFilter : public AudioOutput {
19
20
20
21
// / Constructor which assigns the decoder
21
22
MetaDataFilter (Print &out) { setOutput (out); }
23
+ // / Constructor which assigns the decoder
24
+ MetaDataFilter (AudioWriter &out) { setOutput (out); }
22
25
23
26
// / Defines the decoder to which we write the data
24
27
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; }
25
30
26
31
// / (Re)starts the processing
27
32
bool begin () override {
@@ -35,7 +40,9 @@ class MetaDataFilter : public AudioOutput {
35
40
TRACEI ();
36
41
size_t result = len;
37
42
// 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 ;
39
46
40
47
// find tag
41
48
int meta_len = 0 ;
@@ -48,7 +55,8 @@ class MetaDataFilter : public AudioOutput {
48
55
49
56
// nothing to ignore
50
57
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);
52
60
}
53
61
54
62
// ignore data in metadata range
@@ -61,7 +69,10 @@ class MetaDataFilter : public AudioOutput {
61
69
}
62
70
63
71
// 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
+ }
65
76
66
77
// reset for next run
67
78
if (current_pos > metadata_range.to ) {
@@ -74,6 +85,7 @@ class MetaDataFilter : public AudioOutput {
74
85
75
86
protected:
76
87
Print *p_out = nullptr ;
88
+ AudioWriter *p_writer = nullptr ;
77
89
int current_pos = 0 ;
78
90
enum MetaType { TAG, TAG_PLUS, ID3 };
79
91
int start = 0 ;
@@ -151,4 +163,43 @@ class MetaDataFilter : public AudioOutput {
151
163
}
152
164
};
153
165
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
+
154
205
} // namespace audio_tools
0 commit comments