Teensy 4.0 S/PDIF3 glitches with Serial output

geekEE

Active member
I tried a simple program where I just generated a sine wave with AudioSynthWaveform and send it to AudioOutputSPDIF3. It works fine and I can receive the S/PDIF signal and see the sine wave just fine. However, then I added a delay(10) and a Serial.print('.') in a loop and I get a glitch on the sine wave every 10ms. It looks like 12 samples are from some other part of the waveform. glitch.jpg

I am using PlatformIO and viewing my print output on the built-in terminal, but I also tried using TeraTerm to view the serial output with the same results. When there is no terminal output, the sine wave looks good and when there is terminal output, the sine wave has glitches.

I also tried using Serial1 instead of Serial so that it prints to a real serial port instead of the USB serial port. The sine wave looks fine in that case, so it just seems to be the USB serial port.

Has anyone else run into this problem?
 
Here's my code:

#include <Arduino.h>
#include <Audio.h>

AudioSynthWaveform sinegen; // generate waveform for test
float SINE_LEVEL = 0.5; // sine amplitude (max is 1)
float SINE_FREQ = 100; // sine frequency [Hz]

AudioOutputSPDIF3 spdif1; // SPDIF3 is output on GPIO14
AudioConnection patchCord1(sinegen, 0, spdif1, 0);
AudioConnection patchCord2(sinegen, 0, spdif1, 1);

void setup() {
AudioMemory(60); // Audio connections require memory to work.
Serial.begin(115200); // the baud rate is ignored for USB serial
while (!Serial) {
// wait for Arduino Serial Monitor to be ready
}
sinegen.begin(SINE_LEVEL, SINE_FREQ, WAVEFORM_SINE); // generate sine wave
Serial.print("starting");

}


void loop() {
delay(10);
Serial.print('.');
}
 
Which version of Teensyduino are you using? There’s a fix for this issue in 1.57 beta 3.

Pro tip: using th code tags (# button) will make your code more readable on the forum.
 
I'm using Platformio with the framework-arduinoteensy v1.56 package. Any idea how I can get it to use the 1.57 beta 3? Can I install the beta 3 version into the Arduino IDE and then copy the changed files from the Arduino directories to the Platformio directories?
 
I don't use Platformio myself, so no real idea, but your suggestion of installing the Arduino beta then copying the required change across sounds viable. The only changed file you'd need to fix your stated issue this is output_spdif3.cpp.
 
I copied the 1.57 beta 3 output_spdif3.cpp file to overwrite the 1.56 version and then my S/PDIF output was glitch free.

Thanks so much!
 
Back
Top