Decoding S/PDIF With A Microcontroller Brings A Few Headaches

The average punter shunts audio around with analog 3.5 mm cables, RCA jacks, or Bluetooth on a regular basis. A useful standard that hasn’t really bothered most of us is S/PDIF, standing for Sony/Phillips Digital Interface. It’s a useful way to pump digital audio around over copper cables or optic fiber. [Andrew Jeddeloh] got curious about the standard after contemplating some long cable runs in his home, and decided to try decoding it.

The target for [Andrew]’s development efforts was the STM32L476 Discovery, which had no SPDIF decoding hardware on board. Instead, [Andrew] tinkered with the peripherals he had to see what would work. In the end, a cavalcade of internal timers were daisy chained to allow the microcontroller to recover a clock from the self-clocked S/PDIF signal. This was then used to generate a clock to sync up the onboard SPI hardware to actually read in the 16-bit PCM data from the S/PDIF signal.

[Andrew]’s original broader plan was to pipe the S/PDIF data to the onboard I2S DAC, though he struggled manipulating the remaining resources on the STM chip to do so successfully. Anyone wishing to have a crack can take a look at [Andrew]’s code over on GitHub. If completed, the STM32L476 would become a useful analog endpoint for S/PDIF streams, allowing you to pump tunes digitally over long distances without signal degradation. If you know the key to getting it done, sound off in the comments! Alternatively, if you need to get up and running more quickly, the Teensy platform has you covered!

An Arduino And A CD-ROM Drive Makes A CD Player

In an age of streaming media it’s easy to forget the audio CD, but they still remain as a physical format from the days when the “Play” button was not yet the “Pay” button. A CD player may no longer be the prized possession it once was, but it’s still possible to dabble in the world of 120 mm polycarbonate discs if you have a fancy for it. It’s something [Daniel1111] has done with his Arduino CD player, which uses the little microcontroller board to control a CD-ROM drive via its IDE bus.

The project draws heavily from the work of previous experimenters, notably ATAPIDUINO, but it extends them by taking its audio from the drive’s S/PDIF output. A port expander drives the IDE interface, while a Cirrus Logic WM8805 S/PDIF transceiver handles the digital audio and converts it to an I2S stream. That in turn is fed to a Texas Instruments PCM5102 DAC, which provides a line-level audio output. All the code and schematic can be found in a GitHub repository.

To anyone who worked in the CD-ROM business back in the 1990s this project presses quite a few buttons, though perhaps not enough to dig out all those CDs again. It would be interesting to see whether the I2S stream could be lifted from inside the drive directly, or even if the audio data could be received via the IDE bus. If you’d like to know a bit more about I2S , we have an article for you.

Teensy Adds S/PDIF To Library

With Arduino library support on an ARM Cortex M4 processor, it’s no surprise that we’re fans of the Teensy 3.1. And lately, [Paul Stoffregen] has been building out the Audio Library for this platform, making it even more appealing to the synth / audio geeks among us. And now, with just the addition of a highfalutin LED and some software, the Teensy can output digital audio over optical fiber.

S/PDIF, and more specifically optical TOSLINK, uses LED light sent down an optical fiber to encode audio data. The advantage of this over any voltage-level signals (like with regular wires) is that the source and destination devices aren’t electrically connected at all, which gets rid of the dreaded ground loop hum and any RF interference.

An S/PDIF audio data stream is a bit complex, but if you’re interested [Micah Scott] has a fantastic dissection of it up on her blog. Of course, you don’t have to know anything about any of that to simply use S/PDIF with the Teensy Audio Library.

We love open source hardware and software because of the collaborations that make ultra-rapid development of niche stuff like this possible. You can follow along with the development of the Teensy’s S/PDIF capabilities on the PJRC forum. Contributor [Frank B] modestly claims that “everything was already on the internet”, but that doesn’t make it any less cool that they got from zero to working library in a few weeks. (And note the clever use of a precomputed lookup table for speed.)

LED_TOSLINK2On the hardware side, [Paul] has posted up his adapter board for a cheap, but very professional looking, optical TOSLINK sender. But if you’re feeling ghetto, you can simply use a red LED pointed just right into the optical cable.

