Reporting back: The problem of spdif sound failing appears to be caused by thread lock between loop() and controls of the waveform1 object which seems to be running on a different thread using callback to the output flow for spdif.
The cure is to put yield(); after each control function call to the AudioStream object ie waveform1 to release the thread pool.
Controls seem more responsive and the one second delay after waveform1.begin(WAVE_SINE) is not required.
I hope this assists and improves projects using Audio Library objects and system.
Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
//
// Part 1-2: Test Hardware
//
// Simple beeping is pre-loaded on the Teensy, so
// it will create sound and print info to the serial
// monitor when plugged into a PC.
//
// This program is supposed to be pre-loaded before
// the workshop, so Teensy+Audio will beep when
// plugged in.
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=124,1810
AudioOutputSPDIF3 spdif3; //xy=326,1826
AudioConnection patchCord1(waveform1, 0, spdif3, 1);
AudioConnection patchCord2(waveform1, 0, spdif3, 0);
// GUItool: end automatically generated code
int count=1;
int a1history=0, a2history=0, a3history=0;
void setup()
{
AudioMemory(10);
Serial.begin(115200);
waveform1.begin(WAVEFORM_SINE);
yield();
// delay(1000);
}
void loop() {
Serial.print("Beep #");
Serial.println(count);
count = count + 1;
waveform1.frequency(440);
yield();
waveform1.amplitude(0.9);
yield();
wait(250);
waveform1.amplitude(0);
yield();
wait(1750);
}
void wait(unsigned int milliseconds)
{
elapsedMillis msec=0;
while (msec <= milliseconds)
{
}
}