SOLVED! Adafruit i2s DAC reducing pops / crackle help needed

DACs and Wireless Dongle Compatibility Thread. Post wether a particular device is working or not in Volumio

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

SOLVED! Adafruit i2s DAC reducing pops / crackle help needed

Postby tophee » Wed Apr 15 2020 11:18

Hello,
I've recently built a small mono speaker system for the bedroom using an old raspberry pi and a cheap Adafruit max98357 dac. While my woodworking skills leave something to be desired I'm fairly happy with the results except for the pops and crackles between tracks when playing Spotify.
Having done some research on why this happens a proposed solution has been offered by the manufacturers
I've read through what they are suggesting and the code they suggest breaks playback on a fresh install of Volumio and I'm afraid I don't have enough technical knowledge to troubleshoot beyond following the detailed instructions (on the same page) and getting nowhere. When starting playback I just get an ALSA / Resource busy error in the GUI.Error

Failed to open "alsa" [alsa]; Failed to open ALSA device "hw:0,0": Device or resource busy


Any ideas where to start?
Many thanks
Last edited by tophee on Sat May 23 2020 14:32, edited 1 time in total.
User avatar
tophee
Fresh off the boat
Fresh off the boat
 
Posts: 9
Joined: Sun May 04 2014 10:39

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


Adafruit i2s DAC reducing pops / crackle help needed

Postby tophee » Thu May 21 2020 14:34

Hi, so to follow up on my earlier post I've spent some time trying to work out how to fix the startup and between tracks crackle I get on my Volumio system using the Adafruit MAX98357 i2S mono amp.

I've still not solved this issue and I am not very clear on how to proceed.

I have taken a few steps so far, but they have not solved the crackle between and at the start of playing tracks on Spotify, at the start of playing an internet station or when it stops.

The instructions are suggesting it is possible to play a software mixer to output a fixed sample rate to the DAC so the bit clock does not change. As Volumio uses ALSA the article suggests using dmix ALSA module. (The article is here.)

Is the dmix module included in Volumio's build? I am having trouble setting up what is suggested.
I completed the first step by adding the following line to /boot/config.txt and rebooted.
Code: Select all
dtoverlay=i2s-mmap


This caused no issue for me and survived the reboot.

Next, I switched back to the guide on the adafruit guide.

I added the following code to /etc/asound.conf
Code: Select all
pcm.speakerbonnet {
   type hw card 0
}
 
pcm.!default {
   type plug
   slave.pcm "dmixer"
}
 
pcm.dmixer {
   type dmix
   ipc_key 1024
   ipc_perm 0666
   slave {
     pcm "speakerbonnet"
     period_time 0
     period_size 1024
     buffer_size 8192
     rate 44100
     channels 2
   }
}
 
ctl.dmixer {
  type hw card 0
}


with the exception of changing the value for the hw card from 0 to 1. Now both references read
Code: Select all
type hw card 1
.

Reboot but trying to play anything failed. Looking at the settings regenerated the original code and wiped my changes that are meant to generate the fixed sample rate.

Has anyone got any ideas?
User avatar
tophee
Fresh off the boat
Fresh off the boat
 
Posts: 9
Joined: Sun May 04 2014 10:39


Adafruit i2s DAC reducing pops / crackle help needed

Postby michelangelo » Fri May 22 2020 11:36

IMHO, try increasing\decreasing those values, fine tune them according to results

period_size 1024
buffer_size 8192


You might end up having buffer underruns
User avatar
michelangelo
Founder
 
Posts: 4766
Joined: Sun Dec 15 2013 23:18


Adafruit i2s DAC reducing pops / crackle help needed

Postby tophee » Fri May 22 2020 16:16

Thanks, I'll try that. See if I can improve the inappropriate crackles.

I have discovered someone else trying to solve this issue over on GitHub. And see if I can work my way through the adafruit instructions if those simple tweaks don't solve things.

Many thanks
User avatar
tophee
Fresh off the boat
Fresh off the boat
 
Posts: 9
Joined: Sun May 04 2014 10:39


SOLVED! Adafruit i2s DAC reducing pops / crackle help needed

Postby tophee » Sat May 23 2020 14:08

Thanks to timothyjward over on github to help me resolve this issue. For other users experiencing a crackle or pop between tracks or at the start or end music this may well help.

The adafruit guide I linked to was throwing me off as it assumed there was no prior setup on the system. Unlike on Volumio which knows about HiFiBerry type DACs such the Adafruit -MAX98357 iS2 DAC I was using.

So the steps to resolve this are:

1. Install Volumio and set up the DAC as necessary in the GUI. Also, set the volume to soft volume.

2. ssh into volumio

3. Edit
Code: Select all
asound.conf
in your favourite editor e.g. nano /etc/asound.conf

and modified pcm.softvol to use dmix. In my asound.conf it was the value for the second entry.
Code: Select all
pcm.softvol {
    type            softvol
    slave {
        pcm         "dmix:1,0"
    }
}


After that, I need to add a service and ensure it carried over reboot:

Code: Select all
sudo nano /etc/systemd/system/aplay.service


And copied this into the blank document:

Code: Select all
[Unit]
Description=Invoke aplay from /dev/zero at system start.

[Service]
ExecStart=/usr/bin/aplay -D dmix:1,0 -t raw -r 48000 -c 2 -f S32_LE /dev/zero

[Install]
WantedBy=multi-user.target


Ctrl-x to exit (yes to save)

then issued these commands to finish up.

Code: Select all
sudo systemctl daemon-reload


Code: Select all
sudo systemctl enable aplay.service


Code: Select all
sudo systemctl start aplay.service


To check its working issue this command:

Code: Select all
systemctl status aplay.service


Everything looked good for me - Spotify played with no crackles or pops. :D

I rebooted the system and the changes are persistent.
User avatar
tophee
Fresh off the boat
Fresh off the boat
 
Posts: 9
Joined: Sun May 04 2014 10:39


Return to Compatibility List

Who is online

Users browsing this forum: No registered users and 0 guests