@@ -135,14 +135,16 @@ class DSFDecoder : public AudioDecoder {
135
135
TRACED ();
136
136
AudioDecoder::setAudioInfo (from);
137
137
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
+ }
146
148
}
147
149
148
150
/* *
@@ -368,8 +370,8 @@ class DSFDecoder : public AudioDecoder {
368
370
channelAccum[ch] = 0 .0f ;
369
371
}
370
372
// 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 ;
373
375
}
374
376
375
377
// Accumulate DSD samples over decimation period
@@ -401,7 +403,7 @@ class DSFDecoder : public AudioDecoder {
401
403
402
404
for (int ch = 0 ; ch < meta.channels ; ch++) {
403
405
// store max_value to scale to max 1.0
404
- if (channelAccum[ch] > max_value){
406
+ if (channelAccum[ch] > max_value) {
405
407
max_value = channelAccum[ch];
406
408
}
407
409
@@ -411,9 +413,9 @@ class DSFDecoder : public AudioDecoder {
411
413
// Serial.print(" ");
412
414
413
415
// Convert to PCM sample and store in buffer
414
- writePCMSample (clip (channelAccum[ch]/ max_value));
416
+ writePCMSample (clip (channelAccum[ch] / max_value));
415
417
}
416
-
418
+
417
419
// Serial.println();
418
420
419
421
// Output the PCM samples for all channels
@@ -599,9 +601,8 @@ class DSFDecoder : public AudioDecoder {
599
601
}
600
602
DSFFormat* fmt = (DSFFormat*)data;
601
603
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 ;
605
606
meta.dsd_sample_rate = fmt->samplingFrequency ;
606
607
607
608
// Validate channel count
0 commit comments