The end result? Lossless transmission of CD-quality audio from an Arduino-esque microcontroller, sent on a beam of light, for less than the cost of a latté.

From Reference Design To USB Sound Card

[Entropia] decided to try his hand at rolling is own sound card. He picked out a DAC chip, started his prototyping by studying the reference design from the datasheet, then went through several iterations to arrive at this working model.

He chose to base the board around the PCM2706. It’s a digital to analog converter that has built-in USB support; perfect for his needs. It’s got a headphone amplifier, but is also capable of putting out S/PDIF signals for a digital amplifier to pick up and use. Not bad for a part that can be had for right around eight bucks.

The first PCB he designed had a few electrical and footprint errors. But he was able to get it to run by adding some point-to-point jumpers, and bending the legs of his capacitors to fit the board area. With those issued accounted for he ordered a second batch of boards. These went together nicely, but the headphone output was incredibly loud. Turns out the filtering circuit had the wrong resistor and capacitor values. Changing them around, and swapping the audio output so that the correct channels were patched to the audio jack brings it to the first release version seen above.

SPDIF Passthrough Lets You Digitally Manipulate The Audio

[Mike Field] took what he had learned with a few past projects and combined them to make this FPGA-based SPDIF audio pass-through. In order to get the SPDIF signal ready for the FPGA he needed a few components to use for level conversion. Once everything was connected he used a first in first out (FIFO) buffer to ensure that the outgoing bitrate is the same as the input, while still allowing enough time for the FPGA to do some digital manipulation.

This reminds us of the NeTV, which is an HDMI pass-through device. That one allows you to overlay your own video information to any TV that has an HDMI port. This would allow you patch into any audio system that’s using SPDIF, letting you inject your own audio, such as a paging system in a public lobby, or the ringing of a phone when you get a call, or to create your own sounds.

We like his overhand knot cable management system to keep those jumper wires from becoming too much of a mess on the breadboard.

FPGA Generated SPDIF Output

[Mike Field] just finished implementing SPDIF generation on an FPGA. SPDIF is an industry standard for transmitting digital audio signals; the acronym stands for Sony/Philips Digital Interconnect Format. It’s been around for more than a decade and since it’s found on most home-audio equipment, building an SPDIF output into your projects may be quite a desirable feature. [Mike] mentions several ideas for this functionality like building high-end test equipment, or providing a high-quality output for electronic instruments.

He first jumped into analyzing the specification in order to determine the hardware requirements. Due to some issues with jitter, he found it necessary to use a 100 MHz clock signal. This pushes the jitter down to +/- 5ns of jitter, which he concedes may raise the hackles of audio purists, but does satisfy the published standard. Output requires just one pin of the FPGA and the five components seen above. A hex inverter (74HC04) voltage divider, capacitor, and RCA connector transmit the 0.5V signal to your audio-receiver of choice. Of course, since TOSLINK fiber optic connectors use the same protocol, you could redesign the output and make this an optical connection.

Digital Audio On The Parallax Propeller

[Beth] had the idea for transmitting digital audio over S/PDIF on a Propeller a few years ago, but only just got around to a writeup. For that, we thank her.

The writeup has a marvelous walkthrough of the S/PDIF protocol and the problems associated with with generating the signal. S/PDIF is a relatively resource-intensive protocol – the signal is clocked at 64x the audio sample rate. That signal is doubled for biphase mark code, keeping everything in sync. [Beth] says the microcontroller would neet at least 24 MIPS of processing power just to generate the S/PDIF signal – processing audio would be another task altogether. Because of the processing power needed, and the weird clock rates needed, [Beth] decided to go with the Propeller. The implementation uses only one core of the Propeller, leaving another seven cores available for sound synthesis or even a visualization over VGA.

[Beth] admits this could be done with just about any microcontroller (although it would need to be clocked at a multiple of 4.096 MHz for a 32kHz audio stream), but we really appreciate the work that went into bit-banging this signal.

Video of [Nick] at Gadget Gangster playing around with digital audio on a Propeller after the break.

Continue reading “Digital Audio On The Parallax Propeller”