2 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
36 dec_routine = g723_24_decoder;
41 dec_routine = g721_decoder;
46 dec_routine = g723_40_decoder;
55 LOGE(
"channels must be 1 instead of %d", info.
channels);
59 LOGE(
"sample_rate must be 8000 instead of %d", info.
sample_rate);
69 bool begin()
override {
73 out_size =
sizeof(int16_t);
74 g72x_init_state(&state);
87 operator bool() {
return is_active; }
89 size_t write(
const uint8_t *data,
size_t len)
override {
90 LOGD(
"write: %d", len);
96 uint8_t *p_byte = (uint8_t *)data;
97 for (
int j = 0; j < len; j++) {
98 sample = (*dec_routine)(p_byte[j], AUDIO_ENCODING_LINEAR, &state);
99 p_print->write((uint8_t*)&sample, out_size);
106 Print *p_print =
nullptr;
108 bool is_active =
false;
112 struct g72x_state state;
114 int (*dec_routine)(
int code,
int out_coding,
struct g72x_state* state_ptr);
116 unsigned int in_buffer = 0;
138 enc_routine = g721_encoder;
140 p_mime =
"audio/g721";
144 enc_routine = g723_24_encoder;
146 p_mime =
"audio/g723_24";
150 enc_routine = g723_40_encoder;
152 p_mime =
"audio/g723_40";
157 bool begin()
override {
159 g72x_init_state(&state);
167 void end()
override {
172 const char *
mime()
override {
return p_mime; }
177 LOGE(
"channels must be 1 instead of %d", info.
channels);
181 LOGE(
"sample_rate must be 8000 instead of %d", info.
sample_rate);
185 LOGE(
"bits_per_sample must be 16 instead of %d", info.
bits_per_sample);
191 void setOutput(
Print &out_stream)
override { p_print = &out_stream; }
193 operator bool() {
return is_active; }
195 size_t write(
const uint8_t *data,
size_t len)
override {
196 LOGD(
"write: %d", len);
202 int16_t *p_16 = (int16_t *)data;
203 int samples = len /
sizeof(int16_t);
204 for (
int j = 0; j < samples; j++) {
205 code = (*enc_routine)(p_16[j], AUDIO_ENCODING_LINEAR, &state);
206 p_print->write(&code, 1);
213 Print *p_print =
nullptr;
214 bool is_active =
false;
215 const char *p_mime =
nullptr;
217 struct g72x_state state;
218 unsigned char sample_char;
219 int16_t sample_int16;
221 int (*enc_routine)(
int sample,
int in_coding,
struct g72x_state* state_ptr);
223 unsigned int out_buffer = 0;
307 assert(this->enc!=
nullptr);
309 size_t write(
const uint8_t *data,
size_t len)
override {
310 LOGD(
"write: %d", len);
317 int16_t *p_16 = (int16_t *)data;
318 uint8_t buffer[samples];
319 for (
int j = 0; j < samples; j++) {
320 buffer[j] = enc(p_16[j]);
322 p_print->write(buffer,samples);
326 uint8_t(*enc)(int)=
nullptr;
341 assert(this->dec!=
nullptr);
344 size_t write(
const uint8_t *data,
size_t len)
override {
345 LOGD(
"write: %d", len);
351 uint8_t *p_8 = (uint8_t *)data;
352 for (
int j = 0; j < len; j++) {
353 int16_t result = dec(p_8[j]);
354 p_print->write((uint8_t*)&result,
sizeof(int16_t));
359 int (*dec)(uint8_t a_val)=
nullptr;