11#pragma once
22
3+ #include " AudioCodecsBase.h"
34#include " AudioConfig.h"
45#include " AudioLogger.h"
56#include " AudioTools/CoreAudio/AudioIO.h"
67#include " AudioTools/CoreAudio/AudioOutput.h"
78#include " AudioTools/CoreAudio/AudioStreams.h"
89#include " AudioTools/CoreAudio/AudioTypes.h"
9- #include " AudioCodecsBase.h"
1010
1111namespace audio_tools {
1212
@@ -20,9 +20,7 @@ namespace audio_tools {
2020 */
2121class EncodedAudioOutput : public ModifyingOutput {
2222 public:
23- EncodedAudioOutput () {
24- active = false ;
25- }
23+ EncodedAudioOutput () { active = false ; }
2624
2725 EncodedAudioOutput (AudioDecoder *decoder) {
2826 setDecoder (decoder);
@@ -88,14 +86,14 @@ class EncodedAudioOutput : public ModifyingOutput {
8886
8987 virtual void setAudioInfo (AudioInfo newInfo) override {
9088 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 ) {
9291 this ->cfg = newInfo;
9392 decoder_ptr->setAudioInfo (cfg);
9493 encoder_ptr->setAudioInfo (cfg);
9594 }
9695 }
9796
98-
9997 void setOutput (Print &outputStream) { setOutput (&outputStream); }
10098
10199 // / Defines the output
@@ -166,22 +164,24 @@ class EncodedAudioOutput : public ModifyingOutput {
166164
167165 // / Ends the processing
168166 void end () override {
167+ if (active) {
169168#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
170- custom_log_level.set ();
169+ custom_log_level.set ();
171170#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 ;
176175#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
177- custom_log_level.reset ();
176+ custom_log_level.reset ();
178177#endif
178+ }
179179 }
180180
181181 // / encoder decode the data
182182 virtual size_t write (const uint8_t *data, size_t len) override {
183183 if (len == 0 ) {
184- // LOGI("write: %d", 0);
184+ // LOGI("write: %d", 0);
185185 return 0 ;
186186 }
187187#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
@@ -303,21 +303,13 @@ class EncodedAudioStream : public ReformatBaseStream {
303303 // / Provides the initialized encoder
304304 AudioEncoder &encoder () { return *getEncoder (); }
305305
306- void setStream (Stream *stream) {
307- setStream (*stream);
308- }
306+ void setStream (Stream *stream) { setStream (*stream); }
309307
310- void setStream (AudioStream *stream) {
311- setStream (*stream);
312- }
308+ void setStream (AudioStream *stream) { setStream (*stream); }
313309
314- void setOutput (AudioOutput *stream) {
315- setOutput (*stream);
316- }
310+ void setOutput (AudioOutput *stream) { setOutput (*stream); }
317311
318- void setOutput (Print *stream) {
319- setOutput (*stream);
320- }
312+ void setOutput (Print *stream) { setOutput (*stream); }
321313
322314 void setStream (AudioStream &stream) {
323315 ReformatBaseStream::setStream (stream);
@@ -350,7 +342,7 @@ class EncodedAudioStream : public ReformatBaseStream {
350342 }
351343
352344 bool begin () {
353- // is_output_notify = false;
345+ // is_output_notify = false;
354346 setupReader ();
355347 ReformatBaseStream::begin ();
356348 return enc_out.begin (audioInfo ());
@@ -364,7 +356,7 @@ class EncodedAudioStream : public ReformatBaseStream {
364356 int availableForWrite () { return enc_out.availableForWrite (); }
365357
366358 size_t write (const uint8_t *data, size_t len) {
367- // addNotifyOnFirstWrite();
359+ // addNotifyOnFirstWrite();
368360 return enc_out.write (data, len);
369361 }
370362
@@ -376,12 +368,12 @@ class EncodedAudioStream : public ReformatBaseStream {
376368 enc_out.addNotifyAudioChange (bi);
377369 }
378370
379- // / approx compression factor: e.g. mp3 is around 4
371+ // / approx compression factor: e.g. mp3 is around 4
380372 float getByteFactor () { return byte_factor; }
381- void setByteFactor (float factor) {byte_factor = factor;}
373+ void setByteFactor (float factor) { byte_factor = factor; }
382374
383375#if USE_AUDIO_LOGGING && !defined(USE_IDF_LOGGER)
384- // / Defines the class specific custom log level
376+ // / Defines the class specific custom log level
385377 void setLogLevel (AudioLogger::LogLevel level) { enc_out.setLogLevel (level); }
386378#endif
387379
@@ -391,7 +383,6 @@ class EncodedAudioStream : public ReformatBaseStream {
391383 protected:
392384 EncodedAudioOutput enc_out;
393385 float byte_factor = 2 .0f ;
394-
395386};
396387
397388/* *
0 commit comments