speaker bonnet popping suppression

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
dgorissen
 
Posts: 4
Joined: Sun Jan 02, 2011 5:23 pm

speaker bonnet popping suppression

Post by dgorissen »

I have spent quite some time with the Speaker Bonnet (pre-soldered), trying to get it running without any popping.

Raspberry Pi 4B, My devices:

Code: Select all

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 [HifiBerry DAC HiFi pcm5102a-hifi-0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: ArrayUAC10 [ReSpeaker 4 Mic Array (UAC1.0)], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
This works but with a pop / crackle at the beginning and the end:

Code: Select all

aplay --device plughw:0,0 foo.wav
If I try to run the pop suppression command in the background...

Code: Select all

$ /usr/bin/aplay -D plughw:0,0 -t raw -r 48000 -c 2 -f S16_LE /dev/zero
Playing raw data '/dev/zero' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Then I get...

Code: Select all

$ aplay --device plughw:0,0 foo.wav
aplay: main:828: audio open error: Device or resource busy
As far as I can tell the mixer should be setup correctly. I double checked https://learn.adafruit.com/adafruit-spe ... i2s-tweaks and https://www.hifiberry.com/docs/software ... o-sources/

My /etc/asound.conf is:

Code: Select all

$ cat /etc/asound.conf
pcm.speakerbonnet {
   type hw card 0
}

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
}

pcm.softvol {
    type softvol
    slave.pcm "dmixer"
    control.name "PCM"
    control.card 0
}

ctl.softvol {
    type hw card 0
}

pcm.!default {
    type             plug
    slave.pcm       "softvol"
}
My /boot/config.txt

Code: Select all

$ cat /boot/config.txt
# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
enable_uart=1
# 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)
#dtparam=audio=on
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap

hdmi_drive:0=1
hdmi_force_hotplug:0=1
hdmi_group:0=2
hdmi_mode:0=1
hdmi_mode:0=87
hdmi_timings:0=480 0 40 10 80 800 0 13 3 32 0 0 0 60 0 32000000 3
display_hdmi_rotate:0=3

hdmi_drive:1=1
hdmi_force_hotplug:1=1
hdmi_group:1=2
hdmi_mode:1=1
hdmi_mode:1=87
hdmi_timings:1=480 0 40 10 80 800 0 13 3 32 0 0 0 60 0 32000000 3
display_hdmi_rotate:1=3

dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900

[all]
dtoverlay=vc4-fkms-v3d

dtoverlay=sc16is752-i2c,int_pin=24,addr=0x48

start_x=1
gpu_mem=128
And Im running buster

Code: Select all

$ uname -a
Linux cbrain 5.10.60-v7l+ #1449 SMP Wed Aug 25 15:00:44 BST 2021 armv7l GNU/Linux
Its the same issue as reported by @bgerber in viewtopic.php?f=50&t=145518&p=718901&hi ... et#p718901 but no final solution posted. A related post is https://community.volumio.org/t/solved- ... ed/12355/5

The pi itself is not doing anything else interesting. It has a small HDMI screen attached and runs XFCE but its main purpose is to run a docker container

Ive run out of options how to solve/debug this unfortunately, any suggestions?

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: speaker bonnet popping suppression

Post by mikeysklar »

It looks like you did a good job of following our guide to setup the necessarily config files.

Since aplay still has a pop at the beginning and end of playback is that something you can adjust for with alsamixer (lowering the volume form the default 100% to 50%)?

Does mpg123 also pop when playing files in the same way?

dgorissen
 
Posts: 4
Joined: Sun Jan 02, 2011 5:23 pm

Re: speaker bonnet popping suppression

Post by dgorissen »

Thanks for the reply. The same thing happens with mpg123. I tried changing the volume but for some reason I changing the alsamixer volume for the the snd_rpi_hifiberry_dac device did not have any effect, which feels odd. I also tried with amixer but it invocation and device targetting is rather opaque to me.

For reference the pi/bonnet is part of an interactive voice-controlled robot I am building. Im using the bonnet to relay repsonses of the robot back to the user.

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: speaker bonnet popping suppression

