diff --git a/_audio_s_p_d_i_f_8h_source.html b/_audio_s_p_d_i_f_8h_source.html index 562c30df7a..7d5ef92dcb 100644 --- a/_audio_s_p_d_i_f_8h_source.html +++ b/_audio_s_p_d_i_f_8h_source.html @@ -192,119 +192,122 @@
153 
154  // Setup I2S
155  int sample_rate = cfg.sample_rate * BMC_BITS_FACTOR;
-
156  int bclk = sample_rate * I2S_BITS_PER_SAMPLE * I2S_CHANNELS;
-
157  int mclk = (I2S_BUG_MAGIC / bclk) * bclk; // use mclk for avoiding I2S bug
-
158 
-
159  I2SConfig i2s_cfg;
-
160  i2s_cfg.sample_rate = sample_rate;
-
161  i2s_cfg.channels = cfg.channels;
-
162  i2s_cfg.i2s_format = I2S_STD_FORMAT;
-
163  i2s_cfg.bits_per_sample = I2S_BITS_PER_SAMPLE;
-
164  i2s_cfg.pin_ws = -1;
-
165  i2s_cfg.pin_bck = -1;
-
166  i2s_cfg.pin_data = cfg.pin_data;
-
167 #ifdef ESP32
-
168  i2s_cfg.use_apll = true;
-
169  i2s_cfg.fixed_mclk = mclk;
-
170 #endif
-
171  i2s.begin(i2s_cfg);
-
172  i2sOn = true;
-
173  return i2sOn;
-
174  }
-
175 
-
176  void end() {
-
177  TRACED();
-
178  i2s.end();
-
179  i2sOn = false;
-
180  }
-
181 
-
183  void setAudioInfo(AudioInfo info) {
-
184  TRACED();
-
185  if (info.bits_per_sample != 16) {
-
186  LOGE("Unsupported bits per sample: %d - must be 16!",
-
187  info.bits_per_sample);
-
188  }
-
189  if (cfg.bits_per_sample != info.bits_per_sample
-
190  || cfg.channels != info.channels
-
191  || cfg.sample_rate != info.sample_rate
-
192  || !i2sOn) {
-
193  cfg.bits_per_sample = info.bits_per_sample;
-
194  cfg.channels = info.channels;
-
195  cfg.sample_rate = info.sample_rate;
-
196  begin(cfg);
-
197  }
-
198  }
-
199 
-
201  SPDIFConfig defaultConfig() {
-
202  SPDIFConfig c;
-
203  return c;
-
204  }
-
205 
-
207  size_t write(const uint8_t *src, size_t size) {
-
208  if (!i2sOn) return 0;
-
209  const uint8_t *p = src;
-
210  size_t result = 0;
-
211 
-
212  while (p < (uint8_t *)src + size) {
-
213  // convert PCM 16bit data to BMC 32bit pulse pattern
-
214  if (cfg.channels == 2) {
-
215  *(spdif_ptr + 1) =
-
216  (uint32_t)(((bmc_tab[*p] << 16) ^ bmc_tab[*(p + 1)]) << 1) >> 1;
-
217  p += 2;
-
218  } else {
-
219  // must be one channels -> use the same value for both
-
220  *(spdif_ptr + 1) =
-
221  (uint32_t)(((bmc_tab[*p] << 16) ^ bmc_tab[*(p)]) << 1) >> 1;
-
222  p++;
-
223  }
-
224  result += 2;
-
225  spdif_ptr += 2; // advance to next audio data
-
226 
-
227  if (spdif_ptr >= &spdif_buf[SPDIF_BUF_ARRAY_SIZE]) {
-
228  // set block start preamble
-
229  ((uint8_t *)spdif_buf)[SYNC_OFFSET] ^= SYNC_FLIP;
-
230 
-
231  i2s.write((uint8_t *)spdif_buf, sizeof(spdif_buf));
-
232  spdif_ptr = spdif_buf;
-
233  }
-
234  }
-
235 
-
236  return result;
-
237  }
+
156  if (sample_rate==0){
+
157  TRACEE();
+
158  return false;
+
159  }
+
160  int bclk = sample_rate * I2S_BITS_PER_SAMPLE * I2S_CHANNELS;
+
161  int mclk = (I2S_BUG_MAGIC / bclk) * bclk; // use mclk for avoiding I2S bug
+
162 
+
163  I2SConfig i2s_cfg;
+
164  i2s_cfg.sample_rate = sample_rate;
+
165  i2s_cfg.channels = cfg.channels;
+
166  i2s_cfg.i2s_format = I2S_STD_FORMAT;
+
167  i2s_cfg.bits_per_sample = I2S_BITS_PER_SAMPLE;
+
168  i2s_cfg.pin_ws = -1;
+
169  i2s_cfg.pin_bck = -1;
+
170  i2s_cfg.pin_data = cfg.pin_data;
+
171 #ifdef ESP32
+
172  i2s_cfg.use_apll = true;
+
173  i2s_cfg.fixed_mclk = mclk;
+
174 #endif
+
175  i2sOn = i2s.begin(i2s_cfg);
+
176  return i2sOn;
+
177  }
+
178 
+
179  void end() {
+
180  TRACED();
+
181  i2s.end();
+
182  i2sOn = false;
+
183  }
+
184 
+
186  void setAudioInfo(AudioInfo info) {
+
187  TRACED();
+
188  if (info.bits_per_sample != 16) {
+
189  LOGE("Unsupported bits per sample: %d - must be 16!",
+
190  info.bits_per_sample);
+
191  }
+
192  if (cfg.bits_per_sample != info.bits_per_sample
+
193  || cfg.channels != info.channels
+
194  || cfg.sample_rate != info.sample_rate
+
195  || !i2sOn) {
+
196  cfg.bits_per_sample = info.bits_per_sample;
+
197  cfg.channels = info.channels;
+
198  cfg.sample_rate = info.sample_rate;
+
199  begin(cfg);
+
200  }
+
201  }
+
202 
+
204  SPDIFConfig defaultConfig() {
+
205  SPDIFConfig c;
+
206  return c;
+
207  }
+
208 
+
210  size_t write(const uint8_t *src, size_t size) {
+
211  if (!i2sOn) return 0;
+
212  const uint8_t *p = src;
+
213  size_t result = 0;
+
214 
+
215  while (p < (uint8_t *)src + size) {
+
216  // convert PCM 16bit data to BMC 32bit pulse pattern
+
217  if (cfg.channels == 2) {
+
218  *(spdif_ptr + 1) =
+
219  (uint32_t)(((bmc_tab[*p] << 16) ^ bmc_tab[*(p + 1)]) << 1) >> 1;
+
220  p += 2;
+
221  } else {
+
222  // must be one channels -> use the same value for both
+
223  *(spdif_ptr + 1) =
+
224  (uint32_t)(((bmc_tab[*p] << 16) ^ bmc_tab[*(p)]) << 1) >> 1;
+
225  p++;
+
226  }
+
227  result += 2;
+
228  spdif_ptr += 2; // advance to next audio data
+
229 
+
230  if (spdif_ptr >= &spdif_buf[SPDIF_BUF_ARRAY_SIZE]) {
+
231  // set block start preamble
+
232  ((uint8_t *)spdif_buf)[SYNC_OFFSET] ^= SYNC_FLIP;
+
233 
+
234  i2s.write((uint8_t *)spdif_buf, sizeof(spdif_buf));
+
235  spdif_ptr = spdif_buf;
+
236  }
+
237  }
238 
-
239  protected:
-
240  bool i2sOn = false;
-
241  SPDIFConfig cfg;
-
242  I2SStream i2s;
-
243 
-
244  // initialize S/PDIF buffer
-
245  void spdif_buf_init(void) {
-
246  TRACED();
-
247  size_t i;
-
248  uint32_t bmc_mw = BMC_W;
-
249 
-
250  for (i = 0; i < (size_t)SPDIF_BUF_ARRAY_SIZE; i += 2) {
-
251  spdif_buf[i] = bmc_mw ^= BMC_MW_DIF;
-
252  }
-
253  }
-
254 };
-
255 
-
256 using SPDIFStream = SPDIFOutput;
-
257 
-
258 } // namespace audio_tools
+
239  return result;
+
240  }
+
241 
+
242  protected:
+
243  bool i2sOn = false;
+
244  SPDIFConfig cfg;
+
245  I2SStream i2s;
+
246 
+
247  // initialize S/PDIF buffer
+
248  void spdif_buf_init(void) {
+
249  TRACED();
+
250  size_t i;
+
251  uint32_t bmc_mw = BMC_W;
+
252 
+
253  for (i = 0; i < (size_t)SPDIF_BUF_ARRAY_SIZE; i += 2) {
+
254  spdif_buf[i] = bmc_mw ^= BMC_MW_DIF;
+
255  }
+
256  }
+
257 };
+
258 
+
259 using SPDIFStream = SPDIFOutput;
+
260 
+
261 } // namespace audio_tools
audio_tools::AudioStream
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition: AudioStreams.h:47
audio_tools::I2SConfig
configuration for all common i2s settings
Definition: I2SConfig.h:52
audio_tools::I2SStream
We support the Stream interface for the I2S access. In addition we allow a separate mute pin which mi...
Definition: I2SStream.h:32
audio_tools::I2SStream::write
virtual size_t write(const uint8_t *buffer, size_t size)
Writes the audio data to I2S.
Definition: I2SStream.h:92
audio_tools::I2SStream::end
void end()
Stops the I2S interface.
Definition: I2SStream.h:67
audio_tools::SPDIFOutput
Output as 16 bit stereo SPDIF on the I2S data output pin.
Definition: AudioSPDIF.h:120
-
audio_tools::SPDIFOutput::defaultConfig
SPDIFConfig defaultConfig()
Provides the default configuration.
Definition: AudioSPDIF.h:201
+
audio_tools::SPDIFOutput::defaultConfig
SPDIFConfig defaultConfig()
Provides the default configuration.
Definition: AudioSPDIF.h:204
audio_tools::SPDIFOutput::~SPDIFOutput
virtual ~SPDIFOutput()
destructor
Definition: AudioSPDIF.h:126
-
audio_tools::SPDIFOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Change the audio parameters.
Definition: AudioSPDIF.h:183
+
audio_tools::SPDIFOutput::setAudioInfo
void setAudioInfo(AudioInfo info)
Change the audio parameters.
Definition: AudioSPDIF.h:186
audio_tools::SPDIFOutput::begin
bool begin()
Starting with default settings.
Definition: AudioSPDIF.h:129
audio_tools::SPDIFOutput::SPDIFOutput
SPDIFOutput()=default
default constructor
audio_tools::SPDIFOutput::begin
bool begin(SPDIFConfig config)
Start with the provided parameters.
Definition: AudioSPDIF.h:132
-
audio_tools::SPDIFOutput::write
size_t write(const uint8_t *src, size_t size)
Writes the audio data as SPDIF to the defined output pin.
Definition: AudioSPDIF.h:207
+
audio_tools::SPDIFOutput::write
size_t write(const uint8_t *src, size_t size)
Writes the audio data as SPDIF to the defined output pin.
Definition: AudioSPDIF.h:210
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:9
audio_tools::AudioInfo
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:48
audio_tools::SPDIFConfig
SPDIF configuration.
Definition: AudioSPDIF.h:103