Skip to content

Commit e3c61b7

Browse files
committed
SPDIFStream some more checks
1 parent b9ccb7b commit e3c61b7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/AudioExperiments/AudioSPDIF.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ class SPDIFStream : public AudioStreamX {
136136
/// Start with the provided parameters
137137
bool begin(SPDIFConfig cfg) {
138138
LOGD(LOG_METHOD);
139+
// Some validations to make sure that the config is valid
139140
if (!(cfg.channels == 1 | cfg.channels == 2)) {
140141
LOGE("Unsupported number of channels: %d", cfg.channels);
141142
return false;
142143
}
144+
if (info.bits_per_sample != 16) {
145+
LOGE("Unsupported bits per sample: %d - must be 16!",
146+
info.bits_per_sample);
147+
}
143148

144149
if (i2sOn) {
145150
i2s.end();
@@ -148,6 +153,8 @@ class SPDIFStream : public AudioStreamX {
148153
// initialize S/PDIF buffer
149154
spdif_buf_init();
150155
spdif_ptr = spdif_buf;
156+
157+
// Setup I2S
151158
int sample_rate = cfg.sample_rate * BMC_BITS_FACTOR;
152159
int bclk = sample_rate * I2S_BITS_PER_SAMPLE * I2S_CHANNELS;
153160
int mclk = (I2S_BUG_MAGIC / bclk) * bclk; // use mclk for avoiding I2S bug
@@ -186,9 +193,6 @@ class SPDIFStream : public AudioStreamX {
186193
LOGE("Unsupported bits per sample: %d - must be 16!",
187194
info.bits_per_sample);
188195
}
189-
if (info.channels != 2) {
190-
LOGE("Unsupported number of channels: %d - must be 2!", info.channels);
191-
}
192196
begin(cfg);
193197
}
194198

0 commit comments

Comments
 (0)