Post by mikeysklar »

I've seen other situations where alsmamixer no longer has a control on volume levels.

Does using amixer help?

Code: Select all

 amixer sset PCM,0 90%
Does using mplayer prevent popping?

dgorissen
 
Posts: 4
Joined: Sun Jan 02, 2011 5:23 pm

Re: speaker bonnet popping suppression

Post by dgorissen »

So this works fine (but with the crackle/pops)

Code: Select all

aplay --device plughw:0,0 foo.wav
This does not produce any sound:

Code: Select all

$ mplayer -ao alsa foo.wav
MPlayer 1.3.0 (Debian), built with gcc-8 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing foo.wav.
libavformat version 58.20.100 (external)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 16000 Hz, 1 ch, s16le, 256.0 kbit/100.00% (ratio: 32000->32000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [alsa] 16000Hz 1ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   1.3 (01.3) of 1.0 (01.0)  0.0%


Exiting... (End of file)
Neither does this:

Code: Select all

$ mplayer alsa:device=hw=0.0 foo.wav
MPlayer 1.3.0 (Debian), built with gcc-8 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing alsa:device=hw=0.0.
File not found: 'alsa:device=hw=0.0'
Failed to open alsa:device=hw=0.0.


Playing foo.wav.
libavformat version 58.20.100 (external)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 16000 Hz, 1 ch, s16le, 256.0 kbit/100.00% (ratio: 32000->32000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [pulse] 16000Hz 1ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:   1.6 (01.5) of 1.0 (01.0)  0.0%


Exiting... (End of file)
amixer output:

Code: Select all

 $ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 52454 [80%] [on]
  Front Right: Playback 52454 [80%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right - Rear Left - Rear Right - Front Center - Woofer
  Limits: Capture 0 - 65536
  Front Left: Capture 65536 [100%] [on]
  Front Right: Capture 65536 [100%] [on]
  Rear Left: Capture 65536 [100%] [on]
  Rear Right: Capture 65536 [100%] [on]
  Front Center: Capture 65536 [100%] [on]
  Woofer: Capture 65536 [100%] [on]

Code: Select all

$ amixer sset PCM,0 50%
amixer: Unable to find simple control 'PCM',0

$ amixer -c 0 sset PCM,0 10%
Simple mixer control 'PCM',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 255
  Front Left: 26 [10%]
  Front Right: 26 [10%]
The latter command works without error but it has no effect on the volume.

Thanks for sticking with me so far.

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: speaker bonnet popping suppression

Post by mikeysklar »

Do you also have the recommended ~/.asoundrc with software volume control? You did not mention that in your original post starting this thread. You can see this includes the pcm.softvol and ctl.softvol which seems like the part you are missing.

https://learn.adafruit.com/adafruit-spe ... 2711421-10

Code: Select all

pcm.speakerbonnet {
   type hw card 0
}

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
}

pcm.softvol {
    type softvol
    slave.pcm "dmixer"
    control.name "PCM"
    control.card 0
}

ctl.softvol {
    type hw card 0
}

pcm.!default {
    type             plug
    slave.pcm       "softvol"
}

dgorissen
 
Posts: 4
Joined: Sun Jan 02, 2011 5:23 pm

Re: speaker bonnet popping suppression

Post by dgorissen »

So I did have those contents in my /etc/asound.conf and my understanding was that would be used if ~/asoundrc did not exist? However I created the file but it didnt change anything that I could see.

In parallel, and as a plan B, I ordered a little amplifier board that I can use to connect the headphone output of the pi to my passive speakers. That turns out to work fine, with no pop/crackles, and also properly responds to alsamixer so volume control works. Its also a bit smaller, easier to integrate, so it looks like I will be giving up on the bonnet... :/

User avatar
mikeysklar
 
Posts: 14181
Joined: Mon Aug 01, 2016 8:10 pm

Re: speaker bonnet popping suppression

Post by mikeysklar »

Glad you found a solution that works.

Both configs /etc/asound.conf and ~/.asoundrc are necessary based on our guide as the volume controls are only added at the user level.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”