Skip to content

Commit ad06a5d

Browse files
committed
SPDIFStream clenaup destructor
1 parent bad7148 commit ad06a5d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/AudioExperiments/AudioSPDIF.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,6 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
260260

261261
/// Start with the provided parameters
262262
bool begin(SPDIFConfig cfg) {
263-
if (out == nullptr) {
264-
#if USE_ESP32_I2S == 1
265-
out = new SPDFOutI2SESP32();
266-
#else
267-
out = new SPDIFOutI2S();
268-
#endif
269-
}
270263
if (i2sOn){
271264
out->end();
272265
}
@@ -284,8 +277,6 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
284277
bool result = true;
285278
if (out != nullptr) {
286279
result = out->end();
287-
delete out;
288-
out = nullptr;
289280
}
290281
i2sOn = false;
291282
return result;
@@ -389,6 +380,16 @@ class SPDIFStream : public AudioStreamX {
389380
/// start SPDIF with the indicated configuration
390381
bool begin(SPDIFConfig cfg) {
391382
this->cfg = cfg;
383+
// Define output class if not yet defined
384+
if (spdif_out == nullptr) {
385+
#if USE_ESP32_I2S == 1
386+
spdif_out = new SPDFOutI2SESP32();
387+
#else
388+
spdif_out = new SPDIFOutI2S();
389+
#endif
390+
spdif.setOutput(spdif_out);
391+
}
392+
392393
// define source format
393394
converter.setInputInfo(cfg);
394395
// define target format for converter
@@ -430,7 +431,7 @@ class SPDIFStream : public AudioStreamX {
430431
SPDIFConfig cfg;
431432
SPDIFStream16Bit2Channels spdif;
432433
FormatConverterStream converter{spdif};
433-
SPDIFOutGeneric *spdif_out=nullptr;
434+
SPDIFOut *spdif_out=nullptr;
434435
};
435436

436437
} // namespace audio_tools

0 commit comments

Comments
 (0)