Performance issues with PI3 and HifiBerry DAC+



I installed the Hifiberry DAC+ on my Pi following this guide:

The audio works however depending on the script the sound can be very laggy and return Timing exceptions. The example “Sonic Dreams” seems to work fine (although I think I can hear light audio glitches) but my own script with 4 simple live_loops results in horrible audio.
I doubt it’s due to the complexity of my code. The Pi’s CPU is at 50% while running it.

My code:

use_bpm 120

set :amp_bd, 1
set :amp_bass, 1
set :amp_pentatonik, 1
set :amp_snare, 1
set :amp_guitar, 1

live_loop :metronome do
  sleep 1

live_loop :bd, sync: :metronome do
  sample :bd_haus, amp: get[:amp_bd], lpf: 80 if (spread 8, 16).tick
  sleep 1

with_fx :echo, mix: 0.1 do
  live_loop :snare do
    sync :bd
    sample :drum_snare_hard, amp: get[:amp_snare], attack: 0.2, sustain: 1, release: 0.5 if(spread 2,4).tick
    sleep 1

with_fx :reverb, mix: 0.5 do
  live_loop :bass, sync: :metronome do
    with_fx :lpf, amp: get[:amp_bass], cutoff: 80 do
      use_synth :piano
      play_pattern_timed [:A2, :A2, :C3, :C3, :E3, :E3, :F3, :F3, :A3, :A3, :F3, :F3, :E3, :E3, :C3, :C3],
        [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,]

with_fx :tremolo, mix: 0.5 do
  live_loop :ambient, sync: :metronome do
    sample :guit_e_slide, amp: 1.2, sustain: 4, release: 1, lpf: 70
    sleep 8

Connecting a Midi-controller and playing simple notes with a synthesizer sometimes also lead to audio glitches with higher overload.

I ran the following commands to upgrade my Pi:

sudo apt-get upgrade
sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update

and added to /boot/config.txt

aplay-l output:

pi@raspberrypi:/opt/sonic-pi $ aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], Gerät 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
Sub-Geräte: 0/1
Sub-Gerät #0: subdevice #0

and followed this guide to configurate Sonic Pi

However the guide tells me to use the hardware slot 1 instead of 0 because I won’t get sound but I do have sound? Anyway neither the tutorial’s proposal

sys("jackd -R -T -p 32 -d alsa -d hw:1,0 -n 3 -p 2048 -r 44100& ")
or mine
sys("jackd -R -T -p 32 -d alsa -d hw:0 -n 3 -p 2048 -r 44100& ")

This exchange between Sam, Robin and other’s didn’t help either.!msg/sonic-pi/BvkSTW0Cqnk/nRtzYn4aAwAJ

Please let me know if you need additional information. Thank you!

1 Like