13 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
29 ILBCDecoder(EnumLBCFrameSize frameSize = ms30,
bool useEnhancer =
true) {
33 frame_size = frameSize;
34 use_enhancer = useEnhancer;
41 virtual bool begin() {
43 if (p_print==
nullptr){
44 LOGE(
"Output not defined");
49 p_ilbc =
new iLBCDecode(frame_size, use_enhancer);
53 decoded_buffer.resize(p_ilbc->getSamples());
54 encoded_buffer.resize(p_ilbc->getEncodedBytes());
57 notifyAudioChange(info);
69 operator bool() {
return p_ilbc !=
nullptr; }
71 virtual size_t write(
const uint8_t *data,
size_t len) {
72 if (p_ilbc==
nullptr)
return 0;
73 LOGI(
"write: %d", len);
74 int samples = len /
sizeof(int16_t);
75 int16_t *p_samples = (int16_t *)data;
76 for (
int j=0;j<samples;j++){
77 encoded_buffer[encoded_buffer_pos++]=p_samples[j];
78 if (encoded_buffer_pos>=encoded_buffer.size()){
79 memset(decoded_buffer.data(),0,decoded_buffer.size()*
sizeof(int16_t));
80 p_ilbc->decode(encoded_buffer.data(), decoded_buffer.data());
81 if (p_print!=
nullptr){
82 p_print->write((uint8_t*)decoded_buffer.data(), decoded_buffer.size()*
sizeof(int16_t));
85 encoded_buffer_pos = 0;
92 Print *p_print =
nullptr;
93 iLBCDecode *p_ilbc =
nullptr;
94 Vector<int16_t> decoded_buffer{0};
95 Vector<uint8_t> encoded_buffer{0};
96 int16_t encoded_buffer_pos = 0;
97 EnumLBCFrameSize frame_size;
116 frame_size = frameSize;
125 if (p_print==
nullptr){
126 LOGE(
"Output not defined");
134 LOGW(
"The sample rate should be 8000: %d", info.
sample_rate);
137 LOGW(
"channels should be 1: %d", info.
channels);
139 if (p_ilbc==
nullptr){
140 p_ilbc =
new iLBCEncode(frame_size);
142 decoded_buffer.resize(p_ilbc->getSamples());
143 encoded_buffer.resize(p_ilbc->getEncodedBytes());
144 decoded_buffer_pos = 0;
150 if (p_ilbc !=
nullptr) {
156 virtual const char *
mime() {
return "audio/ilbc"; }
158 virtual void setOutput(
Print &out_stream) { p_print = &out_stream; }
160 operator bool() {
return p_ilbc !=
nullptr; }
162 virtual size_t write(
const uint8_t *data,
size_t len) {
163 if (p_ilbc==
nullptr)
return 0;
164 LOGI(
"write: %d", len);
166 int samples = len /
sizeof(int16_t);
167 int16_t *p_samples = (int16_t *)data;
169 for (
int j=0;j<samples;j++){
170 decoded_buffer[decoded_buffer_pos++]=p_samples[j];
171 if (decoded_buffer_pos>=decoded_buffer.size()){
172 memset(encoded_buffer.data(),0,encoded_buffer.size());
173 p_ilbc->encode(decoded_buffer.data(), encoded_buffer.data());
174 if (p_print!=
nullptr){
175 p_print->write(encoded_buffer.data(), encoded_buffer.size());
177 decoded_buffer_pos = 0;
184 Print *p_print =
nullptr;
185 iLBCEncode *p_ilbc =
nullptr;
186 Vector<float> decoded_buffer{0};
187 Vector<uint8_t> encoded_buffer{0};
188 int16_t decoded_buffer_pos = 0;
189 EnumLBCFrameSize frame_size;