phillipps76
Member
can anyone give me a lead on how to use the SPDIF input for the audio board? I am trying with a RX147L and have it wired to ground, vcc and pin15 running the code below.
I have tried it with a .1uf cap between gnd and vcc as the spec sheet says. It can't be this hard but I'm doing something wrong. I tried two different 147L adaptors.
thanks for any hints!
I have tried it with a .1uf cap between gnd and vcc as the spec sheet says. It can't be this hard but I'm doing something wrong. I tried two different 147L adaptors.
thanks for any hints!
C:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Audio system objects (SPDIF-in on pin 15 / RX)
AudioInputSPDIF3 spdifIn; // Optical/coax SPDIF input
AudioAnalyzePeak peakL, peakR; // Peak detectors
AudioConnection patchCord1(spdifIn, 0, peakL, 0);
AudioConnection patchCord2(spdifIn, 1, peakR, 0);
// Settings
const float ledThreshold = 0.001f; // Lower to show very small signals
const int ledPin = 13; // Teensy 4.0 built-in LED
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
while (!Serial && millis() < 4000) {
// wait for Serial Monitor to attach (optional)
}
AudioMemory(20);
Serial.println("Teensy SPDIF (pin 15) peak monitor");
}
void loop() {
uint32_t now = millis();
// Heartbeat even if no audio blocks are ready
static uint32_t lastStatus = 0;
if (now - lastStatus > 1000) {
lastStatus = now;
Serial.print("SPDIF lock=");
Serial.print(spdifIn.pllLocked() ? "1" : "0");
Serial.print(" sr=");
Serial.println(spdifIn.sampleRate());
}
if (peakL.available() && peakR.available()) {
float L = peakL.read(); // 0.0–1.0
float R = peakR.read();
bool active = (L > ledThreshold) || (R > ledThreshold);
digitalWrite(ledPin, active ? HIGH : LOW);
static uint32_t lastPrint = 0;
if (now - lastPrint > 100) { // print every ~100 ms
lastPrint = now;
Serial.print("Peak L: "); Serial.print(L, 4);
Serial.print(" R: "); Serial.println(R, 4);
}
}
}
Last edited: