I've made a decoder for receiving S/PDIF on an ESP32
github.com
How it works:
It uses RMT to capture raw pulse timings from a GPIO pin. It shoves these into a ringbuf that a processing thread pulls from.
The processing thread is ran on it's own core and converts from the RMT timings
The processing thread waits for a preamble it recognizes and decodes the SPDIF preample + PCM data from the input frame
It then waits until it has L,R samples then writes them to another ringbuf in sync to ensure channel sync
Usage:
Import spdif_in.h
Call spdif_receiver_init(<gpio pin>) to initialize the receiver, this will start receiving
Call spdif_receiver_read(buffer, size) to read data in from SPDIF
It runs the decoding thread on core 1 and is only just able to keep up on an esp32s3 set to 240MHz. I would recommend not running any other tasks on the same core and ensuring your CPU is set to full speed in idf.py menuconfig
With this I am able to decode and transmit spdif received from two different toslink devices (a TV, and a USB -> Toslink cable) just fine. I haven't tested on anything else.
I figured this might be a place where people would be interested in this.
esp32-scream-receiver/main/sender/spdif_in at spdif · netham45/esp32-scream-receiver
ESP32/ESP32-S3 Scream Sender/Receiver that outputs over SPDIF or to a USB UAC 1.0 DAC, or receives as a USB UAC 1.0 sound card and sends over the network - netham45/esp32-scream-receiver
How it works:
It uses RMT to capture raw pulse timings from a GPIO pin. It shoves these into a ringbuf that a processing thread pulls from.
The processing thread is ran on it's own core and converts from the RMT timings
The processing thread waits for a preamble it recognizes and decodes the SPDIF preample + PCM data from the input frame
It then waits until it has L,R samples then writes them to another ringbuf in sync to ensure channel sync
Usage:
Import spdif_in.h
Call spdif_receiver_init(<gpio pin>) to initialize the receiver, this will start receiving
Call spdif_receiver_read(buffer, size) to read data in from SPDIF
It runs the decoding thread on core 1 and is only just able to keep up on an esp32s3 set to 240MHz. I would recommend not running any other tasks on the same core and ensuring your CPU is set to full speed in idf.py menuconfig
With this I am able to decode and transmit spdif received from two different toslink devices (a TV, and a USB -> Toslink cable) just fine. I haven't tested on anything else.
I figured this might be a place where people would be interested in this.
Last edited: