1
1
#pragma once
2
2
3
+ #include " AudioCodecsBase.h"
3
4
#include " AudioConfig.h"
4
5
#include " AudioLogger.h"
5
6
#include " AudioTools/CoreAudio/AudioIO.h"
6
7
#include " AudioTools/CoreAudio/AudioOutput.h"
7
8
#include " AudioTools/CoreAudio/AudioStreams.h"
8
9
#include " AudioTools/CoreAudio/AudioTypes.h"
9
- #include " AudioCodecsBase.h"
10
10
11
11
namespace audio_tools {
12
12
@@ -20,9 +20,7 @@ namespace audio_tools {
20
20
*/
21
21
class EncodedAudioOutput : public ModifyingOutput {
22
22
public:
23
- EncodedAudioOutput () {
24
- active = false ;
25
- }
23
+ EncodedAudioOutput () { active = false ; }
26
24
27
25
EncodedAudioOutput (AudioDecoder *decoder) {
28
26
setDecoder (decoder);
@@ -88,14 +86,14 @@ class EncodedAudioOutput : public ModifyingOutput {
88
86
89
87
virtual void setAudioInfo (AudioInfo newInfo) override {
90
88
TRACED ();
91
- if (this ->cfg != newInfo && newInfo.channels != 0 && newInfo.sample_rate != 0 ) {
89
+ if (this ->cfg != newInfo && newInfo.channels != 0 &&
90
+ newInfo.sample_rate != 0 ) {
92
91
this ->cfg = newInfo;
93
92
decoder_ptr->setAudioInfo (cfg);
94
93
encoder_ptr->setAudioInfo (cfg);
95
94
}
96
95
}
97
96
98
-
99
97
void setOutput (Print &outputStream) { setOutput (&outputStream); }
100
98
101
99
// / Defines the output
@@ -166,22 +164,24 @@ class EncodedAudioOutput : public ModifyingOutput {
166
164
167
165
// / Ends the processing
168
166
void end () override {
167
+ if (active) {
169
168
#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
170
- custom_log_level.set ();
169
+ custom_log_level.set ();
171
170
#endif
172
- TRACEI ();
173
- decoder_ptr->end ();
174
- encoder_ptr->end ();
175
- active = false ;
171
+ TRACEI ();
172
+ decoder_ptr->end ();
173
+ encoder_ptr->end ();
174
+ active = false ;
176
175
#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
177
- custom_log_level.reset ();
176
+ custom_log_level.reset ();
178
177
#endif
178
+ }
179
179
}
180
180
181
181
// / encoder decode the data
182
182
virtual size_t write (const uint8_t *data, size_t len) override {
183
183
if (len == 0 ) {
184
- // LOGI("write: %d", 0);
184
+ // LOGI("write: %d", 0);
185
185
return 0 ;
186
186
}
187
187
#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
@@ -303,21 +303,13 @@ class EncodedAudioStream : public ReformatBaseStream {
303
303
// / Provides the initialized encoder
304
304
AudioEncoder &encoder () { return *getEncoder (); }
305
305
306
- void setStream (Stream *stream) {
307
- setStream (*stream);
308
- }
306
+ void setStream (Stream *stream) { setStream (*stream); }
309
307
310
- void setStream (AudioStream *stream) {
311
- setStream (*stream);
312
- }
308
+ void setStream (AudioStream *stream) { setStream (*stream); }
313
309
314
- void setOutput (AudioOutput *stream) {
315
- setOutput (*stream);
316
- }
310
+ void setOutput (AudioOutput *stream) { setOutput (*stream); }
317
311
318
- void setOutput (Print *stream) {
319
- setOutput (*stream);
320
- }
312
+ void setOutput (Print *stream) { setOutput (*stream); }
321
313
322
314
void setStream (AudioStream &stream) {
323
315
ReformatBaseStream::setStream (stream);
@@ -350,7 +342,7 @@ class EncodedAudioStream : public ReformatBaseStream {
350
342
}
351
343
352
344
bool begin () {
353
- // is_output_notify = false;
345
+ // is_output_notify = false;
354
346
setupReader ();
355
347
ReformatBaseStream::begin ();
356
348
return enc_out.begin (audioInfo ());
@@ -364,7 +356,7 @@ class EncodedAudioStream : public ReformatBaseStream {
364
356
int availableForWrite () { return enc_out.availableForWrite (); }
365
357
366
358
size_t write (const uint8_t *data, size_t len) {
367
- // addNotifyOnFirstWrite();
359
+ // addNotifyOnFirstWrite();
368
360
return enc_out.write (data, len);
369
361
}
370
362
@@ -376,12 +368,12 @@ class EncodedAudioStream : public ReformatBaseStream {
376
368
enc_out.addNotifyAudioChange (bi);
377
369
}
378
370
379
- // / approx compression factor: e.g. mp3 is around 4
371
+ // / approx compression factor: e.g. mp3 is around 4
380
372
float getByteFactor () { return byte_factor; }
381
- void setByteFactor (float factor) {byte_factor = factor;}
373
+ void setByteFactor (float factor) { byte_factor = factor; }
382
374
383
375
#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
384
- // / Defines the class specific custom log level
376
+ // / Defines the class specific custom log level
385
377
void setLogLevel (AudioLogger::LogLevel level) { enc_out.setLogLevel (level); }
386
378
#endif
387
379
@@ -391,7 +383,6 @@ class EncodedAudioStream : public ReformatBaseStream {
391
383
protected:
392
384
EncodedAudioOutput enc_out;
393
385
float byte_factor = 2 .0f ;
394
-
395
386
};
396
387
397
388
/* *
0 commit comments