ESP32 Decodes S/PDIF Like A Boss (Or Any Regular Piece Of Hi-Fi Equipment)

S/PDIF has been around for a long time; it’s still a really great way to send streams of digital audio from device A to device B. [Nathan Ladwig] has got the ESP32 decoding SPDIF quite effectively, using an onboard peripheral outside its traditional remit.

On the ESP32, the Remote Control Transceiver (RMT) peripheral was intended for use with infrared transceivers—think TV remotes and the like. However, this peripheral is actually quite flexible, and can be used for sending and receiving a range of different signals. [Nathan] was able to get it to work with S/PDIF quite effectively. Notably, it has no defined bitrate, which allows it to work with signals of different sample rates quite easily. Instead, it uses biphase mark code to send data. With one or two transitions for each transmitted bit, it’s possible to capture the timing and determine the correct clock from the signal itself.

[Nathan] achieved this feat as part of his work to create an ESP32-based RTP streaming device. The project allows an ESP32 to work as a USB audio device or take an S/PDIF signal as input, and then transmitting that audio stream over RTP to a receiver which delivers the audio at the other end via USB audio or as an SPDIF output. It’s a nifty project that has applications for anyone that regularly finds themselves needing to get digital audio from once place to another. It can also run a simple visualizer, too, with some attached LEDs.

It’s not the first time we’ve seen S/PDIF decoded on a microcontroller; it’s quite achievable if you know what you’re doing. Meanwhile, if you’re cooking up your own digital audio hacks, we’d love to hear about it. Digitally, of course, because we don’t accept analog phone calls here at Hackaday. Video after the break.

5 thoughts on “ESP32 Decodes S/PDIF Like A Boss (Or Any Regular Piece Of Hi-Fi Equipment)

  1. First SPDIF is not a great interface for audio as the master clock has to train on the incoming signal which means it varies due to the way it handles flow control (i.e the sending and receiving not having the same clock). USB or UAC1/2 would work better if the sending is done with the asynchronous method which has a feedback pipe to the sender to control the flow control and the receiving side using a fixed instead of varying clock. Most NXP i.MX6 & 8 have good SPDIF receivers and transmitters. Also if we go back to the beginning of SPDIF, Philips created that to test CD players that were closed box. A known CD was placed in the drive a 3 connection was connected to the CD player (R&L analog & SPDIF output). There the test rig could verify the digital and analog content. Original SPDIF was 75 ohms on an RCA connector… a connector that cannot be 75 ohms!

    1. I’m doing clockless recovery by using the RMT peripheral to measure widths between transitions coupled with a state machine that converts those transitions back into a binary stream. I build a histogram of pulses and use it to identify the pulse lengths for the current signal, and from there I can build a state machine to track what it’s currently doing that outputs a binary stream. Looked at it this way spdif has short and medium pulses used for BMC and long pulses that it uses for it’s preambles that violate BMC decoding. Roughly, short short = 0b, medium = 1b, long = frame preamble for resynchronization

      short is .5t, medium is 1t, long is 1.5t where t is the length of one BMC bit

  2. It’s wild how perfectly timed this article hit. I actually had to make sure it was posted recently rather than just my algorithms dragging it up at the right time (while pooping obviously) I’ve spent the past few days searching for a way to turn a microcontroller into a guitar fx pedal for my 3d printed acoustic guitar which I’ve added 4 piezo for pickups that I’m super pleased at myself for performing this super basic task correctly enough to get signal. I want to give it an Arduino controlled led show too because it’s printed in glow in the dark filament that works great with black light leds. But now that I see this telling me I can use one of my esp32s to get the basic functionality of an audio device, or perhaps Daisy chain for multiple devices/effects? I don’t know! I’m so confused and scared😂 I’ve got choice paralysis! lol I kid, I’ll probably continue on with this pico fx route. I have all the parts arriving today and all that. But for the next audio project?!?! So many erotic choices! I’m especially intrigued about how I could integrate the esp32 special dedicated protocol for wireless signals into a sound making device.

Leave a Reply to JimothyCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.