SPDIF (digital audio) output demo
scanlime
Posts: 106
Hi,
I've been experimenting with generating SPDIF digital audio signals from the propeller. If you aren't familiar with SPDIF, it's the protocol used by the optical and coax digital audio inputs on all modern stereo systems and home theater receivers.
It's a pretty demanding signal: 6 megabits, precise sampling rate, manchester-like "Biphase Mark" encoding. But, the Propeller is up to the task The biphase encoding is done using a pretty simple unrolled loop (2 instructions per bit) while the cog's video generator simultaneously clocks out the signal at the proper rate, as determined by the CTRA PLL.
The net result: You can get 48 KHz 16-bit stereo audio, reproduced in digital clarity, using only a Propeller and an LED.
Attached is my "spdifOut" object, and two demos:
- A modified version of HSS, with 48 KHz SPDIF output.
- A simple WAV file player which plays CD-quality audio from an SD card in real-time.
For the HSS demo, all you need is a Propeller, an LED, and of course some kind of audio equipment that has a TOSLINK (optical digital) input. I just used one of the LEDs on the PropRPM board, and pointed the exposed end of a TOSLINK cable at it. For the WAV demo, you'll also need an SD card with some audio on it.
I tested this with an Onkyo receiver, as well as a cheap USB audio adapter based on the PCM2902 chip. Works fine for me, but YMMV. Please be sure to test at a low volume, to avoid damaging your speakers if anything is wrong.
--Micah
I've been experimenting with generating SPDIF digital audio signals from the propeller. If you aren't familiar with SPDIF, it's the protocol used by the optical and coax digital audio inputs on all modern stereo systems and home theater receivers.
It's a pretty demanding signal: 6 megabits, precise sampling rate, manchester-like "Biphase Mark" encoding. But, the Propeller is up to the task The biphase encoding is done using a pretty simple unrolled loop (2 instructions per bit) while the cog's video generator simultaneously clocks out the signal at the proper rate, as determined by the CTRA PLL.
The net result: You can get 48 KHz 16-bit stereo audio, reproduced in digital clarity, using only a Propeller and an LED.
Attached is my "spdifOut" object, and two demos:
- A modified version of HSS, with 48 KHz SPDIF output.
- A simple WAV file player which plays CD-quality audio from an SD card in real-time.
For the HSS demo, all you need is a Propeller, an LED, and of course some kind of audio equipment that has a TOSLINK (optical digital) input. I just used one of the LEDs on the PropRPM board, and pointed the exposed end of a TOSLINK cable at it. For the WAV demo, you'll also need an SD card with some audio on it.
I tested this with an Onkyo receiver, as well as a cheap USB audio adapter based on the PCM2902 chip. Works fine for me, but YMMV. Please be sure to test at a low volume, to avoid damaging your speakers if anything is wrong.
--Micah
zip
28K
Comments
repeat that...
WOW!!!
You coded an SPDIF digital audio player in the Prop?! Man, I wish I had a system to test this out on.
WOW!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.sxmicro.com - a blog·exploring the SX micro
www.tdswieter.com
I think my Delta-44 sound card has SPDIF, I suppose that would do for testing. I think that an ADI Blackfin DSP board I've got has it , as well.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Looks like it does surround-sound too!
I just tried playing some of the WAV files with AC3 (Dolby Digital) and DTS content from www.kellyindustries.com/sounds.html. Success!
I did have to swap the left and right channel in spdifOut, by inverting the four shl/shr instructions that unpack the audio. I'm not sure whether the channels are just backwards in my code, or whether this is because I'm not parsing the WAV header at all, so my data might be totally misaligned. I tried adding the "NON_AUDIO" flag, to perhaps tell older receivers that this isn't uncompressed audio.. but it seems like receivers (at least the Sony that I tried it on) will totally ignore an SPDIF signal if it has this bit set. The receiver is perfectly happy to magically reinterpret a 44.1 KHz PCM stream as DTS or AC3 if it looks like compressed data.
I haven't noticed this problem yet with AC3 audio, but with DTS the receiver occasionally (every 10 seconds or so) momentarily loses a lock on my signal, and the audio cuts out for a fraction of a second. I have two theories about this:
So, this is kind of neat, but I still have no idea what it would be useful for. I just wanted to see if it could be done. I wonder if it's possible to do some kind of minimal AC3 encoding on the Propeller, for real non-prerecorded surround sound output? Maybe it's possible to build an HSS-style synthesizer, but entirely in the frequency domain?
--Micah
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.sxmicro.com - a blog·exploring the SX micro
www.tdswieter.com
Assuming the Prop is fast enough to do all the bitstream packing and CRC operations in real-time, the tricky part would be writing a useful synthesizer that works in the frequency domain.
Theoretically SPDIF can do multi-channel PCM audio, but I don't know that any actual consumer hardware supports uncompressed surround-sound. The required SPDIF bit rate would go through the roof...
--Micah
According to Wikipedia, it isn't uncompressed- it's a regular DTS stream (for backwards compatibility) plus an additional stream which encodes the difference between the compressed stream and the original. It's lossless, but it isn't uncompressed. Compressing a DTS Master Audio signal would be at least as hard as compressing a regular DTS signal.
Uncompressed PCM would be easy, but I don't know if any real audio receivers support it. I think the S/PDIF spec allows any number of channels (you can replicate the secondary channel subframe any number of times) but in practice nobody seems to use anything but 2-channel PCM.
And again, the data rate would be pretty astronomical. With my current code, I can't *quite* do 96 KHz stereo audio. (I think the max I've tried it at is about 90 KHz) Any kind of multichannel audio would be out of the question unless you used a really low sampling rate.
But hey.. if we want to do high quality audio on the Prop, we could start by experimenting with higher sample rate and higher precision synthesizers for normal 16-bit stereo audio. I can pipe out pristine digital audio from HSS at 48 KHz, but it's still generating that audio using tiny 8-bit wavetables [noparse]:)[/noparse]
--Micah
How about something like 4ch at 32kHz?
What about mp3 decompression from those SD cards? Making your own personalised mp3 player. [noparse]:)[/noparse]
Evan
Even 4ch at 32kHz is a little faster than I've been able to get my object to run... plus there's the fact that I don't know of any receivers that do multi-channel PCM.
Real-time MP3 decoding on the Prop itself is not likely to be possible. Many other threads have discussed this. There are cheap co-processor chips that decode MP3s.. but where's the fun in that?
This project was just a challenge to see if it was possible to output a high-quality digital audio signal using nothing but the Propeller. I still don't know what else, if anything, it's useful for [noparse];)[/noparse]
--Micah
Would making a SPDIF, mixer be a hard thing to do? Many say expensive hardware is needed to mix two spdif 44.1khz, stereo uncompressed signals into one single output?
You mentioned making a synth, how about starting by combining your spdif object with the singing demo spin object?
Wouldn't this sound better than the singing demo that outputs to the props pins? Due to the sound being sent digitally to a higher end device that can render the audio with much better hardware?
I am interested in looking into all this but have no idea how complicated these ideas are, micah, perhaps you can comment a bit on them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
Post Edited (BPM) : 6/1/2009 12:49:29 PM GMT
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Post Edited (Leon) : 6/1/2009 1:48:51 PM GMT
What I did not know was that the propeller can output such a signal. This should go to the Timers and Counters Application note just to show how a clever thought algorithm together with the serializer in the video circuitry can be used as output for other than video. We really need a de-serializer for input now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit the home of pPropQL, pPropQL020 and OMU for the pPropQL/020 at omnibus.uni-freiburg.de/~rp92
That's like 9.2MHz bit rate.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
I thought it had something to do with the video hardware / pll? I guess I need to read more on exactly how the propeller is going about generating the video and audio signals.
But perhaps the benefit for us all is to allow us to understand the
nature of video and audio without going out and buying a dsp fpga combo.
So really, we can only generate stereo spdif signals, and ones on the fly only.
I'll take it.
So...
I am now off to code, and learn from all your examples here to add to the PILE!
[noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
One, I was not able to get "beuler.hwav" to play back properly, but the .hmus files sound great. Is there something wrong with the .hwav player? (yes the .hwav file is compiling proplerly) and yes i turned the .hwav player on, and disabled the .hmus player/file loader
Another question,
This comment...
"Note that we don't actually run the HSS engine at 44.1 kHz, it's still running at the default 32 kHz.
We end up duplicating those samples as necessary to generate a 44.1 kHz output signal."
Why isn't the HSS engine run at 44.1khz or 48khz? If were outputting the signal as 48khz, shouldn't the engine run at the same sample rate?, instead of duplicating samples?
Is this due to prop limitations, or the fact that the engine needs to be recoded to get higher khz?
I am still amazed that this little 7$ chip is putting out digital audio which is also being generated on the fly in the same chip.
And my last question.
Can other cogs, or hub interaction cause minor (audible)speedups and slowdowns in the playback of .hmus files? (if you play fl-sytrus.hmus, you will notice around 3 seconds into the playback, the bassline drops a bit, and the tempo seems to also slow down a bit when more sound samples get mixed into the playback.... I wonder if this is due to code, or is the way the .hmus file is made?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
Post Edited (BPM) : 6/3/2009 10:27:57 PM GMT