35 virtual const char *
mime()
override {
return "audio/aptx"; }
42 return ctx !=
nullptr;
47 bool dropped = aptx_decode_sync_finish(
ctx);
54 operator bool() {
return ctx !=
nullptr; }
56 virtual size_t write(
const uint8_t *data,
size_t len) {
57 LOGI(
"write: %d", len);
71 processed = aptx_decode_sync(
ctx, (
const uint8_t *)data, len,
86 return is_ok ? len : 0;
90 struct aptx_context *
ctx =
nullptr;
104 LOGI(
"samples: %d", samples);
107 for (
int j = 0; j < samples; j++) {
113 LOGE(
"aptX decoding failed to write decoded data");
120 void checkSync(
bool synced,
bool dropped,
bool &is_ok) {
124 LOGE(
"aptX decoding failed, synchronizing");
129 LOGE(
"aptX synchronization successful, dropped %lu byte%s",
130 (
unsigned long)dropped, (dropped != 1) ?
"s" :
"");
135 LOGE(
"aptX decoding failed, synchronizing");
141 if (!
syncing)
LOGE(
"aptX decoding failed, synchronizing");
142 LOGE(
"aptX synchronization successful, dropped %lu byte%s",
143 (
unsigned long)dropped, (dropped != 1) ?
"s" :
"");
147 LOGI(
"aptX synchronization successful");
157 if (length >= 4 && memcmp(input_buffer,
"\x4b\xbf\x4b\xbf", 4) == 0) {
159 LOGE(
"aptX audio stream (not aptX HD)");
162 }
else if (length >= 6 &&
163 memcmp(input_buffer,
"\x73\xbe\xff\x73\xbe\xff", 6) == 0) {
165 LOGE(
"aptX HD audio stream");
169 if (length >= 4 && memcmp(input_buffer,
"\x6b\xbf\x6b\xbf", 4) == 0) {
170 LOGE(
"standard aptX audio stream - not supported");
173 LOGE(
"No aptX nor aptX HD audio stream");
205 LOGI(
"is_hd: %s",
is_hd ?
"true" :
"false");
212 if (
ctx !=
nullptr) {
213 size_t output_written = 0;
216 if (output_written > 0) {
220 if (written != output_written) {
221 LOGE(
"write requested: %d eff: %d", output_written, written);
229 virtual const char *
mime() {
return "audio/aptx"; }
247 operator bool() {
return ctx !=
nullptr; }
249 virtual size_t write(
const uint8_t *data,
size_t len) {
250 LOGI(
"write: %d", len);
251 if (
ctx ==
nullptr)
return 0;
252 size_t output_written = 0;
255 int16_t *in_ptr16 = (int16_t *)data;
256 int in_samples = len / 2;
257 for (
int j = 0; j < in_samples; j++) {
262 size_t result = aptx_encode(
299 struct aptx_context *
ctx =
nullptr;
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120