Skip to content

Commit 9b2e81d

Browse files
authored
Merge branch 'pschatzmann:main' into main
2 parents 7ee2c0c + 431aa6e commit 9b2e81d

File tree

5 files changed

+50
-44
lines changed

5 files changed

+50
-44
lines changed

examples/output_aac/output_aac.ino

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,39 @@
55
* @brief We just display the decoded audio data on the serial monitor
66
* @version 0.1
77
* @date 2021-07-18
8-
*
8+
*
99
* @copyright Copyright (c) 2021
10-
*
10+
*
1111
*/
1212
#include "AACDecoderHelix.h"
1313
#include "BabyElephantWalk60_aac.h"
1414

1515
using namespace libhelix;
1616

17-
void dataCallback(AACFrameInfo &info, int16_t *pcm_buffer, size_t len) {
18-
for (size_t i=0; i<len; i+=info.nChans){
19-
for (int j=0;j<info.nChans;j++){
20-
Serial.print(pcm_buffer[i+j]);
21-
Serial.print(" ");
22-
}
23-
Serial.println();
17+
AACDecoderHelix aac;
18+
19+
void dataCallback(AACFrameInfo &info, int16_t *pcm_buffer, size_t len,
20+
void *ref) {
21+
for (size_t i = 0; i < len; i += info.nChans) {
22+
for (int j = 0; j < info.nChans; j++) {
23+
Serial.print(pcm_buffer[i + j]);
24+
Serial.print(" ");
2425
}
26+
Serial.println();
27+
}
2528
}
2629

27-
AACDecoderHelix aac(dataCallback);
28-
2930
void setup() {
30-
Serial.begin(115200);
31-
aac.begin();
31+
Serial.begin(115200);
32+
aac.setDataCallback(dataCallback);
33+
aac.begin();
3234
}
3335

3436
void loop() {
35-
Serial.println("writing...");
36-
aac.write(BabyElephantWalk60_aac, BabyElephantWalk60_aac_len);
37+
Serial.println("writing...");
38+
aac.write(BabyElephantWalk60_aac, BabyElephantWalk60_aac_len);
3739

38-
// restart from the beginning
39-
delay(2000);
40-
aac.begin();
40+
// restart from the beginning
41+
delay(2000);
42+
aac.begin();
4143
}

examples/output_mp3/output_mp3.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
using namespace libhelix;
1515

16-
void dataCallback(MP3FrameInfo &info, int16_t *pcm_buffer, size_t len) {
16+
MP3DecoderHelix mp3;
17+
18+
19+
void dataCallback(MP3FrameInfo &info, int16_t *pcm_buffer, size_t len, void* ref) {
1720
for (size_t i=0; i<len; i+=info.nChans){
1821
for (int j=0;j<info.nChans;j++){
1922
Serial.print(pcm_buffer[i+j]);
@@ -23,10 +26,9 @@ void dataCallback(MP3FrameInfo &info, int16_t *pcm_buffer, size_t len) {
2326
}
2427
}
2528

26-
MP3DecoderHelix mp3(dataCallback);
27-
2829
void setup() {
2930
Serial.begin(115200);
31+
mp3.setDataCallback(dataCallback);
3032
mp3.begin();
3133
}
3234

src/AACDecoderHelix.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
namespace libhelix {
1010

11-
typedef void (*AACInfoCallback)(_AACFrameInfo &info);
12-
typedef void (*AACDataCallback)(_AACFrameInfo &info,short *pcm_buffer, size_t len);
11+
typedef void (*AACInfoCallback)(_AACFrameInfo &info, void* caller);
12+
typedef void (*AACDataCallback)(_AACFrameInfo &info,short *pcm_buffer, size_t len, void* caller);
1313

1414
/**
1515
* @brief A simple Arduino API for the libhelix AAC decoder. The data us provided with the help of write() calls.
@@ -22,9 +22,8 @@ class AACDecoderHelix : public CommonHelix {
2222
AACDecoderHelix() = default;
2323

2424
#ifdef ARDUINO
25-
AACDecoderHelix(Print &output, AACInfoCallback infoCallback=nullptr){
25+
AACDecoderHelix(Print &output){
2626
this->out = &output;
27-
this->infoCallback = infoCallback;
2827
}
2928
#endif
3029
AACDecoderHelix(AACDataCallback dataCallback){
@@ -35,9 +34,9 @@ class AACDecoderHelix : public CommonHelix {
3534
end();
3635
}
3736

38-
39-
void setInfoCallback(AACInfoCallback cb){
37+
void setInfoCallback(AACInfoCallback cb, void* caller=nullptr){
4038
this->infoCallback = cb;
39+
p_caller_info = caller;
4140
}
4241

4342
void setDataCallback(AACDataCallback cb){
@@ -75,6 +74,8 @@ class AACDecoderHelix : public CommonHelix {
7574
AACDataCallback pcmCallback = nullptr;
7675
AACInfoCallback infoCallback = nullptr;
7776
_AACFrameInfo aacFrameInfo;
77+
void *p_caller_info = nullptr;
78+
void *p_caller_data = nullptr;
7879

7980
/// Allocate the decoder
8081
virtual void allocateDecoder() override {
@@ -140,11 +141,11 @@ class AACDecoderHelix : public CommonHelix {
140141
// provide result
141142
if(pcmCallback!=nullptr){
142143
// output via callback
143-
pcmCallback(info, pcm_buffer,info.outputSamps);
144+
pcmCallback(info, pcm_buffer,info.outputSamps, p_caller_data);
144145
} else {
145146
// output to stream
146147
if (info.sampRateOut!=aacFrameInfo.sampRateOut && infoCallback!=nullptr){
147-
infoCallback(info);
148+
infoCallback(info, p_caller_info);
148149
}
149150
#ifdef ARDUINO
150151
int sampleSize = info.bitsPerSample / 8;

src/CommonHelix.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#pragma once
22

33
#ifdef ARDUINO
4-
#include "Arduino.h"
4+
# include "Arduino.h"
55
#else
6-
// remove yield statment if used outside of arduino
7-
#define yield()
8-
//#define delay(ms)
9-
#include <stdint.h>
6+
// remove delay statment if used outside of arduino
7+
# include <stdint.h>
8+
# define delay(ms)
109
#endif
1110

1211
// Not all processors support assert
1312
#ifndef assert
14-
#ifdef NDEBUG
13+
# ifdef NDEBUG
1514
# define assert(condition) ((void)0)
16-
#else
15+
# else
1716
# define assert(condition) /*implementation defined*/
18-
#endif
17+
# endif
1918
#endif
2019

2120
#include "helix_log.h"

src/MP3DecoderHelix.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace libhelix {
1111

1212

13-
typedef void (*MP3InfoCallback)(MP3FrameInfo &info);
14-
typedef void (*MP3DataCallback)(MP3FrameInfo &info,short *pcm_buffer, size_t len);
13+
typedef void (*MP3InfoCallback)(MP3FrameInfo &info, void* caller);
14+
typedef void (*MP3DataCallback)(MP3FrameInfo &info,short *pcm_buffer, size_t len, void* caller);
1515

1616
enum MP3Type {MP3Normal=0, MP3SelfContaind=1};
1717

@@ -30,9 +30,8 @@ class MP3DecoderHelix : public CommonHelix {
3030
}
3131

3232
#ifdef ARDUINO
33-
MP3DecoderHelix(Print &output, MP3Type mp3Type=MP3Normal, MP3InfoCallback infoCallback=nullptr){
33+
MP3DecoderHelix(Print &output, MP3Type mp3Type=MP3Normal){
3434
this->out = &output;
35-
this->infoCallback = infoCallback;
3635
this->mp3_type = mp3Type;
3736
}
3837
#endif
@@ -49,8 +48,9 @@ class MP3DecoderHelix : public CommonHelix {
4948
end();
5049
}
5150

52-
void setInfoCallback(MP3InfoCallback cb){
51+
void setInfoCallback(MP3InfoCallback cb, void* caller=nullptr){
5352
this->infoCallback = cb;
53+
p_caller_info = caller;
5454
}
5555

5656
void setDataCallback(MP3DataCallback cb){
@@ -91,6 +91,8 @@ class MP3DecoderHelix : public CommonHelix {
9191
MP3InfoCallback infoCallback = nullptr;
9292
MP3Type mp3_type;
9393
MP3FrameInfo mp3FrameInfo;
94+
void *p_caller_info = nullptr;
95+
void *p_caller_data = nullptr;
9496

9597
/// Allocate the decoder
9698
virtual void allocateDecoder() override {
@@ -161,11 +163,11 @@ class MP3DecoderHelix : public CommonHelix {
161163
// provide result
162164
if(pcmCallback!=nullptr){
163165
// output via callback
164-
pcmCallback(info, pcm_buffer, info.outputSamps);
166+
pcmCallback(info, pcm_buffer, info.outputSamps, p_caller_data);
165167
} else {
166168
// output to stream
167169
if (info.samprate!=mp3FrameInfo.samprate && infoCallback!=nullptr){
168-
infoCallback(info);
170+
infoCallback(info, p_caller_info);
169171
}
170172
#ifdef ARDUINO
171173
int sampleSize = info.bitsPerSample / 8;

0 commit comments

Comments
 (0)