Skip to content

Commit 36ae7f1

Browse files
committed
DRAFT CodecDSF
1 parent 71e7243 commit 36ae7f1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/AudioTools/AudioCodecs/CodecDSF.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,16 @@ class DSFDecoder : public AudioDecoder {
135135
TRACED();
136136
AudioDecoder::setAudioInfo(from);
137137
meta.copyFrom(from);
138-
// Ensure PCM buffer is allocated based on the new audio info
139-
int buffer_size = getOutputBufferSize();
140-
pcmBuffer.resize(buffer_size);
141-
channelAccum.resize(meta.channels);
142-
channelIntegrator.resize(meta.channels);
143-
144-
setupTargetPCMRate();
145-
setupDecimationStep();
138+
if (isHeaderAvailable()){
139+
// Ensure PCM buffer is allocated based on the new audio info
140+
int buffer_size = getOutputBufferSize();
141+
pcmBuffer.resize(buffer_size);
142+
channelAccum.resize(meta.channels);
143+
channelIntegrator.resize(meta.channels);
144+
145+
setupTargetPCMRate();
146+
setupDecimationStep();
147+
}
146148
}
147149

148150
/**
@@ -368,8 +370,8 @@ class DSFDecoder : public AudioDecoder {
368370
channelAccum[ch] = 0.0f;
369371
}
370372
// Initialize integrator states
371-
for (int i = 0; i < meta.channels; i++) {
372-
channelIntegrator[i] = 0.0f;
373+
for (int ch = 0; ch < meta.channels; ch++) {
374+
channelIntegrator[ch] = 0.0f;
373375
}
374376

375377
// Accumulate DSD samples over decimation period
@@ -401,7 +403,7 @@ class DSFDecoder : public AudioDecoder {
401403

402404
for (int ch = 0; ch < meta.channels; ch++) {
403405
// store max_value to scale to max 1.0
404-
if (channelAccum[ch] > max_value){
406+
if (channelAccum[ch] > max_value) {
405407
max_value = channelAccum[ch];
406408
}
407409

@@ -411,9 +413,9 @@ class DSFDecoder : public AudioDecoder {
411413
// Serial.print(" ");
412414

413415
// Convert to PCM sample and store in buffer
414-
writePCMSample(clip(channelAccum[ch]/max_value));
416+
writePCMSample(clip(channelAccum[ch] / max_value));
415417
}
416-
418+
417419
// Serial.println();
418420

419421
// Output the PCM samples for all channels
@@ -599,9 +601,8 @@ class DSFDecoder : public AudioDecoder {
599601
}
600602
DSFFormat* fmt = (DSFFormat*)data;
601603
meta.channels = fmt->channelNum;
602-
if (meta.channels == 0)
603-
meta.channels =
604-
fmt->channelType; // Fallback to channel type if channels is 0
604+
// Fallback to channel type if channels is 0
605+
if (meta.channels == 0) meta.channels = fmt->channelType;
605606
meta.dsd_sample_rate = fmt->samplingFrequency;
606607

607608
// Validate channel count

0 commit comments

Comments
 (0)