Skip to content

Commit 6b8962a

Browse files
committed
SPDIFStream
1 parent aab26f7 commit 6b8962a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/AudioExperiments/AudioSPDIF.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
#include "AudioConfig.h"
2121
#include "AudioTools/AudioStreams.h"
22-
#ifdef ESP32
23-
#include "soc/rtc.h"
24-
#endif
2522

2623
// Set USE_ESP32_I2S to 1 if you want to use the explicit ESP32 implementation.
2724
// 0 for generic implementation
@@ -59,6 +56,7 @@
5956
#define SYNC_OFFSET 2 // byte offset of SYNC
6057
#define SYNC_FLIP ((BMC_B ^ BMC_M) >> (SYNC_OFFSET * 8))
6158

59+
// Include I2S based on configuration
6260
#if defined(ESP32) && USE_ESP32_I2S == 1
6361
#include "driver/i2s.h"
6462
#include "freertos/FreeRTOS.h"
@@ -122,7 +120,7 @@ struct SPDIFConfig : public AudioBaseInfo {
122120
};
123121

124122
/**
125-
* @brief Output as 16 bit SPDIF on the I2S data output pin
123+
* @brief Output as 16 bit stereo SPDIF on the I2S data output pin
126124
* @author Phil Schatzmann
127125
* @copyright GPLv3
128126
*
@@ -154,6 +152,10 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
154152
LOGE("Unsupported bits per sample: %d - must be 16!",
155153
info.bits_per_sample);
156154
}
155+
if (info.channels != 2) {
156+
LOGE("Unsupported number of channels: %d - must be 2!",
157+
info.channels);
158+
}
157159
begin(cfg);
158160
}
159161

@@ -191,10 +193,12 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
191193
}
192194

193195
#if USE_ESP32_I2S == 1
196+
194197
bool end() {
195198
i2sOn = false;
196199
return i2s_driver_uninstall(I2S_NUM) == ESP_OK;
197200
}
201+
198202
#else
199203

200204
bool end() {
@@ -298,7 +302,9 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
298302
class SPDIFStream : public AudioStreamX {
299303
public:
300304
SPDIFStream() = default;
305+
/// start SPDIF with default configuration
301306
bool begin() { spdif.begin(); }
307+
/// start SPDIF with the indicated configuration
302308
bool begin(SPDIFConfig cfg) {
303309
this->cfg = cfg;
304310
// define source format
@@ -317,14 +323,18 @@ class SPDIFStream : public AudioStreamX {
317323
spdif.begin(targetSpdifConfig);
318324
}
319325

326+
/// Close the SPDIF processing
320327
bool end() { return spdif.end(); }
321328

329+
/// Provide audio data to SPDIF
322330
size_t write(const uint8_t *src, size_t size) {
323331
return converter.write(src, size);
324332
}
325333

334+
/// Provides the default configuration
326335
SPDIFConfig defaultConfig() { return spdif.defaultConfig(); }
327336

337+
/// Updates the audio information (channels, bits_per_sample, sample_rate)
328338
virtual void setAudioInfo(AudioBaseInfo info) {
329339
// update input info
330340
converter.setInputInfo(info);

0 commit comments

Comments
 (0)