arduino-audio-tools
Loading...
Searching...
No Matches
CodecAACHelix.h
Go to the documentation of this file.
1#pragma once
2
4#ifndef HELIX_PRINT
5#define HELIX_PRINT
6#endif
7#include "AACDecoderHelix.h"
8
9namespace audio_tools {
10
21 public:
23 TRACED();
24 aac = new libhelix::AACDecoderHelix();
25 if (aac != nullptr) {
26 aac->setReference(this);
27 } else {
28 LOGE("Not enough memory for libhelix");
29 }
30 }
36 AACDecoderHelix(Print &out_stream) {
37 TRACED();
38 aac = new libhelix::AACDecoderHelix(out_stream);
39 if (aac != nullptr) {
40 aac->setReference(this);
41 } else {
42 LOGE("Not enough memory for libhelix");
43 }
44 }
45
54 TRACED();
55 aac = new libhelix::AACDecoderHelix(out_stream);
56 if (aac != nullptr) {
57 aac->setReference(this);
58 } else {
59 LOGE("Not enough memory for libhelix");
60 }
62 }
63
69 TRACED();
70 if (aac != nullptr) delete aac;
71 }
72
73 const char *mime() override { return "audio/aac"; }
74
75 // void setRaw(bool flag){
76 // if (aac!=nullptr) aac->setRaw(flag);
77 // }
78
80 virtual void setOutput(Print &out_stream) override {
81 TRACED();
82 AudioDecoder::setOutput(out_stream);
83 if (aac != nullptr) aac->setOutput(out_stream);
84 }
85
87 bool begin() override {
88 TRACED();
89 if (aac != nullptr) {
90 // aac->setDelay(CODEC_DELAY_MS);
91 aac->setInfoCallback(infoCallback, this);
92 aac->begin();
93 }
94 return true;
95 }
96
98 virtual void end() override {
99 TRACED();
100 if (aac != nullptr) aac->end();
101 }
102
103 virtual _AACFrameInfo audioInfoEx() { return aac->audioInfo(); }
104
105 AudioInfo audioInfo() override {
106 AudioInfo result;
107 auto i = audioInfoEx();
108 if (i.nChans != 0 && i.bitsPerSample != 0 && i.sampRateOut != 0) {
109 result.channels = i.nChans;
110 result.sample_rate = i.sampRateOut;
111 result.bits_per_sample = i.bitsPerSample;
112 }
113 return result;
114 }
115
116 void setAudioInfo(AudioInfo info) override {
117 this->info = info;
120 }
121 }
122
124 size_t write(const uint8_t *data, size_t len) override {
125 LOGD("AACDecoderHelix::write: %d", (int)len);
126 if (aac == nullptr) return 0;
127 int open = len;
128 int processed = 0;
129 uint8_t *data8 = (uint8_t *)data;
130 while (open > 0) {
131 int act_write =
132 aac->write(data8 + processed, min(open, DEFAULT_BUFFER_SIZE));
133 open -= act_write;
134 processed += act_write;
135 }
136 return processed;
137 }
138
140 virtual operator bool() override { return aac != nullptr && (bool)*aac; }
141
142 void flush() {
143 // aac->flush();
144 }
145
147 static void infoCallback(_AACFrameInfo &i, void *ref) {
148 AACDecoderHelix *p_helix = (AACDecoderHelix *)ref;
149 if (p_helix != nullptr) {
150 TRACED();
151 AudioInfo baseInfo;
152 baseInfo.channels = i.nChans;
153 baseInfo.sample_rate = i.sampRateOut;
154 baseInfo.bits_per_sample = i.bitsPerSample;
155 // p_helix->audioChangeAACHelix->setAudioInfo(baseInfo);
156 LOGW("sample_rate: %d / channels: %d", i.sampRateOut, i.nChans);
157 p_helix->setAudioInfo(baseInfo);
158 }
159 }
160
163 size_t maxFrameSize() { return aac->maxFrameSize(); }
164
166 void setMaxFrameSize(size_t len) { aac->setMaxFrameSize(len); }
167
168 void setAudioInfoNotifications(bool active) {
170 }
171
174 size_t maxPCMSize() { return aac->maxPCMSize(); }
175
177 void setMaxPCMSize(size_t len) { aac->setMaxPCMSize(len); }
178
179 protected:
180 libhelix::AACDecoderHelix *aac = nullptr;
182};
183
184} // namespace audio_tools
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define DEFAULT_BUFFER_SIZE
Definition avr.h:20
Definition Arduino.h:56
AAC Decoder using libhelix: https://github.com/pschatzmann/arduino-libhelix This is basically just a ...
Definition CodecAACHelix.h:20
void setMaxPCMSize(size_t len)
Define your optimized maximum pwm buffer size.
Definition CodecAACHelix.h:177
void setMaxFrameSize(size_t len)
Define your optimized maximum frame size.
Definition CodecAACHelix.h:166
virtual _AACFrameInfo audioInfoEx()
Definition CodecAACHelix.h:103
AACDecoderHelix()
Definition CodecAACHelix.h:22
static void infoCallback(_AACFrameInfo &i, void *ref)
notifies the subscriber about a change
Definition CodecAACHelix.h:147
libhelix::AACDecoderHelix * aac
Definition CodecAACHelix.h:180
size_t maxFrameSize()
Definition CodecAACHelix.h:163
size_t maxPCMSize()
Definition CodecAACHelix.h:174
size_t write(const uint8_t *data, size_t len) override
Write AAC data to decoder.
Definition CodecAACHelix.h:124
const char * mime() override
Provides the mime type of the data that is expected by this decoder.
Definition CodecAACHelix.h:73
~AACDecoderHelix()
Destroy the AACDecoderMini object.
Definition CodecAACHelix.h:68
bool info_notifications_active
Definition CodecAACHelix.h:181
bool begin() override
Starts the processing.
Definition CodecAACHelix.h:87
virtual void setOutput(Print &out_stream) override
Defines the output Stream.
Definition CodecAACHelix.h:80
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition CodecAACHelix.h:116
void flush()
Definition CodecAACHelix.h:142
void setAudioInfoNotifications(bool active)
Definition CodecAACHelix.h:168
virtual void end() override
Releases the reserved memory.
Definition CodecAACHelix.h:98
AACDecoderHelix(Print &out_stream)
Construct a new AACDecoderMini object.
Definition CodecAACHelix.h:36
AACDecoderHelix(Print &out_stream, AudioInfoSupport &bi)
Construct a new AACDecoderMini object. The decoded output will go to the print object.
Definition CodecAACHelix.h:53
AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition CodecAACHelix.h:105
Decoding of encoded audio into PCM data.
Definition AudioCodecsBase.h:19
AudioInfo info
Definition AudioCodecsBase.h:80
virtual void setOutput(AudioStream &out_stream)
Defines where the decoded result is written to.
Definition AudioCodecsBase.h:40
void notifyAudioChange(AudioInfo info)
Definition AudioTypes.h:175
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition AudioTypes.h:150
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:132
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:51
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:53
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:55
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:57