SPDIF (digital audio) output demo

scanlimescanlime Posts: 106
edited June 2009 in Propeller 1 Vote Up0Vote Down
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 smile.gif 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

Comments

  • 21 Comments sorted by Date Added Votes
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,605
    edited July 2008 Vote Up0Vote Down
    WOW!

    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
    Timothy D. Swieter, P.E.
    www.brilldea.com :RGB LED Ribbon, LED Painter II-8, PolkaDOT-51 and other gadgets for artistic lighting displays
    http://www.brilldea.com/Prod_Clearance.html :Need to make room for new ideas!
    www.tdswieter.com
  • LeonLeon Posts: 7,617
    edited July 2008 Vote Up0Vote Down
    Very impressive!

    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
    Leon Heller
    G1HSM
  • scanlimescanlime Posts: 106
    edited July 2008 Vote Up0Vote Down
    Thanks!

    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:
    • The DTS WAV file includes some additional chunks of data (keyframes??) every so often, and my demo isn't smart enough to skip them.
    • The receiver's buffer is over/under-running, because my 44.1 kHz clock isn't accurate enough. Maybe the spdifOut module should be constantly tweaking the PLL frequency in order to get higher long-term frequency accuracy? (This would be kind of like what the utility companies do, periodically changing the power line frequency to ensure all of the line-powered clocks show the right time...)

    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
  • RaymanRayman Posts: 8,066
    edited July 2008 Vote Up0Vote Down
    Very interesting!
    Prop Info and Apps: http://www.rayslogic.com/
  • PFloyd36069PFloyd36069 Posts: 125
    edited July 2008 Vote Up0Vote Down
    now someone needs to make something like the stereo spatializer work in surround.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,605
    edited July 2008 Vote Up0Vote Down
    That is a great idea. Can Chip's singing monk demo or "seven" song be done in surround?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    Timothy D. Swieter, P.E.
    www.brilldea.com :RGB LED Ribbon, LED Painter II-8, PolkaDOT-51 and other gadgets for artistic lighting displays
    http://www.brilldea.com/Prod_Clearance.html :Need to make room for new ideas!
    www.tdswieter.com
  • scanlimescanlime Posts: 106
    edited July 2008 Vote Up0Vote Down
    Well, the AC3 audio specs are public now, thanks to the ATSC: www.atsc.org/standards/a_52b.pdf

    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
  • Jimmy W.Jimmy W. Posts: 112
    edited July 2008 Vote Up0Vote Down
    Look at Master Audio specs, they use uncompressed digital audio for "perfect" reproduction.
  • scanlimescanlime Posts: 106
    edited July 2008 Vote Up0Vote Down
    Jimmy W. said...
    Look at Master Audio specs, they use uncompressed digital audio for "perfect" reproduction.

    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
  • evanhevanh Posts: 3,608
    edited July 2008 Vote Up0Vote Down
    You're being a bit enthusiastic wanting to pump out 5.1ch at 24bit/96kHz! I suggest leaving the high-end to uncompressed stereo only. That makes the most sense to me.

    How about something like 4ch at 32kHz?

    What about mp3 decompression from those SD cards? Making your own personalised mp3 player. [noparse]:)[/noparse]


    Evan
    As long as websites don't require javascript in the browser then I'm happy.
  • scanlimescanlime Posts: 106
    edited July 2008 Vote Up0Vote Down
    evanh said...
    You're being a bit enthusiastic wanting to pump out 5.1ch at 24bit/96kHz! I suggest leaving the high-end to uncompressed stereo only. That makes the most sense to me.

    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
  • Clock LoopClock Loop Posts: 1,309
    edited June 2009 Vote Up0Vote Down
    What about spdif decoding? or say I wanted to use the prop to MERGE two SPDIF signals and output one final mixed signal?

    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
    To study the nature of randomness in a digital processor network using the same clock source, 54 prop chips were all connected to a master prop. http://forums.parallax.com/discussion/127983/55-parallax-propeller-s-parallells-processing-of-permanent-perturbations/p1
    Optic communication between homogenous and commensurable, 8-core, 635nm emitting, phase locked loop, bit salad tossing units? http://forums.parallax.com/discussion/comment/1248240/#Comment_1248240
    TheBlackBox: Release v2.0 - Propeller HSS FX/Sequencer with Digital Audio SPDIF output. http://forums.parallax.com/discussion/115258/theblackbox-release-v2-0-propeller-hss-fx-sequencer-with-digital-audio-spdif
    E-Tools - Mono555 calculator, resistor calculator, voltage divider calculator, RCtime calculator, LM317 calculator, Binary-Hex-Decimal calculator, Resistor color matrix, Series LED resistance calculator, OHMS LAW calculator.
    http://forums.parallax.com/discussion/81449/e-tools-html-java-script-electronic-design-tools-free-for-you
  • LeonLeon Posts: 7,617
    edited June 2009 Vote Up0Vote Down
    You'd need a lot more processing power than the Propeller has to mix SPDIF inputs. It would be quite easy with the right hardware, though.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
    Leon Heller
    G1HSM
  • Clock LoopClock Loop Posts: 1,309
    edited June 2009 Vote Up0Vote Down
    It has enough power to encode a spdif signal, but can't decode one? why? perhaps someone can go a bit more into why this is not possible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Meh. Nothing here, move along.
    To study the nature of randomness in a digital processor network using the same clock source, 54 prop chips were all connected to a master prop. http://forums.parallax.com/discussion/127983/55-parallax-propeller-s-parallells-processing-of-permanent-perturbations/p1
    Optic communication between homogenous and commensurable, 8-core, 635nm emitting, phase locked loop, bit salad tossing units? http://forums.parallax.com/discussion/comment/1248240/#Comment_1248240
    TheBlackBox: Release v2.0 - Propeller HSS FX/Sequencer with Digital Audio SPDIF output. http://forums.parallax.com/discussion/115258/theblackbox-release-v2-0-propeller-hss-fx-sequencer-with-digital-audio-spdif
    E-Tools - Mono555 calculator, resistor calculator, voltage divider calculator, RCtime calculator, LM317 calculator, Binary-Hex-Decimal calculator, Resistor color matrix, Series LED resistance calculator, OHMS LAW calculator.
    http://forums.parallax.com/discussion/81449/e-tools-html-java-script-electronic-design-tools-free-for-you
  • LeonLeon Posts: 7,617
    edited June 2009 Vote Up0Vote Down
    Some software I have (not for the Propeller, of course) samples S/PDIF input at 50 MHz!

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle

    Post Edited (Leon) : 6/1/2009 1:48:51 PM GMT
    Leon Heller
    G1HSM
  • AleAle Posts: 2,252
    edited June 2009 Vote Up0Vote Down
    Leon: We know that _that_ other processor can do it wink.gif.
    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
  • BeanBean Posts: 7,797
    edited June 2009 Vote Up0Vote Down
    I guess there is no way to do ADAT, 8 channels of 24-bit 48KHz audio...

    That's like 9.2MHz bit rate.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
    logo.png?503
    Esterline Research & Design
    thitt@esterlineresearch.com

    We offer consulting on the following areas of expertise:
    Frequency Control - Micro-Controller/Processor Projects
    Test and Automation - General Programming and Coding
    Circuit Design - Board Layouts
  • heaterheater Posts: 3,370
    edited June 2009 Vote Up0Vote Down
    @BPM: I think you'll find the answer to your question is that the SPDIF is actually being shifted out of the Prop at 6MHz by the Props video shifters. Sadly there is no similar hardware support to shift data into the Prop. sampling the an SPDIF input at that rate in software only is not going to happen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Clock LoopClock Loop Posts: 1,309
    edited June 2009 Vote Up0Vote Down
    heater said...
    @BPM: I think you'll find the answer to your question is that the SPDIF is actually being shifted out of the Prop at 6MHz by the Props video shifters. Sadly there is no similar hardware support to shift data into the Prop. sampling the an SPDIF input at that rate in software only is not going to happen.

    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.
    To study the nature of randomness in a digital processor network using the same clock source, 54 prop chips were all connected to a master prop. http://forums.parallax.com/discussion/127983/55-parallax-propeller-s-parallells-processing-of-permanent-perturbations/p1
    Optic communication between homogenous and commensurable, 8-core, 635nm emitting, phase locked loop, bit salad tossing units? http://forums.parallax.com/discussion/comment/1248240/#Comment_1248240
    TheBlackBox: Release v2.0 - Propeller HSS FX/Sequencer with Digital Audio SPDIF output. http://forums.parallax.com/discussion/115258/theblackbox-release-v2-0-propeller-hss-fx-sequencer-with-digital-audio-spdif
    E-Tools - Mono555 calculator, resistor calculator, voltage divider calculator, RCtime calculator, LM317 calculator, Binary-Hex-Decimal calculator, Resistor color matrix, Series LED resistance calculator, OHMS LAW calculator.
    http://forums.parallax.com/discussion/81449/e-tools-html-java-script-electronic-design-tools-free-for-you
  • Clock LoopClock Loop Posts: 1,309
    edited June 2009 Vote Up0Vote Down
    I have a few questions.


    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
    To study the nature of randomness in a digital processor network using the same clock source, 54 prop chips were all connected to a master prop. http://forums.parallax.com/discussion/127983/55-parallax-propeller-s-parallells-processing-of-permanent-perturbations/p1
    Optic communication between homogenous and commensurable, 8-core, 635nm emitting, phase locked loop, bit salad tossing units? http://forums.parallax.com/discussion/comment/1248240/#Comment_1248240
    TheBlackBox: Release v2.0 - Propeller HSS FX/Sequencer with Digital Audio SPDIF output. http://forums.parallax.com/discussion/115258/theblackbox-release-v2-0-propeller-hss-fx-sequencer-with-digital-audio-spdif
    E-Tools - Mono555 calculator, resistor calculator, voltage divider calculator, RCtime calculator, LM317 calculator, Binary-Hex-Decimal calculator, Resistor color matrix, Series LED resistance calculator, OHMS LAW calculator.
    http://forums.parallax.com/discussion/81449/e-tools-html-java-script-electronic-design-tools-free-for-you
Sign In or Register to comment.