20#pragma GCC optimize("O3")
147 LOGD(
"write: %u", (
unsigned)len);
175 int buffer_size = frame_size;
183 LOGI(
"processHeader: %u", (
unsigned)len);
185 if (
memcmp(data,
"DSD ", 4) != 0) {
186 LOGE(
"Invalid DSF header magic");
190 int dataPos =
findTag(
"data", data, len);
192 if (dataPos < 0 ||
fmtPos < 0) {
193 LOGE(
"DSF header not found in data (fmt: %d, data: %d)",
fmtPos, dataPos);
198 parseData(data + dataPos, len - dataPos);
213 LOGD(
"processDSDData: %u (%u)", (
unsigned)len, (
unsigned)
startPos);
226 if (buffered == 0)
break;
239 for (
size_t i =
startPos; i < len; i++) {
304 v = (
v & 0x55) + ((
v >> 1) & 0x55);
305 v = (
v & 0x33) + ((
v >> 2) & 0x33);
306 return (
v & 0x0F) + ((
v >> 4) & 0x0F);
310 if (value > 1.0f)
return 1.0f;
311 if (value < -1.0f)
return -1.0f;
333 {0.5412f, 1.3066f, 0},
334 {0.5176f, 0.7071f, 1.9319f},
348 LOGE(
"Invalid sample rates: DSD=%u, PCM=%u",
355 LOGW(
"Decimation step %u too low, setting to 64",
360 LOGW(
"Decimation step %u too high, setting to 512",
368 LOGI(
"Decimation step set to %u for DSD rate %u and target PCM rate %u",
403 for (
size_t j = 0;
j +
taglen <= len;
j++) {
414 LOGE(
"FMT section too short to parse DSF format header");
429 LOGI(
"channels: %u, DSD sample rate: %u, block size: %u",
438 LOGE(
"Data section too short to parse DSF data header");
468 const char*
mime()
override {
return "audio/dsf"; }
524 if (frameSize == 0)
return 0;
527 while (pos + frameSize <= len) {
565 return *
reinterpret_cast<const int8_t*
>(ptr) / 127.0f;
574 return static_cast<float>(
static_cast<int32_t>(
v)) / 8388607.0f;
579 return v / 2147483647.0f;
587 float prevSample =
chState[
ch].prevSample;
592 float input = prevSample +
t * (currentSample - prevSample);
598 float feedback =
bit ? 1.0f : -1.0f;
673 memcpy(prefix.id,
"DSD ", 4);
676 prefix.metadataOffset = 0;
681 fmt.formatVersion = 1;
686 fmt.bitsPerSample = 1;
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120
enum VBanDataTypeList __attribute__