From 27d09c34bd7edbaa1c53edf61fcd9bcbef5af523 Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Mon, 29 Jan 2024 10:04:30 +0100 Subject: [PATCH] doygen --- Doxyfile | 2 +- docs/html/_a_a_c_decoder_helix_8h_source.html | 379 +++--- docs/html/_common_helix_8h_source.html | 611 +++++----- docs/html/_m_p3_decoder_helix_8h_source.html | 395 +++---- docs/html/annotated.html | 47 +- docs/html/classes.html | 47 +- ...helix_1_1_a_a_c_decoder_helix-members.html | 103 +- ...classlibhelix_1_1_a_a_c_decoder_helix.html | 480 +++----- .../classlibhelix_1_1_a_a_c_decoder_helix.png | Bin 650 -> 634 bytes ...lasslibhelix_1_1_common_helix-members.html | 90 +- docs/html/classlibhelix_1_1_common_helix.html | 368 ++---- docs/html/classlibhelix_1_1_common_helix.png | Bin 936 -> 903 bytes ...bhelix_1_1_m_p3_decoder_helix-members.html | 110 +- .../classlibhelix_1_1_m_p3_decoder_helix.html | 480 +++----- .../classlibhelix_1_1_m_p3_decoder_helix.png | Bin 667 -> 650 bytes .../dir_68267d1309a1af8e8297ef4c3efbcdba.html | 53 +- docs/html/doxygen.css | 1028 +++++++---------- docs/html/dynsections.js | 2 - docs/html/files.html | 45 +- docs/html/functions.html | 160 ++- docs/html/functions_func.html | 160 ++- docs/html/helix__log_8h_source.html | 91 +- docs/html/helix__pgm_8h_source.html | 61 +- docs/html/hierarchy.html | 43 +- docs/html/index.html | 43 +- docs/html/jquery.js | 11 +- docs/html/menu.js | 97 +- docs/html/search/all_0.js | 2 +- docs/html/search/all_1.js | 2 +- docs/html/search/all_2.js | 2 +- docs/html/search/all_3.js | 3 +- docs/html/search/all_4.js | 2 +- docs/html/search/all_5.js | 6 +- docs/html/search/all_6.js | 6 +- docs/html/search/all_7.js | 2 +- docs/html/search/all_8.js | 2 +- docs/html/search/all_9.js | 10 +- docs/html/search/all_a.js | 4 +- docs/html/search/all_b.js | 4 +- docs/html/search/classes_0.js | 2 +- docs/html/search/classes_1.js | 2 +- docs/html/search/classes_2.js | 2 +- docs/html/search/classes_3.js | 2 +- docs/html/search/functions_0.js | 6 +- docs/html/search/functions_1.js | 2 +- docs/html/search/functions_2.js | 3 +- docs/html/search/functions_3.js | 2 +- docs/html/search/functions_4.js | 6 +- docs/html/search/functions_5.js | 4 +- docs/html/search/functions_6.js | 2 +- docs/html/search/functions_7.js | 10 +- docs/html/search/functions_8.js | 4 +- docs/html/search/functions_9.js | 4 +- docs/html/search/pages_0.js | 2 +- docs/html/search/search.css | 122 +- docs/html/search/search.js | 160 +-- .../structlibhelix_1_1_range-members.html | 41 +- docs/html/structlibhelix_1_1_range.html | 53 +- docs/html/tabs.css | 2 +- 59 files changed, 2282 insertions(+), 3100 deletions(-) diff --git a/Doxyfile b/Doxyfile index a2474ae..6d7c8c2 100644 --- a/Doxyfile +++ b/Doxyfile @@ -151,7 +151,7 @@ ALWAYS_DETAILED_SEC = NO # operators of the base classes will not be shown. # The default value is: NO. -INLINE_INHERITED_MEMB = NO +INLINE_INHERITED_MEMB = YES # If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the diff --git a/docs/html/_a_a_c_decoder_helix_8h_source.html b/docs/html/_a_a_c_decoder_helix_8h_source.html index 8102abc..3b271fc 100644 --- a/docs/html/_a_a_c_decoder_helix_8h_source.html +++ b/docs/html/_a_a_c_decoder_helix_8h_source.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: src/AACDecoderHelix.h Source File @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
AACDecoderHelix.h
+
+
AACDecoderHelix.h
-
1#pragma once
-
2
-
3#include "CommonHelix.h"
-
4#include "libhelix-aac/aacdec.h"
-
5
-
6#define AAC_MAX_OUTPUT_SIZE 1024 * 3
-
7#define AAC_MAX_FRAME_SIZE 2100
-
8
-
9namespace libhelix {
-
10
-
11typedef void (*AACInfoCallback)(_AACFrameInfo &info);
-
12typedef void (*AACDataCallback)(_AACFrameInfo &info,short *pcm_buffer, size_t len);
-
13
- -
21 public:
-
22 AACDecoderHelix() = default;
-
23
-
24#ifdef ARDUINO
-
25 AACDecoderHelix(Print &output, AACInfoCallback infoCallback=nullptr){
-
26 this->out = &output;
-
27 this->infoCallback = infoCallback;
-
28 }
-
29#endif
-
30 AACDecoderHelix(AACDataCallback dataCallback){
-
31 this->pcmCallback = dataCallback;
-
32 }
-
33
-
34 virtual ~AACDecoderHelix(){
-
35 end();
-
36 }
-
37
-
38
-
39 void setInfoCallback(AACInfoCallback cb){
-
40 this->infoCallback = cb;
-
41 }
-
42
-
43 void setDataCallback(AACDataCallback cb){
-
44 this->pcmCallback = cb;
-
45 }
-
46
-
47
-
49 virtual void end() override {
-
50 LOG_HELIX(Debug, "end");
-
51 if (decoder!=nullptr){
-
52 flush();
-
53 AACFreeDecoder(decoder);
-
54 decoder = nullptr;
-
55 }
- -
57 memset(&aacFrameInfo,0,sizeof(_AACFrameInfo));
-
58 }
-
59
-
61 _AACFrameInfo audioInfo(){
-
62 return aacFrameInfo;
-
63 }
-
64
-
65 size_t maxFrameSize() override {
-
66 return max_frame_size == 0 ? AAC_MAX_FRAME_SIZE : max_frame_size;
-
67 }
-
68
-
69 size_t maxPCMSize() override {
-
70 return max_pcm_size == 0 ? AAC_MAX_OUTPUT_SIZE : max_pcm_size;
-
71 }
-
72
-
73 protected:
-
74 HAACDecoder decoder = nullptr;
-
75 AACDataCallback pcmCallback = nullptr;
-
76 AACInfoCallback infoCallback = nullptr;
-
77 _AACFrameInfo aacFrameInfo;
-
78
-
80 virtual void allocateDecoder() override {
-
81 if (decoder==nullptr){
-
82 decoder = AACInitDecoder();
-
83 }
-
84 }
-
85
-
86
-
87 int findSynchWord(int offset=0) override {
-
88 int result = AACFindSyncWord(frame_buffer+offset, buffer_size)+offset;
-
89 return result < 0 ? result : result + offset;
-
90 }
-
91
-
93 void decode(Range r) override {
-
94 LOG_HELIX(Debug, "decode %d", r.end);
-
95 int len = buffer_size - r.start;
-
96 int bytesLeft = len;
-
97 uint8_t* ptr = frame_buffer + r.start;
-
98
-
99 int result = AACDecode(decoder, &ptr, &bytesLeft, pcm_buffer);
-
100 int decoded = len - bytesLeft;
-
101 assert(decoded == ptr-(frame_buffer + r.start));
-
102 if (result==0){
-
103 LOG_HELIX(Debug, "-> bytesLeft %d -> %d = %d ", buffer_size, bytesLeft, decoded);
-
104 LOG_HELIX(Debug, "-> End of frame (%d) vs end of decoding (%d)", r.end, decoded)
-
105
-
106 // return the decoded result
-
107 _AACFrameInfo info;
-
108 AACGetLastFrameInfo(decoder, &info);
-
109 provideResult(info);
-
110
-
111 // remove processed data from buffer
-
112 if (decoded<=buffer_size) {
-
113 buffer_size -= decoded;
-
114 //assert(buffer_size<=maxFrameSize());
-
115 memmove(frame_buffer, frame_buffer+r.start+decoded, buffer_size);
-
116 LOG_HELIX(Debug, " -> decoded %d bytes - remaining buffer_size: %d", decoded, buffer_size);
-
117 } else {
-
118 LOG_HELIX(Warning, " -> decoded %d > buffersize %d", decoded, buffer_size);
-
119 buffer_size = 0;
-
120 }
-
121 } else {
-
122 // decoding error
-
123 LOG_HELIX(Debug, " -> decode error: %d - removing frame!", result);
-
124 int ignore = decoded;
-
125 if (ignore == 0) ignore = r.end;
-
126 // We advance to the next synch world
-
127 if (ignore<=buffer_size){
-
128 buffer_size -= ignore;
-
129 memmove(frame_buffer, frame_buffer+ignore, buffer_size);
-
130 } else {
-
131 buffer_size = 0;
-
132 }
-
133 }
-
134 }
-
135
-
136 // return the result PCM data
-
137 void provideResult(_AACFrameInfo &info){
-
138 LOG_HELIX(Debug, "provideResult: %d samples",info.outputSamps);
-
139 if (info.outputSamps>0){
-
140 // provide result
-
141 if(pcmCallback!=nullptr){
-
142 // output via callback
-
143 pcmCallback(info, pcm_buffer,info.outputSamps);
-
144 } else {
-
145 // output to stream
-
146 if (info.sampRateOut!=aacFrameInfo.sampRateOut && infoCallback!=nullptr){
-
147 infoCallback(info);
-
148 }
-
149#ifdef ARDUINO
-
150 int sampleSize = info.bitsPerSample / 8;
-
151 out->write((uint8_t*)pcm_buffer, info.outputSamps*sampleSize);
-
152#endif
-
153 }
-
154 aacFrameInfo = info;
-
155 }
-
156 }
-
157};
-
158}
+
1 #pragma once
+
2 
+
3 #include "CommonHelix.h"
+
4 #include "libhelix-aac/aacdec.h"
+
5 
+
6 #define AAC_MAX_OUTPUT_SIZE 1024 * 3
+
7 #define AAC_MAX_FRAME_SIZE 2100
+
8 
+
9 namespace libhelix {
+
10 
+
11 typedef void (*AACInfoCallback)(_AACFrameInfo &info, void* caller);
+
12 typedef void (*AACDataCallback)(_AACFrameInfo &info,short *pcm_buffer, size_t len, void* caller);
+
13 
+
20 class AACDecoderHelix : public CommonHelix {
+
21  public:
+
22  AACDecoderHelix() = default;
+
23 
+
24 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
25  AACDecoderHelix(Print &output){
+
26  this->out = &output;
+
27  }
+
28 #endif
+
29  AACDecoderHelix(AACDataCallback dataCallback){
+
30  this->pcmCallback = dataCallback;
+
31  }
+
32 
+
33  virtual ~AACDecoderHelix(){
+
34  end();
+
35  }
+
36 
+
37  void setInfoCallback(AACInfoCallback cb, void* caller=nullptr){
+
38  this->infoCallback = cb;
+
39  p_caller_info = caller;
+
40  }
+
41 
+
42  void setDataCallback(AACDataCallback cb){
+
43  this->pcmCallback = cb;
+
44  }
+
45 
+
47  virtual void end() override {
+
48  LOG_HELIX(Debug, "end");
+
49  if (decoder!=nullptr){
+
50  flush();
+
51  AACFreeDecoder(decoder);
+
52  decoder = nullptr;
+
53  }
+ +
55  memset(&aacFrameInfo,0,sizeof(_AACFrameInfo));
+
56  }
+
57 
+
59  _AACFrameInfo audioInfo(){
+
60  return aacFrameInfo;
+
61  }
+
62 
+
63  size_t maxFrameSize() override {
+
64  return max_frame_size == 0 ? AAC_MAX_FRAME_SIZE : max_frame_size;
+
65  }
+
66 
+
67  size_t maxPCMSize() override {
+
68  return max_pcm_size == 0 ? AAC_MAX_OUTPUT_SIZE : max_pcm_size;
+
69  }
+
70 
+
72  void setAudioInfo(int channels, int samplerate) {
+
73  memset(&aacFrameInfo, 0, sizeof(AACFrameInfo));
+
74  aacFrameInfo.nChans = channels;
+
75  //aacFrameInfo.bitsPerSample = bits; not used
+
76  aacFrameInfo.sampRateCore = samplerate;
+
77  aacFrameInfo.profile = AAC_PROFILE_LC;
+
78  AACSetRawBlockParams(decoder, 0, &aacFrameInfo);
+
79  }
+
80 
+
81 
+
82  protected:
+
83  HAACDecoder decoder = nullptr;
+
84  AACDataCallback pcmCallback = nullptr;
+
85  AACInfoCallback infoCallback = nullptr;
+
86  _AACFrameInfo aacFrameInfo;
+
87  void *p_caller_info = nullptr;
+
88  void *p_caller_data = nullptr;
+
89 
+
91  virtual void allocateDecoder() override {
+
92  if (decoder==nullptr){
+
93  decoder = AACInitDecoder();
+
94  }
+
95  }
+
96 
+
98  int findSynchWord(int offset=0) override {
+
99  int result = AACFindSyncWord(frame_buffer+offset, buffer_size);;
+
100  return result < 0 ? result : result + offset;
+
101  }
+
102 
+
104  void decode(Range r) override {
+
105  LOG_HELIX(Debug, "decode %d", r.end);
+
106  int len = buffer_size - r.start;
+
107  int bytesLeft = len;
+
108  uint8_t* ptr = frame_buffer + r.start;
+
109 
+
110  int result = AACDecode(decoder, &ptr, &bytesLeft, pcm_buffer);
+
111  int decoded = len - bytesLeft;
+
112  assert(decoded == ptr-(frame_buffer + r.start));
+
113  if (result==0){
+
114  LOG_HELIX(Debug, "-> bytesLeft %d -> %d = %d ", buffer_size, bytesLeft, decoded);
+
115  LOG_HELIX(Debug, "-> End of frame (%d) vs end of decoding (%d)", r.end, decoded)
+
116 
+
117  // return the decoded result
+
118  _AACFrameInfo info;
+
119  AACGetLastFrameInfo(decoder, &info);
+
120  provideResult(info);
+
121 
+
122  // remove processed data from buffer
+
123  if (decoded<=buffer_size) {
+
124  buffer_size -= decoded;
+
125  //assert(buffer_size<=maxFrameSize());
+
126  memmove(frame_buffer, frame_buffer+r.start+decoded, buffer_size);
+
127  LOG_HELIX(Debug, " -> decoded %d bytes - remaining buffer_size: %d", decoded, buffer_size);
+
128  } else {
+
129  LOG_HELIX(Warning, " -> decoded %d > buffersize %d", decoded, buffer_size);
+
130  buffer_size = 0;
+
131  }
+
132  } else {
+
133  // decoding error
+
134  LOG_HELIX(Debug, " -> decode error: %d - removing frame!", result);
+
135  int ignore = decoded;
+
136  if (ignore == 0) ignore = r.end;
+
137  // We advance to the next synch world
+
138  if (ignore<=buffer_size){
+
139  buffer_size -= ignore;
+
140  memmove(frame_buffer, frame_buffer+ignore, buffer_size);
+
141  } else {
+
142  buffer_size = 0;
+
143  }
+
144  }
+
145  }
+
146 
+
148  size_t decodeRaw(uint8_t* data, size_t len) override {
+
149  int bytesLeft = len;
+
150  int result = AACDecode(decoder, &data, &bytesLeft, pcm_buffer);
+
151  if (result==0){
+
152  // return the decoded result
+
153  _AACFrameInfo info;
+
154  AACGetLastFrameInfo(decoder, &info);
+
155  provideResult(info);
+
156  }
+
157  return len - bytesLeft;
+
158  }
+
159 
+
160 
+
161  // return the result PCM data
+
162  void provideResult(_AACFrameInfo &info){
+
163  LOG_HELIX(Debug, "provideResult: %d samples",info.outputSamps);
+
164  if (info.outputSamps>0){
+
165  // provide result
+
166  if(pcmCallback!=nullptr){
+
167  // output via callback
+
168  pcmCallback(info, pcm_buffer,info.outputSamps, p_caller_data);
+
169  } else {
+
170  // output to stream
+
171  if (info.sampRateOut!=aacFrameInfo.sampRateOut && infoCallback!=nullptr){
+
172  infoCallback(info, p_caller_info);
+
173  }
+
174 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
175  int sampleSize = info.bitsPerSample / 8;
+
176  out->write((uint8_t*)pcm_buffer, info.outputSamps*sampleSize);
+
177 #endif
+
178  }
+
179  aacFrameInfo = info;
+
180  }
+
181  }
+
182 };
+
183 }
A simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() call...
Definition: AACDecoderHelix.h:20
-
_AACFrameInfo audioInfo()
Provides the last available _AACFrameInfo_t.
Definition: AACDecoderHelix.h:61
-
size_t maxPCMSize() override
Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size...
Definition: AACDecoderHelix.h:69
-
virtual void end() override
Releases the reserved memory.
Definition: AACDecoderHelix.h:49
-
void decode(Range r) override
decods the data and removes the decoded frame from the buffer
Definition: AACDecoderHelix.h:93
-
size_t maxFrameSize() override
Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my m...
Definition: AACDecoderHelix.h:65
-
int findSynchWord(int offset=0) override
Finds the synchronization word in the frame buffer (starting from the indicated offset)
Definition: AACDecoderHelix.h:87
-
virtual void allocateDecoder() override
Allocate the decoder.
Definition: AACDecoderHelix.h:80
+
size_t decodeRaw(uint8_t *data, size_t len) override
Directly calls AACDecode.
Definition: AACDecoderHelix.h:148
+
_AACFrameInfo audioInfo()
Provides the last available _AACFrameInfo_t.
Definition: AACDecoderHelix.h:59
+
size_t maxPCMSize() override
Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size...
Definition: AACDecoderHelix.h:67
+
virtual void end() override
Releases the reserved memory.
Definition: AACDecoderHelix.h:47
+
void decode(Range r) override
decods the data and removes the decoded frame from the buffer
Definition: AACDecoderHelix.h:104
+
void setAudioInfo(int channels, int samplerate)
Used by M3A format.
Definition: AACDecoderHelix.h:72
+
size_t maxFrameSize() override
Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my m...
Definition: AACDecoderHelix.h:63
+
int findSynchWord(int offset=0) override
finds the sync word in the buffer
Definition: AACDecoderHelix.h:98
+
virtual void allocateDecoder() override
Allocate the decoder.
Definition: AACDecoderHelix.h:91
Common Simple Arduino API.
Definition: CommonHelix.h:49
-
void flush()
Decode open packets.
Definition: CommonHelix.h:161
-
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:103
-
Range with a start and an end.
Definition: CommonHelix.h:35
+
void flush()
Decode open packets.
Definition: CommonHelix.h:184
+
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:120
+
Range with a start and an end.
Definition: CommonHelix.h:34
diff --git a/docs/html/_common_helix_8h_source.html b/docs/html/_common_helix_8h_source.html index 987ae53..a64a6ea 100644 --- a/docs/html/_common_helix_8h_source.html +++ b/docs/html/_common_helix_8h_source.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: src/CommonHelix.h Source File @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
CommonHelix.h
+
+
CommonHelix.h
-
1#pragma once
-
2
-
3#ifdef ARDUINO
-
4#include "Arduino.h"
-
5#else
-
6// remove yield statment if used outside of arduino
-
7#define yield()
-
8//#define delay(ms)
-
9#include <stdint.h>
-
10#endif
-
11
-
12// Not all processors support assert
-
13#ifndef assert
-
14#ifdef NDEBUG
-
15# define assert(condition) ((void)0)
-
16#else
-
17# define assert(condition) /*implementation defined*/
-
18#endif
-
19#endif
-
20
-
21#include "helix_log.h"
-
22#include <string.h>
-
23
-
24#define SYNCH_WORD_LEN 4
-
25
-
26
-
27namespace libhelix {
-
28
-
35struct Range {
-
36 int start;
-
37 int end;
-
38 bool isValid(uint32_t max) {
-
39 return start>=0 && end>start && (end - start)<=max;
-
40 }
-
41};
-
42
- -
50 public:
-
51
-
52 virtual ~CommonHelix(){
-
53 if (active){
-
54 end();
-
55 }
-
56 if (pcm_buffer!=nullptr){
-
57 delete[] pcm_buffer;
-
58 }
-
59 if (frame_buffer!=nullptr){
-
60 delete[] frame_buffer;
-
61 }
-
62 }
-
63
-
64#ifdef ARDUINO
-
65 void setOutput(Print &output){
-
66 this->out = &output;
-
67 }
-
68#endif
-
69
-
74 virtual void begin(){
-
75 buffer_size = 0;
-
76 frame_counter = 0;
-
77
-
78 if (active){
-
79 end();
-
80 }
-
81
-
82 allocateDecoder();
-
83
-
84 if (frame_buffer == nullptr) {
-
85 LOG_HELIX(Info,"allocating frame_buffer with %zu bytes", maxFrameSize());
-
86 frame_buffer = new uint8_t[maxFrameSize()];
-
87 }
-
88 if (pcm_buffer == nullptr) {
-
89 LOG_HELIX(Info,"allocating pcm_buffer with %zu bytes", maxPCMSize());
-
90 pcm_buffer = new short[maxPCMSize()];
-
91 }
-
92 if (pcm_buffer==nullptr || frame_buffer==nullptr){
-
93 LOG_HELIX(Error, "Not enough memory for buffers");
-
94 active = false;
-
95 return;
-
96 }
-
97 memset(frame_buffer,0, maxFrameSize());
-
98 memset(pcm_buffer,0, maxPCMSize());
-
99 active = true;
-
100 }
-
101
-
103 virtual void end(){
-
104 active = false;
-
105 }
-
106
-
114 virtual size_t write(const void *in_ptr, size_t in_size) {
-
115 LOG_HELIX(Info, "write %zu", in_size);
-
116 time_last_write = millis();
-
117 size_t start = 0;
-
118 if (active){
-
119 uint8_t* ptr8 = (uint8_t* )in_ptr;
-
120 // we can not write more then the AAC_MAX_FRAME_SIZE
-
121 size_t write_len = min(in_size, static_cast<size_t>(maxFrameSize()-buffer_size));
-
122 while(start<in_size){
-
123 // we have some space left in the buffer
-
124 int written_len = writeFrame(ptr8+start, write_len);
-
125 start += written_len;
-
126 LOG_HELIX(Info,"-> Written %zu of %zu - Counter %zu", start, in_size, frame_counter);
-
127 write_len = min(in_size - start, static_cast<size_t>(maxFrameSize()-buffer_size));
-
128 // add delay - e.g. needed by esp32 and esp8266
-
129 if (delay_ms>0){
-
130 delay(delay_ms);
-
131 }
-
132 }
-
133 } else {
-
134 LOG_HELIX(Warning, "CommonHelix not active");
-
135 }
-
136
-
137 return start;
-
138 }
-
139
-
141 operator bool() {
-
142 return active;
-
143 }
-
144
-
146 virtual void setDelay(int delayMs){
-
147 delay_ms = delayMs;
-
148 }
-
149
-
151 uint64_t timeOfLastWrite() {
-
152 return time_last_write;
-
153 }
-
154
-
156 uint64_t timeOfLastResult() {
-
157 return time_last_result;
-
158 }
-
159
-
161 void flush() {
- -
163 // Decode if we have a valid start and end synch word
-
164 while(r.isValid(maxFrameSize())){
-
165 decode(r);
-
166 r = synchronizeFrame();
-
167 }
-
168 }
-
169
-
171 virtual size_t maxFrameSize() = 0;
-
172
-
174 void setMaxFrameSize(size_t len){
-
175 max_frame_size = len;
-
176 }
-
177
-
179 virtual size_t maxPCMSize() = 0 ;
-
180
-
182 void setMaxPCMSize(size_t len) {
-
183 max_pcm_size = len;
-
184 }
-
185
-
186 protected:
-
187 bool active = false;
-
188 uint32_t buffer_size = 0; // actually filled sized
-
189 uint8_t *frame_buffer = nullptr;
-
190 short *pcm_buffer = nullptr;
-
191 size_t max_frame_size = 0;
-
192 size_t max_pcm_size = 0;
-
193 size_t frame_counter = 0;
-
194 int delay_ms = -1;
-
195 uint64_t time_last_write=0;
-
196 uint64_t time_last_result=0;
-
197
-
198#ifdef ARDUINO
-
199 Print *out = nullptr;
-
200#endif
-
201
-
202 virtual void allocateDecoder() = 0;
-
203
-
204
-
206 virtual int findSynchWord(int offset=0) = 0;
-
207
-
209 virtual void decode(Range r) = 0;
-
210
-
212 size_t appendToBuffer(const void *in_ptr, int in_size){
-
213 LOG_HELIX(Info, "appendToBuffer: %d (at %p)", in_size, frame_buffer);
-
214 int buffer_size_old = buffer_size;
-
215 int process_size = min((int)(maxFrameSize() - buffer_size), in_size);
-
216 memmove(frame_buffer+buffer_size, in_ptr, process_size);
-
217 buffer_size += process_size;
-
218 if (buffer_size>maxFrameSize()){
-
219 LOG_HELIX(Error, "Increase MAX_FRAME_SIZE > %u", (unsigned int)buffer_size);
-
220 }
-
221 assert(buffer_size<=maxFrameSize());
-
222
-
223 LOG_HELIX(Debug, "appendToBuffer %d + %d -> %u", buffer_size_old, process_size, (unsigned int)buffer_size );
-
224 return process_size;
-
225 }
-
226
-
228 size_t writeFrame(const void *in_ptr, size_t in_size){
-
229 LOG_HELIX(Info, "writeFrame %zu", in_size);
-
230 size_t result = 0;
-
231 // in the beginning we ingnore all data until we found the first synch word
-
232 result = appendToBuffer(in_ptr, in_size);
- -
234 // Decode if we have a valid start and end synch word
-
235 if(r.isValid(maxFrameSize())){
-
236 decode(r);
-
237 } else {
-
238 int size = r.end-r.start;
-
239 if (size>0){
-
240 LOG_HELIX(Warning, " -> invalid frame size: %d / max: %d", (int) r.end-r.start, (int) maxFrameSize());
-
241 } else {
-
242 LOG_HELIX(Info, " -> invalid frame size: %d / max: %d", (int) r.end-r.start, (int) maxFrameSize());
-
243 }
-
244 }
-
245 frame_counter++;
-
246 return result;
-
247 }
-
248
- -
251 LOG_HELIX(Debug, "synchronizeFrame");
-
252 Range range = frameRange();
-
253 if (range.start<0){
-
254 // there is no Synch in the buffer at all -> we can ignore all data
-
255 range.end = -1;
-
256 LOG_HELIX(Debug, "-> no synch")
-
257 if (buffer_size==maxFrameSize()) {
-
258 buffer_size = 0;
-
259 LOG_HELIX(Debug, "-> buffer cleared");
-
260 }
-
261 } else if (range.start>0) {
-
262 // make sure that buffer starts with a synch word
-
263 LOG_HELIX(Debug, "-> moving to new start %d",range.start);
-
264 buffer_size -= range.start;
-
265 assert(buffer_size<=maxFrameSize());
-
266
-
267 memmove(frame_buffer, frame_buffer + range.start, buffer_size);
-
268 range.end -= range.start;
-
269 range.start = 0;
-
270 LOG_HELIX(Debug, "-> we are at beginning of synch word");
-
271 } else if (range.start==0) {
-
272 LOG_HELIX(Debug, "-> we are at beginning of synch word");
-
273 if (range.end<0 && buffer_size == maxFrameSize()){
-
274 buffer_size = 0;
-
275 LOG_HELIX(Debug, "-> buffer cleared");
-
276 }
-
277 }
-
278 return range;
-
279 }
-
280
- -
283 Range result;
-
284 result.start = findSynchWord(0);
-
285 result.end = findSynchWord(result.start+SYNCH_WORD_LEN);
-
286 LOG_HELIX(Debug, "-> frameRange -> %d - %d", result.start, result.end);
-
287 return result;
-
288 }
-
289
-
290 void advanceFrameBuffer(int offset){
-
291 buffer_size -= offset;
-
292 assert(buffer_size<=maxFrameSize());
-
293 memmove(frame_buffer, frame_buffer+offset, buffer_size);
-
294 }
-
295
-
296
-
297};
-
298
-
299}
+
1 #pragma once
+
2 
+
3 #if defined(ARDUINO)
+
4 # include "Arduino.h"
+
5 #else
+
6 // remove delay statment if used outside of arduino
+
7 # include <stdint.h>
+
8 # define delay(ms)
+
9 #endif
+
10 
+
11 // Not all processors support assert
+
12 #ifndef assert
+
13 # ifdef NDEBUG
+
14 # define assert(condition) ((void)0)
+
15 # else
+
16 # define assert(condition) /*implementation defined*/
+
17 # endif
+
18 #endif
+
19 
+
20 #include "helix_log.h"
+
21 #include <string.h>
+
22 
+
23 #define SYNCH_WORD_LEN 4
+
24 #define HELIX_PCM_CORRECTED
+
25 
+
26 namespace libhelix {
+
27 
+
34 struct Range {
+
35  int start = 0;
+
36  int end = 0;
+
37 
+
38  bool isValid(uint32_t max) {
+
39  return start>=0 && end>start && (end - start)<=max;
+
40  }
+
41 };
+
42 
+
49 class CommonHelix {
+
50  public:
+
51 
+
52  virtual ~CommonHelix(){
+
53  if (active){
+
54  end();
+
55  }
+
56  if (pcm_buffer!=nullptr){
+
57  delete[] pcm_buffer;
+
58  }
+
59  if (frame_buffer!=nullptr){
+
60  delete[] frame_buffer;
+
61  }
+
62  }
+
63 
+
64 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
65  void setOutput(Print &output){
+
66  this->out = &output;
+
67  }
+
68 #endif
+
69 
+
70 
+
75  void setRaw(bool flag){
+
76  is_raw = flag;
+
77  }
+
78 
+
83  virtual void begin(){
+
84  buffer_size = 0;
+
85  frame_counter = 0;
+
86 
+
87  if (active){
+
88  end();
+
89  }
+
90 
+ +
92 
+
93  if (!is_raw){
+
94  if (frame_buffer == nullptr) {
+
95  LOG_HELIX(Info,"allocating frame_buffer with %zu bytes", maxFrameSize());
+
96  frame_buffer = new uint8_t[maxFrameSize()];
+
97  }
+
98  memset(frame_buffer,0, maxFrameSize());
+
99  if (frame_buffer==nullptr){
+
100  LOG_HELIX(Error, "Not enough memory for buffers");
+
101  active = false;
+
102  return;
+
103  }
+
104  }
+
105 
+
106  if (pcm_buffer == nullptr) {
+
107  LOG_HELIX(Info,"allocating pcm_buffer with %zu bytes", maxPCMSize());
+
108  pcm_buffer = new short[maxPCMSize()];
+
109  }
+
110  if (pcm_buffer==nullptr ){
+
111  LOG_HELIX(Error, "Not enough memory for buffers");
+
112  active = false;
+
113  return;
+
114  }
+
115  memset(pcm_buffer,0, maxPCMSize());
+
116  active = true;
+
117  }
+
118 
+
120  virtual void end(){
+
121  active = false;
+
122  }
+
123 
+
131  virtual size_t write(const void *in_ptr, size_t in_size) {
+
132  LOG_HELIX(Info, "write %zu", in_size);
+
133  time_last_write = millis();
+
134  size_t start = 0;
+
135  uint8_t* ptr8 = (uint8_t* )in_ptr;
+
136  if (active){
+
137  if (!is_raw){
+
138  // regular decoding logic
+
139  // we can not write more then the AAC_MAX_FRAME_SIZE
+
140  size_t write_len = min(in_size, static_cast<size_t>(maxFrameSize()-buffer_size));
+
141  while(start<in_size){
+
142  // we have some space left in the buffer
+
143  int written_len = writeFrame(ptr8+start, write_len);
+
144  start += written_len;
+
145  LOG_HELIX(Info,"-> Written %zu of %zu - Counter %zu", start, in_size, frame_counter);
+
146  write_len = min(in_size - start, static_cast<size_t>(maxFrameSize()-buffer_size));
+
147  // add delay - e.g. needed by esp32 and esp8266
+
148  if (delay_ms>0){
+
149  delay(delay_ms);
+
150  }
+
151  }
+
152  } else {
+
153  // decode the submitted data directly
+
154  start = decodeRaw(ptr8, in_size);
+
155  }
+
156  } else {
+
157  LOG_HELIX(Warning, "CommonHelix not active");
+
158  }
+
159 
+
160  return start;
+
161  }
+
162 
+
164  operator bool() {
+
165  return active;
+
166  }
+
167 
+
169  virtual void setDelay(int delayMs){
+
170  delay_ms = delayMs;
+
171  }
+
172 
+
174  uint64_t timeOfLastWrite() {
+
175  return time_last_write;
+
176  }
+
177 
+
179  uint64_t timeOfLastResult() {
+
180  return time_last_result;
+
181  }
+
182 
+
184  void flush() {
+
185  Range r = synchronizeFrame();
+
186  // Decode if we have a valid start and end synch word
+
187  while(r.isValid(maxFrameSize())){
+
188  decode(r);
+
189  r = synchronizeFrame();
+
190  }
+
191  }
+
192 
+
194  virtual size_t maxFrameSize() = 0;
+
195 
+
197  void setMaxFrameSize(size_t len){
+
198  max_frame_size = len;
+
199  }
+
200 
+
202  virtual size_t maxPCMSize() = 0 ;
+
203 
+
205  void setMaxPCMSize(size_t len) {
+
206  max_pcm_size = len;
+
207  }
+
208 
+
209  protected:
+
210  bool active = false;
+
211  bool is_raw = false;
+
212  uint32_t buffer_size = 0; // actually filled sized
+
213  uint8_t *frame_buffer = nullptr;
+
214  short *pcm_buffer = nullptr;
+
215  size_t max_frame_size = 0;
+
216  size_t max_pcm_size = 0;
+
217  size_t frame_counter = 0;
+
218  int delay_ms = -1;
+
219  uint64_t time_last_write=0;
+
220  uint64_t time_last_result=0;
+
221 
+
222 
+
223 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
224  Print *out = nullptr;
+
225 #endif
+
226 
+
228  virtual size_t decodeRaw(uint8_t* data, size_t len) = 0;
+
229 
+
231  virtual void allocateDecoder() = 0;
+
232 
+
234  virtual int findSynchWord(int offset=0) = 0;
+
235 
+
237  virtual void decode(Range r) = 0;
+
238 
+
240  size_t appendToBuffer(const void *in_ptr, int in_size){
+
241  LOG_HELIX(Info, "appendToBuffer: %d (at %p)", in_size, frame_buffer);
+
242  int buffer_size_old = buffer_size;
+
243  int process_size = min((int)(maxFrameSize() - buffer_size), in_size);
+
244  memmove(frame_buffer+buffer_size, in_ptr, process_size);
+
245  buffer_size += process_size;
+
246  if (buffer_size>maxFrameSize()){
+
247  LOG_HELIX(Error, "Increase MAX_FRAME_SIZE > %u", (unsigned int)buffer_size);
+
248  }
+
249  assert(buffer_size<=maxFrameSize());
+
250 
+
251  LOG_HELIX(Debug, "appendToBuffer %d + %d -> %u", buffer_size_old, process_size, (unsigned int)buffer_size );
+
252  return process_size;
+
253  }
+
254 
+
256  size_t writeFrame(const void *in_ptr, size_t in_size){
+
257  LOG_HELIX(Info, "writeFrame %zu", in_size);
+
258  size_t result = 0;
+
259  // in the beginning we ingnore all data until we found the first synch word
+
260  result = appendToBuffer(in_ptr, in_size);
+
261  Range r = synchronizeFrame();
+
262  // Decode if we have a valid start and end synch word
+
263  if(r.isValid(maxFrameSize())){
+
264  decode(r);
+
265  } else {
+
266  int size = r.end-r.start;
+
267  if (size>0){
+
268  LOG_HELIX(Warning, " -> invalid frame size: %d / max: %d", (int) r.end-r.start, (int) maxFrameSize());
+
269  } else {
+
270  LOG_HELIX(Info, " -> invalid frame size: %d / max: %d", (int) r.end-r.start, (int) maxFrameSize());
+
271  }
+
272  }
+
273  frame_counter++;
+
274  return result;
+
275  }
+
276 
+ +
279  LOG_HELIX(Debug, "synchronizeFrame");
+
280  Range range = frameRange();
+
281  if (range.start<0){
+
282  // there is no Synch in the buffer at all -> we can ignore all data
+
283  range.end = -1;
+
284  LOG_HELIX(Debug, "-> no synch")
+
285  if (buffer_size==maxFrameSize()) {
+
286  buffer_size = 0;
+
287  LOG_HELIX(Debug, "-> buffer cleared");
+
288  }
+
289  } else if (range.start>0) {
+
290  // make sure that buffer starts with a synch word
+
291  LOG_HELIX(Debug, "-> moving to new start %d",range.start);
+
292  buffer_size -= range.start;
+
293  assert(buffer_size<=maxFrameSize());
+
294 
+
295  memmove(frame_buffer, frame_buffer + range.start, buffer_size);
+
296  range.end -= range.start;
+
297  range.start = 0;
+
298  LOG_HELIX(Debug, "-> we are at beginning of synch word");
+
299  } else if (range.start==0) {
+
300  LOG_HELIX(Debug, "-> we are at beginning of synch word");
+
301  if (range.end<0 && buffer_size == maxFrameSize()){
+
302  buffer_size = 0;
+
303  LOG_HELIX(Debug, "-> buffer cleared");
+
304  }
+
305  }
+
306  return range;
+
307  }
+
308 
+ +
311  Range result;
+
312  result.start = findSynchWord(0);
+
313  result.end = findSynchWord(result.start+SYNCH_WORD_LEN);
+
314  LOG_HELIX(Debug, "-> frameRange -> %d - %d", result.start, result.end);
+
315  return result;
+
316  }
+
317 
+
318  void advanceFrameBuffer(int offset){
+
319  buffer_size -= offset;
+
320  assert(buffer_size<=maxFrameSize());
+
321  memmove(frame_buffer, frame_buffer+offset, buffer_size);
+
322  }
+
323 
+
324 };
+
325 
+
326 }
Common Simple Arduino API.
Definition: CommonHelix.h:49
virtual size_t maxPCMSize()=0
Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size...
-
size_t appendToBuffer(const void *in_ptr, int in_size)
we add the data to the buffer until it is full
Definition: CommonHelix.h:212
-
size_t writeFrame(const void *in_ptr, size_t in_size)
appends the data to the frame buffer and decodes
Definition: CommonHelix.h:228
-
void setMaxFrameSize(size_t len)
Define your optimized maximum frame size.
Definition: CommonHelix.h:174
-
void flush()
Decode open packets.
Definition: CommonHelix.h:161
-
Range synchronizeFrame()
returns valid start and end synch word.
Definition: CommonHelix.h:250
+
size_t appendToBuffer(const void *in_ptr, int in_size)
we add the data to the buffer until it is full
Definition: CommonHelix.h:240
+
size_t writeFrame(const void *in_ptr, size_t in_size)
appends the data to the frame buffer and decodes
Definition: CommonHelix.h:256
+
void setMaxFrameSize(size_t len)
Define your optimized maximum frame size.
Definition: CommonHelix.h:197
+
void flush()
Decode open packets.
Definition: CommonHelix.h:184
+
Range synchronizeFrame()
returns valid start and end synch word.
Definition: CommonHelix.h:278
virtual void decode(Range r)=0
Decodes a frame.
-
Range frameRange()
determines the next start and end synch word in the buffer
Definition: CommonHelix.h:282
+
Range frameRange()
determines the next start and end synch word in the buffer
Definition: CommonHelix.h:310
virtual int findSynchWord(int offset=0)=0
Finds the synchronization word in the frame buffer (starting from the indicated offset)
virtual size_t maxFrameSize()=0
Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my m...
-
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:103
-
virtual void begin()
Starts the processing.
Definition: CommonHelix.h:74
-
virtual size_t write(const void *in_ptr, size_t in_size)
decodes the next segments from the intput. The data can be provided in one short or in small incremen...
Definition: CommonHelix.h:114
-
uint64_t timeOfLastWrite()
Provides the timestamp in ms of last write.
Definition: CommonHelix.h:151
-
uint64_t timeOfLastResult()
Provides the timestamp in ms of last decoded result.
Definition: CommonHelix.h:156
-
virtual void setDelay(int delayMs)
Defines the delay that is added at each segment.
Definition: CommonHelix.h:146
-
void setMaxPCMSize(size_t len)
Define your optimized maximum pcm buffer size.
Definition: CommonHelix.h:182
-
Range with a start and an end.
Definition: CommonHelix.h:35
+
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:120
+
virtual void begin()
Starts the processing.
Definition: CommonHelix.h:83
+
virtual void allocateDecoder()=0
Allocate the decoder.
+
virtual size_t write(const void *in_ptr, size_t in_size)
decodes the next segments from the intput. The data can be provided in one short or in small incremen...
Definition: CommonHelix.h:131
+
uint64_t timeOfLastWrite()
Provides the timestamp in ms of last write.
Definition: CommonHelix.h:174
+
virtual size_t decodeRaw(uint8_t *data, size_t len)=0
Decode w/o parsing.
+
void setRaw(bool flag)
With setRaw(true) you deactivate the parsing of the frames and submit the data directly to the decode...
Definition: CommonHelix.h:75
+
uint64_t timeOfLastResult()
Provides the timestamp in ms of last decoded result.
Definition: CommonHelix.h:179
+
virtual void setDelay(int delayMs)
Defines the delay that is added at each segment.
Definition: CommonHelix.h:169
+
void setMaxPCMSize(size_t len)
Define your optimized maximum pcm buffer size.
Definition: CommonHelix.h:205
+
Range with a start and an end.
Definition: CommonHelix.h:34
diff --git a/docs/html/_m_p3_decoder_helix_8h_source.html b/docs/html/_m_p3_decoder_helix_8h_source.html index 1692184..f53bf63 100644 --- a/docs/html/_m_p3_decoder_helix_8h_source.html +++ b/docs/html/_m_p3_decoder_helix_8h_source.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: src/MP3DecoderHelix.h Source File @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
MP3DecoderHelix.h
+
+
MP3DecoderHelix.h
-
1#pragma once
-
2
-
3#include "CommonHelix.h"
-
4#include "libhelix-mp3/mp3dec.h"
-
5#include "libhelix-mp3/mp3common.h"
-
6
-
7#define MP3_MAX_OUTPUT_SIZE 1024 * 5
-
8#define MP3_MAX_FRAME_SIZE 1600
-
9
-
10namespace libhelix {
-
11
-
12
-
13typedef void (*MP3InfoCallback)(MP3FrameInfo &info);
-
14typedef void (*MP3DataCallback)(MP3FrameInfo &info,short *pcm_buffer, size_t len);
-
15
-
16enum MP3Type {MP3Normal=0, MP3SelfContaind=1};
-
17
-
18
- -
26
-
27 public:
- -
29 this->mp3_type = MP3Normal;
-
30 }
-
31
-
32#ifdef ARDUINO
-
33 MP3DecoderHelix(Print &output, MP3Type mp3Type=MP3Normal, MP3InfoCallback infoCallback=nullptr){
-
34 this->out = &output;
-
35 this->infoCallback = infoCallback;
-
36 this->mp3_type = mp3Type;
-
37 }
-
38#endif
-
39 MP3DecoderHelix(MP3DataCallback dataCallback, MP3Type mp3Type=MP3Normal){
-
40 this->pcmCallback = dataCallback;
-
41 this->mp3_type = mp3Type;
-
42 }
-
43
-
44 MP3DecoderHelix(MP3Type mp3Type){
-
45 this->mp3_type = mp3Type;
-
46 }
-
47
-
48 virtual ~MP3DecoderHelix(){
-
49 end();
-
50 }
-
51
-
52 void setInfoCallback(MP3InfoCallback cb){
-
53 this->infoCallback = cb;
-
54 }
-
55
-
56 void setDataCallback(MP3DataCallback cb){
-
57 this->pcmCallback = cb;
-
58 }
-
59
-
61 MP3FrameInfo audioInfo(){
-
62 return mp3FrameInfo;
-
63 }
-
64
-
66 virtual void end() override {
-
67 LOG_HELIX(Debug, "end");
-
68 flush();
-
69
-
70 if (decoder!=nullptr){
-
71 MP3FreeDecoder(decoder);
-
72 decoder = nullptr;
-
73 }
- -
75 memset(&mp3FrameInfo,0,sizeof(MP3FrameInfo));
-
76 }
-
77
-
79 size_t maxFrameSize() override {
-
80 return max_frame_size == 0 ? MP3_MAX_FRAME_SIZE : max_frame_size;
-
81 }
-
82
-
84 size_t maxPCMSize() override {
-
85 return max_pcm_size == 0 ? MP3_MAX_OUTPUT_SIZE : max_pcm_size;
-
86 }
-
87
-
88 protected:
-
89 HMP3Decoder decoder = nullptr;
-
90 MP3DataCallback pcmCallback = nullptr;
-
91 MP3InfoCallback infoCallback = nullptr;
-
92 MP3Type mp3_type;
-
93 MP3FrameInfo mp3FrameInfo;
-
94
-
96 virtual void allocateDecoder() override {
-
97 if (decoder==nullptr){
-
98 decoder = MP3InitDecoder();
-
99 }
-
100 }
-
101
-
102
-
104 int findSynchWord(int offset=0) override {
-
105 int result = MP3FindSyncWord(frame_buffer+offset, buffer_size);
-
106 return result < 0 ? result : result + offset;
-
107 }
-
108
-
110 void decode(Range r) override {
-
111 LOG_HELIX(Debug, "decode %d", r.end);
-
112 int len = buffer_size - r.start;
-
113 int bytesLeft = len;
-
114 uint8_t* ptr = frame_buffer + r.start;
-
115
-
116 int result = MP3Decode(decoder, &ptr, &bytesLeft, pcm_buffer, mp3_type);
-
117 int decoded = len - bytesLeft;
-
118
-
119 if (result==0){
-
120 LOG_HELIX(Debug, "-> bytesLeft %d -> %d = %d ", buffer_size, bytesLeft, decoded);
-
121 LOG_HELIX(Debug, "-> End of frame (%d) vs end of decoding (%d)", r.end, decoded)
-
122
-
123 // return the decoded result
-
124 MP3FrameInfo info;
-
125 MP3GetLastFrameInfo(decoder, &info);
-
126 provideResult(info);
-
127
-
128 // remove processed data from buffer
-
129 if (decoded<=buffer_size) {
-
130 buffer_size -= decoded;
-
131 //assert(buffer_size<=maxFrameSize());
-
132 memmove(frame_buffer, frame_buffer+r.start+decoded, buffer_size);
-
133 LOG_HELIX(Debug, " -> decoded %d bytes - remaining buffer_size: %d", decoded, buffer_size);
-
134 } else {
-
135 LOG_HELIX(Warning, " -> decoded %d > buffersize %d", decoded, buffer_size);
-
136 buffer_size = 0;
-
137 }
-
138 } else {
-
139 // decoding error
-
140 LOG_HELIX(Debug, " -> decode error: %d - removing frame!", result);
-
141 int ignore = decoded;
-
142 if (ignore == 0) ignore = r.end;
-
143 // We advance to the next synch world
-
144 if (ignore<=buffer_size){
-
145 buffer_size -= ignore;
-
146 memmove(frame_buffer, frame_buffer+ignore, buffer_size);
-
147 } else {
-
148 buffer_size = 0;
-
149 }
-
150
-
151 }
-
152 }
-
153
-
154 // return the resulting PCM data
-
155 void provideResult(MP3FrameInfo &info){
-
156 // increase PCM size if this fails
-
157 assert(info.outputSamps<maxPCMSize());
-
158
-
159 LOG_HELIX(Debug, "=> provideResult: %d", info.outputSamps);
-
160 if (info.outputSamps>0){
-
161 // provide result
-
162 if(pcmCallback!=nullptr){
-
163 // output via callback
-
164 pcmCallback(info, pcm_buffer, info.outputSamps);
-
165 } else {
-
166 // output to stream
-
167 if (info.samprate!=mp3FrameInfo.samprate && infoCallback!=nullptr){
-
168 infoCallback(info);
-
169 }
-
170#ifdef ARDUINO
-
171 int sampleSize = info.bitsPerSample / 8;
-
172 out->write((uint8_t*)pcm_buffer, info.outputSamps*sampleSize);
-
173#endif
-
174 }
-
175 mp3FrameInfo = info;
-
176 }
-
177 }
-
178
-
179};
-
180
-
181}
+
1 #pragma once
+
2 
+
3 #include "CommonHelix.h"
+
4 #include "libhelix-mp3/mp3dec.h"
+
5 #include "libhelix-mp3/mp3common.h"
+
6 
+
7 #define MP3_MAX_OUTPUT_SIZE 1024 * 5
+
8 #define MP3_MAX_FRAME_SIZE 1600
+
9 
+
10 namespace libhelix {
+
11 
+
12 
+
13 typedef void (*MP3InfoCallback)(MP3FrameInfo &info, void* caller);
+
14 typedef void (*MP3DataCallback)(MP3FrameInfo &info,short *pcm_buffer, size_t len, void* caller);
+
15 
+
16 enum MP3Type {MP3Normal=0, MP3SelfContaind=1};
+
17 
+
18 
+
25 class MP3DecoderHelix : public CommonHelix {
+
26 
+
27  public:
+ +
29  this->mp3_type = MP3Normal;
+
30  }
+
31 
+
32 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
33  MP3DecoderHelix(Print &output, MP3Type mp3Type=MP3Normal){
+
34  this->out = &output;
+
35  this->mp3_type = mp3Type;
+
36  }
+
37 #endif
+
38  MP3DecoderHelix(MP3DataCallback dataCallback, MP3Type mp3Type=MP3Normal){
+
39  this->pcmCallback = dataCallback;
+
40  this->mp3_type = mp3Type;
+
41  }
+
42 
+
43  MP3DecoderHelix(MP3Type mp3Type){
+
44  this->mp3_type = mp3Type;
+
45  }
+
46 
+
47  virtual ~MP3DecoderHelix(){
+
48  end();
+
49  }
+
50 
+
51  void setInfoCallback(MP3InfoCallback cb, void* caller=nullptr){
+
52  this->infoCallback = cb;
+
53  p_caller_info = caller;
+
54  }
+
55 
+
56  void setDataCallback(MP3DataCallback cb){
+
57  this->pcmCallback = cb;
+
58  }
+
59 
+
61  MP3FrameInfo audioInfo(){
+
62  return mp3FrameInfo;
+
63  }
+
64 
+
66  virtual void end() override {
+
67  LOG_HELIX(Debug, "end");
+
68  flush();
+
69 
+
70  if (decoder!=nullptr){
+
71  MP3FreeDecoder(decoder);
+
72  decoder = nullptr;
+
73  }
+ +
75  memset(&mp3FrameInfo,0,sizeof(MP3FrameInfo));
+
76  }
+
77 
+
79  size_t maxFrameSize() override {
+
80  return max_frame_size == 0 ? MP3_MAX_FRAME_SIZE : max_frame_size;
+
81  }
+
82 
+
84  size_t maxPCMSize() override {
+
85  return max_pcm_size == 0 ? MP3_MAX_OUTPUT_SIZE : max_pcm_size;
+
86  }
+
87 
+
88  protected:
+
89  HMP3Decoder decoder = nullptr;
+
90  MP3DataCallback pcmCallback = nullptr;
+
91  MP3InfoCallback infoCallback = nullptr;
+
92  MP3Type mp3_type;
+
93  MP3FrameInfo mp3FrameInfo;
+
94  void *p_caller_info = nullptr;
+
95  void *p_caller_data = nullptr;
+
96 
+
98  virtual void allocateDecoder() override {
+
99  if (decoder==nullptr){
+
100  decoder = MP3InitDecoder();
+
101  }
+
102  }
+
103 
+
104 
+
106  int findSynchWord(int offset=0) override {
+
107  int result = MP3FindSyncWord(frame_buffer+offset, buffer_size);
+
108  return result < 0 ? result : result + offset;
+
109  }
+
110 
+
112  void decode(Range r) override {
+
113  LOG_HELIX(Debug, "decode %d", r.end);
+
114  int len = buffer_size - r.start;
+
115  int bytesLeft = len;
+
116  uint8_t* ptr = frame_buffer + r.start;
+
117 
+
118  int result = MP3Decode(decoder, &ptr, &bytesLeft, pcm_buffer, mp3_type);
+
119  int decoded = len - bytesLeft;
+
120 
+
121  if (result==0){
+
122  LOG_HELIX(Debug, "-> bytesLeft %d -> %d = %d ", buffer_size, bytesLeft, decoded);
+
123  LOG_HELIX(Debug, "-> End of frame (%d) vs end of decoding (%d)", r.end, decoded)
+
124 
+
125  // return the decoded result
+
126  MP3FrameInfo info;
+
127  MP3GetLastFrameInfo(decoder, &info);
+
128  provideResult(info);
+
129 
+
130  // remove processed data from buffer
+
131  if (decoded<=buffer_size) {
+
132  buffer_size -= decoded;
+
133  //assert(buffer_size<=maxFrameSize());
+
134  memmove(frame_buffer, frame_buffer+r.start+decoded, buffer_size);
+
135  LOG_HELIX(Debug, " -> decoded %d bytes - remaining buffer_size: %d", decoded, buffer_size);
+
136  } else {
+
137  LOG_HELIX(Warning, " -> decoded %d > buffersize %d", decoded, buffer_size);
+
138  buffer_size = 0;
+
139  }
+
140  } else {
+
141  // decoding error
+
142  LOG_HELIX(Debug, " -> decode error: %d - removing frame!", result);
+
143  int ignore = decoded;
+
144  if (ignore == 0) ignore = r.end;
+
145  // We advance to the next synch world
+
146  if (ignore<=buffer_size){
+
147  buffer_size -= ignore;
+
148  memmove(frame_buffer, frame_buffer+ignore, buffer_size);
+
149  } else {
+
150  buffer_size = 0;
+
151  }
+
152 
+
153  }
+
154  }
+
155 
+
157  size_t decodeRaw(uint8_t* data, size_t len) {
+
158  return 0;
+
159  }
+
160 
+
161 
+
162  // return the resulting PCM data
+
163  void provideResult(MP3FrameInfo &info){
+
164  // increase PCM size if this fails
+
165  assert(info.outputSamps<maxPCMSize());
+
166 
+
167  LOG_HELIX(Debug, "=> provideResult: %d", info.outputSamps);
+
168  if (info.outputSamps>0){
+
169  // provide result
+
170  if(pcmCallback!=nullptr){
+
171  // output via callback
+
172  pcmCallback(info, pcm_buffer, info.outputSamps, p_caller_data);
+
173  } else {
+
174  // output to stream
+
175  if (info.samprate!=mp3FrameInfo.samprate && infoCallback!=nullptr){
+
176  infoCallback(info, p_caller_info);
+
177  }
+
178 #if defined(ARDUINO) || defined(HELIX_PRINT)
+
179  int sampleSize = info.bitsPerSample / 8;
+
180  out->write((uint8_t*)pcm_buffer, info.outputSamps*sampleSize);
+
181 #endif
+
182  }
+
183  mp3FrameInfo = info;
+
184  }
+
185  }
+
186 
+
187 };
+
188 
+
189 }
Common Simple Arduino API.
Definition: CommonHelix.h:49
-
void flush()
Decode open packets.
Definition: CommonHelix.h:161
-
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:103
+
void flush()
Decode open packets.
Definition: CommonHelix.h:184
+
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:120
A simple Arduino API for the libhelix MP3 decoder. The data is provided with the help of write() call...
Definition: MP3DecoderHelix.h:25
-
int findSynchWord(int offset=0) override
Finds the synch word in the available buffer data starting from the indicated offset.
Definition: MP3DecoderHelix.h:104
+
size_t decodeRaw(uint8_t *data, size_t len)
Not supported.
Definition: MP3DecoderHelix.h:157
+
int findSynchWord(int offset=0) override
Finds the synch word in the available buffer data starting from the indicated offset.
Definition: MP3DecoderHelix.h:106
size_t maxFrameSize() override
determines the frame buffer size that will be allocated
Definition: MP3DecoderHelix.h:79
MP3FrameInfo audioInfo()
Provides the last available MP3FrameInfo.
Definition: MP3DecoderHelix.h:61
-
void decode(Range r) override
decods the data
Definition: MP3DecoderHelix.h:110
+
void decode(Range r) override
decods the data
Definition: MP3DecoderHelix.h:112
virtual void end() override
Releases the reserved memory.
Definition: MP3DecoderHelix.h:66
size_t maxPCMSize() override
Determines the pcm buffer size that will be allocated.
Definition: MP3DecoderHelix.h:84
-
virtual void allocateDecoder() override
Allocate the decoder.
Definition: MP3DecoderHelix.h:96
-
Range with a start and an end.
Definition: CommonHelix.h:35
+
virtual void allocateDecoder() override
Allocate the decoder.
Definition: MP3DecoderHelix.h:98
+
Range with a start and an end.
Definition: CommonHelix.h:34
diff --git a/docs/html/annotated.html b/docs/html/annotated.html index 7295a08..65ce1ff 100644 --- a/docs/html/annotated.html +++ b/docs/html/annotated.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: Class List @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
@@ -56,35 +55,29 @@
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
Class List
+
+
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
[detail level 12]
- - - - + + + +
 Nlibhelix
 CAACDecoderHelixA simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() calls. The decoded result is available either via a callback method or via an output stream
 CCommonHelixCommon Simple Arduino API
 CMP3DecoderHelixA simple Arduino API for the libhelix MP3 decoder. The data is provided with the help of write() calls. The decoded result is available either via a callback method or via an output stream
 CRangeRange with a start and an end
 CAACDecoderHelixA simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() calls. The decoded result is available either via a callback method or via an output stream
 CRangeRange with a start and an end
 CCommonHelixCommon Simple Arduino API
 CMP3DecoderHelixA simple Arduino API for the libhelix MP3 decoder. The data is provided with the help of write() calls. The decoded result is available either via a callback method or via an output stream
