arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
CodecAACHelix.h
1#pragma once
2
3#include "AudioTools/AudioCodecs/AudioCodecsBase.h"
4#ifndef HELIX_PRINT
5# define HELIX_PRINT
6#endif
7#include "AACDecoderHelix.h"
8
9namespace audio_tools {
10
20 public:
21
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 // void setRaw(bool flag){
74 // if (aac!=nullptr) aac->setRaw(flag);
75 // }
76
78 virtual void setOutput(Print &out_stream) override {
79 TRACED();
80 AudioDecoder::setOutput(out_stream);
81 if (aac!=nullptr) aac->setOutput(out_stream);
82 }
83
85 bool begin() override {
86 TRACED();
87 if (aac!=nullptr) {
88 //aac->setDelay(CODEC_DELAY_MS);
89 aac->setInfoCallback(infoCallback, this);
90 aac->begin();
91 }
92 return true;
93 }
94
96 virtual void end() override {
97 TRACED();
98 if (aac!=nullptr) aac->end();
99 }
100
101 virtual _AACFrameInfo audioInfoEx(){
102 return aac->audioInfo();
103 }
104
106 AudioInfo result;
107 auto i = audioInfoEx();
108 result.channels = i.nChans;
109 result.sample_rate = i.sampRateOut;
110 result.bits_per_sample = i.bitsPerSample;
111 return result;
112 }
113
114 void setAudioInfo(AudioInfo info) override {
115 this->info = info;
116 if(info_notifications_active){
117 notifyAudioChange(info);
118 }
119 }
120
122 size_t write(const uint8_t* data, size_t len) override {
123 LOGD("AACDecoderHelix::write: %d", (int)len);
124 if (aac==nullptr) return 0;
125 int open = len;
126 int processed = 0;
127 uint8_t *data8 = (uint8_t*)data;
128 while(open>0){
129 int act_write = aac->write(data8+processed, min(open, DEFAULT_BUFFER_SIZE));
130 open -= act_write;
131 processed += act_write;
132 }
133 return processed;
134 }
135
137 virtual operator bool() override {
138 return aac!=nullptr && (bool)*aac;
139 }
140
141 void flush(){
142 // aac->flush();
143 }
144
146 static void infoCallback(_AACFrameInfo &i, void* ref){
147 AACDecoderHelix *p_helix = (AACDecoderHelix *)ref;
148 if (p_helix!=nullptr){
149 TRACED();
150 AudioInfo baseInfo;
151 baseInfo.channels = i.nChans;
152 baseInfo.sample_rate = i.sampRateOut;
153 baseInfo.bits_per_sample = i.bitsPerSample;
154 //p_helix->audioChangeAACHelix->setAudioInfo(baseInfo);
155 LOGW("sample_rate: %d", i.sampRateOut);
156 p_helix->setAudioInfo(baseInfo);
157 }
158 }
159
161 size_t maxFrameSize() {
162 return aac->maxFrameSize();
163 }
164
166 void setMaxFrameSize(size_t len){
167 aac->setMaxFrameSize(len);
168 }
169
170 void setAudioInfoNotifications(bool active){
171 info_notifications_active = active;
172 }
173
175 size_t maxPCMSize() {
176 return aac->maxPCMSize();
177 }
178
180 void setMaxPCMSize(size_t len) {
181 aac->setMaxPCMSize(len);
182 }
183
184 protected:
185 libhelix::AACDecoderHelix *aac=nullptr;
186 bool info_notifications_active = true;
187
188};
189
190
191} // namespace
192
AAC Decoder using libhelix: https://github.com/pschatzmann/arduino-libhelix This is basically just a ...
Definition CodecAACHelix.h:19
void setMaxPCMSize(size_t len)
Define your optimized maximum pwm buffer size.
Definition CodecAACHelix.h:180
void setMaxFrameSize(size_t len)
Define your optimized maximum frame size.
Definition CodecAACHelix.h:166
static void infoCallback(_AACFrameInfo &i, void *ref)
notifies the subscriber about a change
Definition CodecAACHelix.h:146
size_t maxFrameSize()
Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my m...
Definition CodecAACHelix.h:161
size_t maxPCMSize()
Provides the maximum pwm buffer size - this is allocated on the heap and you can reduce the heap size...
Definition CodecAACHelix.h:175
size_t write(const uint8_t *data, size_t len) override
Write AAC data to decoder.
Definition CodecAACHelix.h:122
~AACDecoderHelix()
Destroy the AACDecoderMini object.
Definition CodecAACHelix.h:68
bool begin() override
Starts the processing.
Definition CodecAACHelix.h:85
virtual void setOutput(Print &out_stream) override
Defines the output Stream.
Definition CodecAACHelix.h:78
void setAudioInfo(AudioInfo info) override
Defines the input AudioInfo.
Definition CodecAACHelix.h:114
virtual void end() override
Releases the reserved memory.
Definition CodecAACHelix.h:96
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:18
virtual void setOutput(AudioStream &out_stream)
Defines where the decoded result is written to.
Definition AudioCodecsBase.h:36
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition AudioTypes.h:151
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:133
Definition NoArduino.h:62
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:53
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:55
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:57
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:59