teensy4 Spdif

Status
Not open for further replies.

Dweezel

New member
I am having problem with spdif3 output
I have connected it to Hardware Test program
Spdif snc is detected at 44100 hz but there is no sound from waveform1 oscillator.

Please help.

sorry i'm new to this posting stuff hope its ok.

// 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);
delay(1000);

}




void loop() {
Serial.print("Beep #");
Serial.println(count);
count = count + 1;
waveform1.frequency(440);
waveform1.amplitude(0.9);
wait(250);
waveform1.amplitude(0);
wait(1750);
}

void wait(unsigned int milliseconds)
{
elapsedMillis msec=0;

while (msec <= milliseconds)
{

}
}
 
As I understand it, S/PDIF support is not in the current 1.48 for Teensy 4 (it is in Teensy 3.x).

Note, when posting code, please put it inside the CODE and /CODE tags. Use the '#' on the tool bar to create the tags.
 
Thank you Michael for for your sage advice on posting code I have taken note.
output_spdif.cpp and output_spdif2.cpp are for teensy 3.x.
output_spdif3.cpp is "rem hardware spdif for teensy4"
examination of code and pin assignment are correct for teensy4.
module is working as downstream spdif receiver is receiving snyc lock from teensy4 output.
 
Update got spdif working with whitenoise generator
I will look at waveforms apparent lack of activity and report back.

Code below
Code:
//@@@@@ CHUFFING PROGRAM @@@@@@

//Teensy4 spdif working test ok

//Dweezel 2019 


#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

const int led = 13;
int gofaster =300;

// GUItool: begin automatically generated code
AudioSynthNoiseWhite     noise1;         //xy=445,307
AudioOutputSPDIF3         spdif3;         //xy=750,309
AudioConnection          patchCord1(noise1, 0, spdif3, 0);
AudioConnection          patchCord2(noise1, 0, spdif3, 1);
// GUItool: end automatically generated code
void setup() 
{
  AudioMemory(10);
  
pinMode(led, OUTPUT);
  Serial.begin(115200);
  noise1.amplitude(0.5);
  delay(1000);

}

void loop() 
{
  noise1.amplitude(0.9);
  digitalWrite(led, HIGH);    // turn the LED off by making the voltage LOW
  wait(gofaster);
  if (gofaster>60)
     gofaster -=5;
  noise1.amplitude(0);
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  wait(gofaster+100);
}

void wait(unsigned int milliseconds)
{
  elapsedMillis msec=0;
  
  while (msec <= milliseconds) 
  {

  }
}
 
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) 
  {

  }
}
 
Status
Not open for further replies.
Back
Top