19
19
20
20
#include " AudioConfig.h"
21
21
#include " AudioTools/AudioStreams.h"
22
- #ifdef ESP32
23
- #include " soc/rtc.h"
24
- #endif
25
22
26
23
// Set USE_ESP32_I2S to 1 if you want to use the explicit ESP32 implementation.
27
24
// 0 for generic implementation
59
56
#define SYNC_OFFSET 2 // byte offset of SYNC
60
57
#define SYNC_FLIP ((BMC_B ^ BMC_M) >> (SYNC_OFFSET * 8 ))
61
58
59
+ // Include I2S based on configuration
62
60
#if defined(ESP32) && USE_ESP32_I2S == 1
63
61
#include " driver/i2s.h"
64
62
#include " freertos/FreeRTOS.h"
@@ -122,7 +120,7 @@ struct SPDIFConfig : public AudioBaseInfo {
122
120
};
123
121
124
122
/* *
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
126
124
* @author Phil Schatzmann
127
125
* @copyright GPLv3
128
126
*
@@ -154,6 +152,10 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
154
152
LOGE (" Unsupported bits per sample: %d - must be 16!" ,
155
153
info.bits_per_sample );
156
154
}
155
+ if (info.channels != 2 ) {
156
+ LOGE (" Unsupported number of channels: %d - must be 2!" ,
157
+ info.channels );
158
+ }
157
159
begin (cfg);
158
160
}
159
161
@@ -191,10 +193,12 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
191
193
}
192
194
193
195
#if USE_ESP32_I2S == 1
196
+
194
197
bool end () {
195
198
i2sOn = false ;
196
199
return i2s_driver_uninstall (I2S_NUM) == ESP_OK;
197
200
}
201
+
198
202
#else
199
203
200
204
bool end () {
@@ -298,7 +302,9 @@ class SPDIFStream16Bit2Channels : public AudioStreamX {
298
302
class SPDIFStream : public AudioStreamX {
299
303
public:
300
304
SPDIFStream () = default ;
305
+ // / start SPDIF with default configuration
301
306
bool begin () { spdif.begin (); }
307
+ // / start SPDIF with the indicated configuration
302
308
bool begin (SPDIFConfig cfg) {
303
309
this ->cfg = cfg;
304
310
// define source format
@@ -317,14 +323,18 @@ class SPDIFStream : public AudioStreamX {
317
323
spdif.begin (targetSpdifConfig);
318
324
}
319
325
326
+ // / Close the SPDIF processing
320
327
bool end () { return spdif.end (); }
321
328
329
+ // / Provide audio data to SPDIF
322
330
size_t write (const uint8_t *src, size_t size) {
323
331
return converter.write (src, size);
324
332
}
325
333
334
+ // / Provides the default configuration
326
335
SPDIFConfig defaultConfig () { return spdif.defaultConfig (); }
327
336
337
+ // / Updates the audio information (channels, bits_per_sample, sample_rate)
328
338
virtual void setAudioInfo (AudioBaseInfo info) {
329
339
// update input info
330
340
converter.setInputInfo (info);
0 commit comments