To setup the Hifiberry Amp2 you'll have to start by removing the driver for the onboard sound.
$ sudo nano /boot/config.txt
Remove the line dtparam=audio=on
and add the line dtoverlay=hifiberry-dacplus
The final part of the file will look something like this:
# Uncomment some or all of these to enable the optional hardware interfaces
# dtparam=i2c_arm=on
# dtparam=i2s=on
# dtparam=spi=on # Uncomment this to enable the lirc-rpi module
# dtoverlay=lirc-rpi # Additional overlays and parameters are documented boot overlays README
# Enable audio (loads snd_bcm2835)
dtoverlay=hifiberry-dacplus
gpu_mem=256
start_x=1
According to the Hifiberry site this part should be optional, but I couldn't get my amp2 to work without it.
Create the file /etc/asound.conf
$ sudo nano /etc/asound.conf
with following content:
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
Make sure you have no .asound.conf file with different settings in your home directory, if there is delete it (or rename it)
Reboot to start with the new settings and check if the device is listed by typing aplay -l:
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
Subdevices: 0/1
Subdevice #0: subdevice #0
Before testing it is advised to lower the output volume. By default the amp will output at 100% which might damage your speakers.
Check current volume settings:
$ amixer sget Digital
Simple mixer control 'Digital',0
Capabilities: pvolume pswitch
Playback channels: Front Left - Front Right
Limits: Playback 0 - 207
Mono:
Front Left: Playback 179 [86%] [-14.00dB] [on]
Front Right: Playback 179 [86%] [-14.00dB] [on]
Set volume to 60%:
$ amixer sset Digital 60%
To test playback it is recommended to install mplayer because it can play all types of files
$ sudo apt-get install mplayer
To start playback a testfile type:
$ mplayer http://www.waailap.nl/upload/test.mp3
(CTRL+C to abort playing)
See original article at Hifiberry forum: https://support.hifiberry.com/hc/en-us/articles/205377651-Configuring-Linux-4-x-or-higher
John B 2020-04-29 17:46
The above guide worked for me using a Raspberry Pi 4 and Raspbian Buster. Thanks!