Kodi Audio Heaven With Pifi Digi+ and External DAC

Last modified by Site Administrator on 2017/08/14 11:06

Introduction to HifiBerry/Pifi Digi+ SPDIF Soundcard for Raspberry Pi

http://images10.newegg.com/NeweggImage/productimage/A6TJ_130637720604504548HHPO0h1kMI.jpg "PiFi Digi+" is a low cost solution to HD Audio via the Raspberry Pi 2, B+, or A+ HAT Connection. This Chinese clone of the HifiBerry Digi+ card is readily available at NewEgg Marketplace, AliExpress, EBay, etc. In contrast, the HifiBerry Digi+ available in the USA and Canada is twice as expensive and is missing the SPDIF galvanic isolation transformer that is standard on the PiFi. An additional feature of the Pifi over the HifiBerry is an IR sensor that can be used with lirc(1) to enable a wide variety of old IR remote controls to work with a Raspberry Pi Media Center like Kodi.

Motivation: Why de-jittered SPDIF sounds good with an external DAC

The technical reasons why dejittered i2s digital audio on the Raspberry Pi sounds good

"Jitter" is what makes digital audio sound "digital" grungy and bad. A high quality reference DAC, and a digital source without jitter (or with a WM8804 like on this $26.00 board) means that HD digital audio can sound indistinguishable from analog.

Installation and ALSA setup

The PiFi Digi+ is fully supported by stock Raspbian and works perfectly with a RaspberryPi2 Kodi(1) media center using an external DAC. Setup took about five minutes following the HifiBerry guide https://www.hifiberry.com/guides/configuring-linux-3-18-x/

  1. Enable SPI and i2c in /etc/modprobe.d/raspi-blacklist.conf
    • comment-out
      #blacklist spi-bcm2708
    • comment-out
      #blacklist i2c-bcm2708
  2. Remove stock audio driver in /etc/modules
    • comment-out
      #snd-bcm2835
  3. Add device tree overlay in /boot/config.txt
    • add
      dtoverlay=hifiberry-digi
  4. Make this card the system default ALSA device in /etc/asound.conf
    • pcm.!default  {
       type hw card 0
      }
      ctl.!default {
       type hw card 0
      }
  5. Unlike HifiBerry Digi+, this card includes an IR receiver for remote control. However, there's GPIO conflicts by default. For quick testing, I disabled lirc(1) to prevent conflict with GPIO26 (GPIO header pin 37). Later I enabled lirc(1) and got it to work with kodi(1). (see below).

After a reboot, the card is enabled:

npm@kodipi:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_digi], device 0: HifiBerry Digi HiFi wm8804-spdif-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
npm@kodipi:~$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_digi,
    Default Audio Device

Select this device in the Kodi(1) media center and all playback will occur over SPDIF:

kodi-system-settings-audio-for-digiplus.png

A big advantage of using this card over USB audio with Kodi(1) is that the default Kodi(1) setup always resamples to 48k over USB; with this card, the exact sample rate of the video or audio files are output to the DAC, even 192kHz/24 bit files.

Using IR remote controls with PiFi Digi+ IR receiver with lirc(1)

http://wiki.ljackson.us/images/7/73/Wintv-pvr-150_remote.jpghttp://kodi.wiki/images/e/e2/Hpremote.jpgCheap, free or surplus 2007 Windows Media Center MCE remotes allow easy control of Kodi(1) via the IR sensor on the PiFi Digi+. I had a few laying around in drawers, unused (see images), which now work, thanks to lirc(1), the Linux Infrared Remote Control project and an open-source database of IR remotes.

lirc(1) setup for use with Kodi(1)

  1. Install lirc(1)
    • sudo apt-get install lirc
    • Configure /etc/lirc/hardware.conf
      LIRCD_ARGS="--uinput"
      LOAD_MODULES=true
      DRIVER="default"
      DEVICE="/dev/lirc0"
      MODULES="lirc_rpi"
    • Configure /etc/lirc/lircd.conf by finding the appropriate remote control definition(s) online or installed in /usr/share/lirc/remotes/ and inserting the contents of the chosen remote control into the /etc/lirc/lircd.conf file. The "HP MCE Remote" works with the lirc(1) "mceusb" remote (installed in /usr/share/lirc/remotes/mceusb/lircd.conf.mceusb). The "Hauppauge" remote works with the lirc(1) "Hauppauge_350" remote (installed in /usr/share/lirc/remotes/hauppauge/lircd.conf.hauppauge).
  2. Start lirc(1): sudo service lirc start
  3. Test the remote by running irw(1) and pressing buttons on the remote. You should see output like:
    npm@kodipi:~$ irw
    000000037ff07be1 00 Up mceusb
    000000037ff07bdf 00 Left mceusb
    000000037ff07be0 00 Down mceusb
    000000037ff07bde 00 Right mceusb
    000000037ff07bdd 00 OK mceusb
    000000037ff07bdc 00 Back mceusb
  4. Configure $HOME/.kodi/userdata/Lircmap.xml. The file needs to explicitly name the remotes setup in /etc/lirc/lircd.conf above, e.g., device="Hauppauge_350", and device="mceusb". The template entries in /usr/share/kodi/system/Lircmap.xml are modified slightly to exclude using the "new" KEY_XXX event names, choosing instead to use the traditional names (e.g., OK, not KEY_OK) for all but the power button:
    • Some of the lirc(1) definitions for "mceusb" were in the new format and had to be transformed back to the old to avoid issues. The problem is that KEY_XXX forms send multimedia keyboard codes to the console, which potentially turn up as garbage on the console with inadvertent input from the remotes. For example, an accidental KEY_ENTER from the remote at the wrong time while editing a command-line as 'root' could be devastating. Now only KEY_POWER is transmitted to console via remotes: in Kodi(1) it pops up the shutdown menu; in bash(1) it is safely ignored as a keyboard power button click. An important problem avoided by using only the "old" names: in default Kodi(1) setup, Kodi would respond to *both* lirc(1) and keyboard events giving double keypresses. Thus a single IR remote event using the new naming (e.g. KEY_UP) generates a "double event" in Kodi(1): one as the up-arrow keyboard event, and one as the KEY_UP IR event. Using only "Up" (old event naming) generates a lirc(1) "Up" event in Kodi(1) and correctly gives the action of a single event. 

Future enhancements could include using an IR remote with a builtin keyboard alongside a customized lirc(1) to get rid of wired keyboard for Kodi(1) text entry and console couch jockeying.

For more info on lirc(1) troubleshooting, debugging, see Installing LIRC on Raspbian and for more details, Setting Up LIRC on the RaspberryPi.

A case that fits!

Amazon has a $10.00 case, originally for the PiFace Digital 2, that happens to fit the Pifi Digi+'s additional height and SPDIF connections perfectly:

IMG_20150619_191751.jpg

Tags:
Created by Niels Mayer on 2015/06/08 19:14
    
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.4.4 - Documentation