diff --git a/docs/html/classes.html b/docs/html/classes.html index 932dfeb..3622c80 100644 --- a/docs/html/classes.html +++ b/docs/html/classes.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: Class Index @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
@@ -56,41 +55,35 @@
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
Class Index
+
+
Class Index
A | C | M | R
-
A
+
A
AACDecoderHelix (libhelix)
-
C
+
C
CommonHelix (libhelix)
-
M
+
M
MP3DecoderHelix (libhelix)
-
R
+
R
Range (libhelix)
diff --git a/docs/html/classlibhelix_1_1_a_a_c_decoder_helix-members.html b/docs/html/classlibhelix_1_1_a_a_c_decoder_helix-members.html index af4b9cf..811f8ba 100644 --- a/docs/html/classlibhelix_1_1_a_a_c_decoder_helix-members.html +++ b/docs/html/classlibhelix_1_1_a_a_c_decoder_helix-members.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: Member List @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
libhelix::AACDecoderHelix Member List
+
+
libhelix::AACDecoderHelix Member List

This is the complete list of members for libhelix::AACDecoderHelix, including all inherited members.

- + - + - + - + - + - + - - - - - - - - - + + + + + + + + + + + - + - + - + + + - - - - - - - + + + + + + + + + - + - + - + - +
AACDecoderHelix()=default (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelix
AACDecoderHelix(Print &output, AACInfoCallback infoCallback=nullptr) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
AACDecoderHelix(Print &output) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
AACDecoderHelix(AACDataCallback dataCallback) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
aacFrameInfo (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
aacFrameInfo (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
active (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
advanceFrameBuffer(int offset) (defined in libhelix::CommonHelix)libhelix::CommonHelixinlineprotected
advanceFrameBuffer(int offset) (defined in libhelix::CommonHelix)libhelix::CommonHelixinlineprotected
allocateDecoder() overridelibhelix::AACDecoderHelixinlineprotectedvirtual
appendToBuffer(const void *in_ptr, int in_size)libhelix::CommonHelixinlineprotected
appendToBuffer(const void *in_ptr, int in_size)libhelix::CommonHelixinlineprotected
audioInfo()libhelix::AACDecoderHelixinline
begin()libhelix::CommonHelixinlinevirtual
begin()libhelix::CommonHelixinlinevirtual
buffer_size (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
decode(Range r) overridelibhelix::AACDecoderHelixinlineprotectedvirtual
decode(Range r) overridelibhelix::AACDecoderHelixinlineprotectedvirtual
decoder (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
delay_ms (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
end() overridelibhelix::AACDecoderHelixinlinevirtual
findSynchWord(int offset=0) overridelibhelix::AACDecoderHelixinlineprotectedvirtual
flush()libhelix::CommonHelixinline
frame_buffer (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
frame_counter (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
frameRange()libhelix::CommonHelixinlineprotected
infoCallback (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
max_frame_size (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
decodeRaw(uint8_t *data, size_t len) overridelibhelix::AACDecoderHelixinlineprotectedvirtual
delay_ms (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
end() overridelibhelix::AACDecoderHelixinlinevirtual
findSynchWord(int offset=0) overridelibhelix::AACDecoderHelixinlineprotectedvirtual
flush()libhelix::CommonHelixinline
frame_buffer (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
frame_counter (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
frameRange()libhelix::CommonHelixinlineprotected
infoCallback (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
is_raw (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
max_frame_size (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
max_pcm_size (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
maxFrameSize() overridelibhelix::AACDecoderHelixinlinevirtual
maxFrameSize() overridelibhelix::AACDecoderHelixinlinevirtual
maxPCMSize() overridelibhelix::AACDecoderHelixinlinevirtual
operator bool()libhelix::CommonHelixinline
operator bool()libhelix::CommonHelixinline
out (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
pcm_buffer (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
p_caller_data (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
p_caller_info (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
pcm_buffer (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
pcmCallback (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixprotected
provideResult(_AACFrameInfo &info) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinlineprotected
setDataCallback(AACDataCallback cb) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
setDelay(int delayMs)libhelix::CommonHelixinlinevirtual
setInfoCallback(AACInfoCallback cb) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
setMaxFrameSize(size_t len)libhelix::CommonHelixinline
setMaxPCMSize(size_t len)libhelix::CommonHelixinline
setOutput(Print &output) (defined in libhelix::CommonHelix)libhelix::CommonHelixinline
provideResult(_AACFrameInfo &info) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinlineprotected
setAudioInfo(int channels, int samplerate)libhelix::AACDecoderHelixinline
setDataCallback(AACDataCallback cb) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
setDelay(int delayMs)libhelix::CommonHelixinlinevirtual
setInfoCallback(AACInfoCallback cb, void *caller=nullptr) (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinline
setMaxFrameSize(size_t len)libhelix::CommonHelixinline
setMaxPCMSize(size_t len)libhelix::CommonHelixinline
setOutput(Print &output) (defined in libhelix::CommonHelix)libhelix::CommonHelixinline
setRaw(bool flag)libhelix::CommonHelixinline
synchronizeFrame()libhelix::CommonHelixinlineprotected
time_last_result (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
time_last_result (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
time_last_write (defined in libhelix::CommonHelix)libhelix::CommonHelixprotected
timeOfLastResult()libhelix::CommonHelixinline
timeOfLastResult()libhelix::CommonHelixinline
timeOfLastWrite()libhelix::CommonHelixinline
write(const void *in_ptr, size_t in_size)libhelix::CommonHelixinlinevirtual
write(const void *in_ptr, size_t in_size)libhelix::CommonHelixinlinevirtual
writeFrame(const void *in_ptr, size_t in_size)libhelix::CommonHelixinlineprotected
~AACDecoderHelix() (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinlinevirtual
~AACDecoderHelix() (defined in libhelix::AACDecoderHelix)libhelix::AACDecoderHelixinlinevirtual
~CommonHelix() (defined in libhelix::CommonHelix)libhelix::CommonHelixinlinevirtual
diff --git a/docs/html/classlibhelix_1_1_a_a_c_decoder_helix.html b/docs/html/classlibhelix_1_1_a_a_c_decoder_helix.html index 01d9d0a..0ca452f 100644 --- a/docs/html/classlibhelix_1_1_a_a_c_decoder_helix.html +++ b/docs/html/classlibhelix_1_1_a_a_c_decoder_helix.html @@ -1,9 +1,9 @@ - + - - + + Arduino LibHelix: libhelix::AACDecoderHelix Class Reference @@ -19,8 +19,8 @@
- - + @@ -29,22 +29,21 @@
+
Arduino LibHelix
- + +/* @license-end */
-
-
-
-
-
Loading...
-
Searching...
-
No Matches
-
-
-
+
-
libhelix::AACDecoderHelix Class Reference
+
+
libhelix::AACDecoderHelix Class Reference
@@ -96,362 +89,193 @@
- - - - + + - - - + + - - + + - + - - + + - - + + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+

Public Member Functions

AACDecoderHelix (Print &output, AACInfoCallback infoCallback=nullptr)
 
+
AACDecoderHelix (Print &output)
 
 AACDecoderHelix (AACDataCallback dataCallback)
 
-void setInfoCallback (AACInfoCallback cb)
 
+
+void setInfoCallback (AACInfoCallback cb, void *caller=nullptr)
 
void setDataCallback (AACDataCallback cb)
 
virtual void end () override
 Releases the reserved memory.
+virtual void end () override
 Releases the reserved memory.
 
-_AACFrameInfo audioInfo ()
+_AACFrameInfo audioInfo ()
 Provides the last available _AACFrameInfo_t.
 
size_t maxFrameSize () override
 Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
+size_t maxFrameSize () override
 Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
 
size_t maxPCMSize () override
 Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
+size_t maxPCMSize () override
 Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
 
- Public Member Functions inherited from libhelix::CommonHelix
+
+void setAudioInfo (int channels, int samplerate)
 Used by M3A format.
 
void setOutput (Print &output)
 
virtual void begin ()
 Starts the processing.
 
virtual void end ()
 Releases the reserved memory.
 
-virtual size_t write (const void *in_ptr, size_t in_size)
 decodes the next segments from the intput. The data can be provided in one short or in small incremental pieces. It is suggested to be called in the Arduino Loop. If the provided data does not fit into the buffer it is split up into small pieces that fit
 
operator bool ()
 returns true if active
 
-virtual void setDelay (int delayMs)
 Defines the delay that is added at each segment.
 
-uint64_t timeOfLastWrite ()
 Provides the timestamp in ms of last write.
 
-uint64_t timeOfLastResult ()
 Provides the timestamp in ms of last decoded result.
 
-void flush ()
 Decode open packets.
 
virtual size_t maxFrameSize ()=0
 Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
 
-void setMaxFrameSize (size_t len)
 Define your optimized maximum frame size.
 
virtual size_t maxPCMSize ()=0
 Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size my minimizing this value.
 
-void setMaxPCMSize (size_t len)
 Define your optimized maximum pcm buffer size.
 
 
+void setRaw (bool flag)
 With setRaw(true) you deactivate the parsing of the frames and submit the data directly to the decoder,.
 
+virtual void begin ()
 Starts the processing.
 
+virtual size_t write (const void *in_ptr, size_t in_size)
 decodes the next segments from the intput. The data can be provided in one short or in small incremental pieces. It is suggested to be called in the Arduino Loop. If the provided data does not fit into the buffer it is split up into small pieces that fit
 
operator bool ()
 returns true if active
 
+virtual void setDelay (int delayMs)
 Defines the delay that is added at each segment.
 
+uint64_t timeOfLastWrite ()
 Provides the timestamp in ms of last write.
 
+uint64_t timeOfLastResult ()
 Provides the timestamp in ms of last decoded result.
 
+void flush ()
 Decode open packets.
 
+void setMaxFrameSize (size_t len)
 Define your optimized maximum frame size.
 
+void setMaxPCMSize (size_t len)
 Define your optimized maximum pcm buffer size.
 
- - - + + - - + + - - + + - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - +

+

Protected Member Functions

virtual void allocateDecoder () override
 Allocate the decoder.
+virtual void allocateDecoder () override
 Allocate the decoder.
 
int findSynchWord (int offset=0) override
 Finds the synchronization word in the frame buffer (starting from the indicated offset)
+int findSynchWord (int offset=0) override
 finds the sync word in the buffer
 
void decode (Range r) override
 decods the data and removes the decoded frame from the buffer
+void decode (Range r) override
 decods the data and removes the decoded frame from the buffer
 
+
+size_t decodeRaw (uint8_t *data, size_t len) override
 Directly calls AACDecode.
 
void provideResult (_AACFrameInfo &info)
 
- Protected Member Functions inherited from libhelix::CommonHelix
virtual void allocateDecoder ()=0
 
virtual int findSynchWord (int offset=0)=0
 Finds the synchronization word in the frame buffer (starting from the indicated offset)
 
virtual void decode (Range r)=0
 Decodes a frame.
 
-size_t appendToBuffer (const void *in_ptr, int in_size)
 we add the data to the buffer until it is full
 
-size_t writeFrame (const void *in_ptr, size_t in_size)
 appends the data to the frame buffer and decodes
 
-Range synchronizeFrame ()
 returns valid start and end synch word.
 
-Range frameRange ()
 determines the next start and end synch word in the buffer
 
+
+size_t appendToBuffer (const void *in_ptr, int in_size)
 we add the data to the buffer until it is full
 
+size_t writeFrame (const void *in_ptr, size_t in_size)
 appends the data to the frame buffer and decodes
 
+Range synchronizeFrame ()
 returns valid start and end synch word.
 
+Range frameRange ()
 determines the next start and end synch word in the buffer
 
void advanceFrameBuffer (int offset)
 
 
- - - - - - - + + + + - - + + + - - + - - + - - + - - + - - + - - + - - + - - + - - + - +

+

Protected Attributes

+
HAACDecoder decoder = nullptr
 
+
AACDataCallback pcmCallback = nullptr
 
+
AACInfoCallback infoCallback = nullptr
 
+
_AACFrameInfo aacFrameInfo
 
- Protected Attributes inherited from libhelix::CommonHelix
+
+void * p_caller_info = nullptr
 
+void * p_caller_data = nullptr
 
bool active = false
 
+
 
+bool is_raw = false
 
uint32_t buffer_size = 0
 
+
 
uint8_t * frame_buffer = nullptr
 
+
 
short * pcm_buffer = nullptr
 
+
 
size_t max_frame_size = 0
 
+
 
size_t max_pcm_size = 0
 
+
 
size_t frame_counter = 0
 
+
 
int delay_ms = -1
 
+
 
uint64_t time_last_write =0
 
+
 
uint64_t time_last_result =0
 
+
 
Print * out = nullptr
 
 

Detailed Description

A simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() calls. The decoded result is available either via a callback method or via an output stream.

Author
Phil Schatzmann
-

Member Function Documentation

- -

◆ allocateDecoder()

- -
-
- - - - - -
- - - - - - - -
virtual void libhelix::AACDecoderHelix::allocateDecoder ()
-
-inlineoverrideprotectedvirtual
-
- -

Allocate the decoder.

- -

Implements libhelix::CommonHelix.

- -
-
- -

◆ decode()

- -
-
- - - - - -
- - - - - - - - -
void libhelix::AACDecoderHelix::decode (Range r)
-
-inlineoverrideprotectedvirtual
-
- -

decods the data and removes the decoded frame from the buffer

- -

Implements libhelix::CommonHelix.

- -
-
- -

◆ end()

- -
-
- - - - - -
- - - - - - - -
virtual void libhelix::AACDecoderHelix::end ()
-
-inlineoverridevirtual
-
- -

Releases the reserved memory.

- -

Reimplemented from libhelix::CommonHelix.

- -
-
- -

◆ findSynchWord()

- -
-
- - - - - -
- - - - - - - - -
int libhelix::AACDecoderHelix::findSynchWord (int offset = 0)
-
-inlineoverrideprotectedvirtual
-
- -

Finds the synchronization word in the frame buffer (starting from the indicated offset)

- -

Implements libhelix::CommonHelix.

- -
-
- -

◆ maxFrameSize()

- -
-
- - - - - -
- - - - - - - -
size_t libhelix::AACDecoderHelix::maxFrameSize ()
-
-inlineoverridevirtual
-
- -

Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value.

- -

Implements libhelix::CommonHelix.

- -
-
- -

◆ maxPCMSize()

- -
-
- - - - - -
- - - - - - - -
size_t libhelix::AACDecoderHelix::maxPCMSize ()
-
-inlineoverridevirtual
-
- -

Provides the maximum pcm buffer size - this is allocated on the heap and you can reduce the heap size my minimizing this value.

- -

Implements libhelix::CommonHelix.

- -
-
-
The documentation for this class was generated from the following file: