patrickm
Posts: 4
Joined: Wed Jun 26, 2013 10:59 pm

Method for cheap optical audio out from headphone jack?

Fri Aug 16, 2013 4:40 am

After having some issues with background noise on the analog output from the Pi, I was thinking about alternatives. Perhaps a silly question, but is there a way to force a TTL-level digital audio output from the headphone jack? I'm a linux noob, but recall making a passable TTL-to-Toslink optical cable with just a bright red LED at the right wavelength, an old toslink blank plug, and an appropriate resistor in order to make an old CD-ROM drive into a digital audio source for a garage stereo. I'm wondering if a similar approach might lead to a super-cheap adapter that would avoid additional interface hardware... just basically require a 3.5mm cable going to a similar LED/toslink plug. There used to be programs out there that would record AC3 audio as a WAV file for equipment demo/testing, so it's certainly theoretically possible. just not sure if the hardware supports it or if it's worth someone's time to develop. Also not sure what the maximum voltage output is from that jack, which could be a limiting factor if it's a 1V peak.

thoughts from the experts out there?

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Method for cheap optical audio out from headphone jack?

Fri Aug 16, 2013 5:20 am

The only way to make that work would be to re-digitize the analogue audio output (using an A/D converter), and then use the digitized audio to drive the Toslink LED. But given your problem is noise on the analogue, the A/D here won't help. There might be a digital audio output via the HDMI cable - it's certainly the best place to start - I have no idea of the audio frequency range it covered (i.e. 44.1kHz like a CD, 48kHz like DVD (I think)), but it's probably the only option.

Sadly I can't help further as you now know everything I do.

Good luck!
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Method for cheap optical audio out from headphone jack?

Fri Aug 16, 2013 10:10 am

If you look at the schematic (http://www.raspberrypi.org/wp-content/u ... .2_027.pdf, I've reproduced the audio circuit here)
AudioOut2.png
AudioOut2.png (25.67 KiB) Viewed 4660 times
you'll see it's giving out about 1v p-p from 100Ω and is limited to ~50kHz by the 33n capacitor
Also, by default it's driven by the PWM subsystem.

However, if you're willing to butcher the board, you could get rid of the capacitor to increase the bandwidth, and replace R26 with an LED.
You could then replace the PWM software with your own to output whatever is required for Toslink - the audio uses GPIO 40 and GPIO 45.
Although it might be easier to bit-bang ordinary GPIOs on P1

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Method for cheap optical audio out from headphone jack?

Fri Aug 16, 2013 10:15 am

either use the HDMI audio as you should or the use the
p5 header for i2s audio ? as that will be much better quality
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Method for cheap optical audio out from headphone jack?

Fri Aug 16, 2013 10:19 am

If there is noise at the output why digitise this when you'll just get noise decoded at the output??

A simple solution would be to use a USB sound dongle and if you prefer digital output then find one with a toslink or s/pdif interface.

Richard S.

patrickm
Posts: 4
Joined: Wed Jun 26, 2013 10:59 pm

Re: Method for cheap optical audio out from headphone jack?

Sun Aug 18, 2013 3:56 am

Thanks for the quick feedback. I'm aware that HDMI audio is better, but that's not an option for this project because the amplifier lacks HDMI inputs and the cost of a converter isn't worth it in this case. I was also thinking about something more generally of use to others with similar situations that wouldn't require modifying anything internally.

A couple clarifications:
- i don't want to re-sample the existing analog audio and then output as digital. I'm thinking that this could be done in software during the decode process, eventually sending stereo PCM using an SPDIF protocol. this can be done at 48khz

- converting before it's output would probably solve the noise problem. the noise i'm getting is low-level junk that may be related to either power supply issues, or the DAC/output on the board. it seems unlikely this would significantly affect a digital output, which is basically looking for something above or below roughly half the max voltage.

- thanks for the schematic too. seems that the 1v p-p may be the limiting factor here on a cheap solution. maybe the usb dongle is going to be the only way.

User avatar
Paul Webster
Posts: 822
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: Method for cheap optical audio out from headphone jack?

Sun Aug 18, 2013 6:21 am

Is there enough support for the i2S interface to make it a viable alternate route?

Return to “Graphics, sound and multimedia”