This project was about getting audio out of the BeagleBone Black. The aim was to have stereo audio, at least as good as an iPod. See further below for the circuit, and also a video showing it working.
Later, this project was used to build a PCB design (see below for the link to this part 2, and then the PCB was used to make a home Sonos-type hi-fi audio player (see the link to part 3 below).
The BBB has an on-board I2S interface, which makes interfacing an external DAC easy. The I2S interface is connected from the AM3359 processor to the HDMI chip (TDA19988) but it is not required for HDMI to be used in order to make use of the I2S interface. The I2S interface is brought out to some pins on port P9 (see here for details). It was encouraging that Technoshaman and Donald Miller had some success with the interface, so I wanted to try it out and I got some time today.
Since the interface is capable of 24-bit/192kHz audio, it was worthwhile picking a nice DAC. A good but not over-the-top device seemed to be the Texas Instrument's PCM5101 which is nice because it has reasonable specs and also provides a built-in charge pump so that it can function from a single supply. A headphone amp was connected, and this was ON Semi's NCP2811A. The combination of PCM5101 (actually my prototype used PCM5101A which can also function from 1.8V, but this was not needed) and NCP2811A was chosen so that the entire circuit could operate from the BBB supply if desired, even if it was from a Li-Ion battery that was powering the BBB, and for low noise and distortion. The only problem is that the PCM5101 has quite a high output (clearly a good thing!) but the audio amp minimum recommended gain is 1 and it cannot meet the required output voltage, and it means that it will distort at high volume. So, at a lower volume (and lower SNR) it will be fine, and I prefer this particular amp because of the very low distortion. The ON semi datasheet was sparse though.
This is the DAC prototype:
This is the whole thing connected up:
This is the rear of the board - a bit messier! It was built on a SMD to DIP adapter board with some copper tape for supply rails:
This is the audio amp - not a lot to it, since it is so integrated.
I made a recording, but excuse the quality. The audio is from a small 64 ohm speaker picked up by a simple camera in-built microphone so it sounds bad, but connecting to headphones is a different story - it sounds as good as an ipod (although this is subjective - I don't have a way to measure). Another thing I still need to check is that originally I thought the data was read on the falling edge of the bitclock on the BBB, but I2S specifies the opposite. Maybe I made a mistake in my initial observations (I have not had a chance to re-check), or maybe it changed in a build. But the circuit as shown here works for me.
This is running on an not-recent Angstrom downloaded build (maybe a few weeks old image), and I still hear some very slight audio issues - it sounds like perhaps a break for a few tens of milliseconds occasionally, only if you're listening closely. I really hope it is resolved in a build soon (or maybe it is due to ffmpeg - perhaps avconv gives better results).
EDIT: I've since been using mplayer (command line is mplayer -ao alsa -volume 4 AmyWinehouse-BackToBlack.mp3 and either I'm not noticing any audio issues or they have disappeared). I've concluded it sounds at least as capable as my old ipod touch, maybe better).
I played audio using the command line:
ffmpeg -i AmyWinehouse-YouKnowImNoGood.mp3 -f alsa "default:CARD=Black" -re -vol 150
and it reported the stream as:
Stream #0.0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
This is the circuit. All the 3.3V supplies were connected together for the prototype (I wouldn't do that for real, although it sounded very good in my limited tests). The amplifier V+ can be connected to 3.3V or the 5V supply (or the Li-Ion battery directly).
Note 16th Jan 2014: See the comments section below for more detail; the SCK pin on the PCM5101A was disconnected from 0V and instead connected to the BBB P9 pin 25. This will provide the lowest jitter by disabling the DAC's internal PLL. A sample capture of the audio quality (captured from the headphone output of the NCP2811A, just to give an approximate idea of what it sounds like from headphones) is attached to the post below, in the zip file dac-output.zip. More info on it in the comments section below.
Note 2: Please add a logic inverter to the bitclock connection. For more detail, see the comments below (search for the word 'bitclock' to make it easier to find). See the part 2 blog post, and the attached file there called dac-documentation.zip for the circuit diagram, showing the bitclock inversion. More recent BBB images may not need it, but it was certainly needed for the images I tested with.
Experiments with FLAC
I've also tried a FLAC file, but I'm hitting some limitation with ffmpeg it seems, and it picks a 16-bit format when it ought to be 24-bit. Meanwhile, avconv I couldn't get to work for MP3 or FLAC (it reported 'av_interleaved_write_frame(): Resource temporarily unavailable'). If anyone knows, any tips on how to play FLAC at 24-bit would be gratefully appreciated.
root@beaglebone:~# ffmpeg -i Taxman_2009_Digital_Remaster.flac -f alsa "default:CARD=Black" -re -vol 5 ffmpeg version v0.8.4, Copyright (c) 2000-2012 the Libav developers built on May 20 2013 13:00:42 with gcc 4.7.3 20130205 (prerelease) This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes). [flac @ 0x2da80] max_analyze_duration reached Input #0, flac, from 'Taxman_2009_Digital_Remaster.flac': Metadata: ORIGREFERENCE : 6C05C9F79EE74052A7991B9669B98533 ORIGDATE : 2009:09:14 ORIGTIME : 11:57:01 TIMEREFERENCE : 5292000 CODINGHISTORY : A=PCM,F=44100,W=24,M=stereo,T=SADiE5 ORGANIZATION : EMI TITLE : Taxman track : 1 ARTIST : The Beatles ALBUM : Revolver (24 BIT Remastered) DATE : 2009 Duration: 00:02:37.85, bitrate: 1892 kb/s Stream #0.0: Audio: flac, 44100 Hz, 2 channels, s32 Incompatible sample format 's32' for codec 'pcm_s16le', auto-selecting format 's16' Output #0, alsa, to 'default:CARD=Black': Metadata: ORIGREFERENCE : 6C05C9F79EE74052A7991B9669B98533 ORIGDATE : 2009:09:14 ORIGTIME : 11:57:01 TIMEREFERENCE : 5292000 CODINGHISTORY : A=PCM,F=44100,W=24,M=stereo,T=SADiE5 ORGANIZATION : EMI TITLE : Taxman track : 1 ARTIST : The Beatles ALBUM : Revolver (24 BIT Remastered) DATE : 2009 encoder : Lavf53.21.0 Stream #0.0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s Stream mapping: Stream #0.0 -> #0.0
dac-output.zip 3.1 MB