35 dec_routine = g723_24_decoder;
40 dec_routine = g721_decoder;
45 dec_routine = g723_40_decoder;
54 LOGE(
"channels must be 1 instead of %d", info.
channels);
58 LOGE(
"sample_rate must be 8000 instead of %d", info.
sample_rate);
68 bool begin()
override {
72 out_size =
sizeof(int16_t);
73 g72x_init_state(&state);
86 operator bool() {
return is_active; }
88 size_t write(
const void *data,
size_t length)
override {
89 LOGD(
"write: %d", length);
95 uint8_t *p_byte = (uint8_t *)data;
96 for (
int j = 0; j < length; j++) {
97 sample = (*dec_routine)(p_byte[j], AUDIO_ENCODING_LINEAR, &state);
98 p_print->write((uint8_t*)&sample, out_size);
105 Print *p_print =
nullptr;
107 bool is_active =
false;
111 struct g72x_state state;
113 int (*dec_routine)(
int code,
int out_coding,
struct g72x_state* state_ptr);
115 unsigned int in_buffer = 0;
137 enc_routine = g721_encoder;
139 p_mime =
"audio/g721";
143 enc_routine = g723_24_encoder;
145 p_mime =
"audio/g723_24";
149 enc_routine = g723_40_encoder;
151 p_mime =
"audio/g723_40";
156 bool begin()
override {
158 g72x_init_state(&state);
166 void end()
override {
171 const char *
mime()
override {
return p_mime; }
176 LOGE(
"channels must be 1 instead of %d", info.
channels);
180 LOGE(
"sample_rate must be 8000 instead of %d", info.
sample_rate);
184 LOGE(
"bits_per_sample must be 16 instead of %d", info.
bits_per_sample);
190 void setOutput(
Print &out_stream)
override { p_print = &out_stream; }
192 operator bool() {
return is_active; }
194 size_t write(
const void *in_ptr,
size_t byte_count)
override {
195 LOGD(
"write: %d", byte_count);
201 int16_t *p_16 = (int16_t *)in_ptr;
202 int samples = byte_count /
sizeof(int16_t);
203 for (
int j = 0; j < samples; j++) {
204 code = (*enc_routine)(p_16[j], AUDIO_ENCODING_LINEAR, &state);
205 p_print->write(&code, 1);
212 Print *p_print =
nullptr;
213 bool is_active =
false;
214 const char *p_mime =
nullptr;
216 struct g72x_state state;
217 unsigned char sample_char;
218 int16_t sample_int16;
220 int (*enc_routine)(
int sample,
int in_coding,
struct g72x_state* state_ptr);
222 unsigned int out_buffer = 0;
306 assert(this->enc!=
nullptr);
308 size_t write(
const void *in_ptr,
size_t in_size)
override {
309 LOGD(
"write: %d", in_size);
315 int samples = in_size/2;
316 int16_t *p_16 = (int16_t *)in_ptr;
317 uint8_t buffer[samples];
318 for (
int j = 0; j < samples; j++) {
319 buffer[j] = enc(p_16[j]);
321 p_print->write(buffer,samples);
325 uint8_t(*enc)(int)=
nullptr;
340 assert(this->dec!=
nullptr);
343 size_t write(
const void *in_ptr,
size_t in_size)
override {
344 LOGD(
"write: %d", in_size);
350 uint8_t *p_8 = (uint8_t *)in_ptr;
351 for (
int j = 0; j < in_size; j++) {
352 int16_t result = dec(p_8[j]);
353 p_print->write((uint8_t*)&result,
sizeof(int16_t));
358 int (*dec)(uint8_t a_val)=
nullptr;