3 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
37 p_print = &out_stream;
55 void setSigned(
bool isSigned) { is_signed = isSigned; }
65 notifyAudioChange(from);
70 virtual size_t write(
const uint8_t *data,
size_t len)
override {
71 if (p_print ==
nullptr)
return 0;
73 memset(buffer.data(), 0, len * 2);
75 int8_t *pt8 = (int8_t *)data;
76 for (
size_t j = 0; j < len; j++) {
77 buffer[j] = convertSample(pt8[j]);
80 uint8_t *pt8 = (uint8_t *)data;
81 for (
size_t j = 0; j < len; j++) {
82 buffer[j] = convertSample(pt8[j]);
85 int write_byte_count = len *
sizeof(int16_t);
86 size_t result = p_print->write((uint8_t *)buffer.data(), write_byte_count);
87 LOGD(
"DecoderL8 %d -> %d -> %d", (
int)len, write_byte_count, (
int)result);
88 return result /
sizeof(int16_t);
91 int16_t convertSample(int16_t in) {
96 return NumberConverter::clipT<int16_t>(tmp * 258);
99 virtual operator bool()
override {
return p_print!=
nullptr; }
103 bool is_signed =
false;
104 Vector<int16_t> buffer;
138 const char *
mime()
override {
return "audio/l8"; }
141 bool begin()
override { is_open =
true;
return true;}
150 void end()
override { is_open =
false; }
153 size_t write(
const uint8_t *data,
size_t len)
override {
154 if (p_print ==
nullptr)
return 0;
155 int16_t *pt16 = (int16_t *)data;
156 size_t samples = len / 2;
157 buffer.resize(samples);
158 memset(buffer.data(), 0, samples);
159 for (
size_t j = 0; j < samples; j++) {
160 buffer[j] = convertSample(pt16[j]);
163 size_t result = p_print->write((uint8_t *)buffer.data(), samples);
164 LOGD(
"EncoderL8 %d -> %d -> %d", (
int)len,(
int) samples, (
int)result);
165 return result *
sizeof(int16_t);
168 operator bool()
override {
return is_open; }
170 int16_t convertSample(int16_t sample) {
171 int16_t tmp = NumberConverter::clipT<int8_t>(sample / 258);
177 }
else if (tmp > 255) {
184 bool isOpen() {
return is_open; }
187 Print *p_print =
nullptr;
189 bool is_signed =
false;
190 Vector<int8_t> buffer;