Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

PWM audio playback Noise/Screech after few moments

Sat May 09, 2020 3:21 am

I'm lost. Out of ideas, I'll try and keep this brief and post this to all forums hardware and software because I'm not sure where the problem lies...

my setup is pretty simple,

raspberry Pi zero W with raspian Lite
Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A followed the adafruit guide for hookup with i2s pop noise tweaks
adafruit speaker bonnet (just using one of the speakers) 3w 4o
an LED light running off UART gpio
a shutdown button that would be off gpio4
adafruit MPR121 touch sensor board for buttons

I have raspian lite with the latest upgrades, all latest dependencies to run the audio and touch sensor board and Mopidy software. I run Mopidy to playback audio on boot and build an http server so that I have a web client to use as a music control player. Everything is tested and works perfectly fine and audio comes out really nice and I NEVER had this issue when I was prototyping and didnt finalize my project to a PCB but after a few moments of playback usually or maybe it's after the Pi has activity I notice a few scratching noises come onto speaker and then suddenly just loud screeching no matter what volume I have hardware or software at and then it garbles up to a point where theres no sound. Sometimes sound will come back and sound normal and scratch a little or just completely stop working, If I fetch another song to stream or even if its a local audio file audio often comes back crystal clear for a few moments or even A WHILE and then there's a hiccup and screeching noise and audio dies off again. I cannot figure out what is happening because often times audio can play back for 15 minutes of no problems and clear audio and then it happens again, sometimes it just is worse and happens after 10-15 seconds of playback.

I have taken a video of what keeps happening as it helps a lot to understand what to look for?

https://youtu.be/ozl80uslla8 listen closely right before end of video (not sure if you can hear what I'm saying anyways)


So (I believe) I've eliminated the following as the obvious culprits that you would think should solve it to no avail and no length of google searching has brought me to a similar enough problem or what to test for.. I'm pretty much giving up and truly believing either the Adafruit Amp is damaged or the Pi but i'm not sure which or how or if it's my wiring and soldering which I keep checking over and over and seems to be perfectly fine. It honestly sounds like noise interference but nothing I do nor shaking wires to look for a problematic one or a bad ground, nothings working unless the hardware is damaged -I get this strange feeling if I grounded the Amp elsewhere or powered the amp on a seperate power supply that it could be a workaround and if it isn't even a temp fix then I would think the wiring or hardware is damaged.. I find it hard to believe my wiring is bad.
>>>
Tested multiple power supplies with more than enough amperage,
tested different microusb cables for the power supply.
tried a different outlet
checked if it's not the MicroSD card
disabled the shutdown button I made and the LED, the only thing that manually starts on boot that I've added is Mopidy and it's extensions.

I have no idea how else to troubleshoot or verify if it's hardware, if anyone has any idea what the underlying cause might be to start with that would be amazing as I'm giving up hope :D :D :'(

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2351
Joined: Thu Jul 11, 2013 2:37 pm

Re: PWM audio playback Noise/Screech after few moments

Sat May 09, 2020 5:49 pm

What happens if you run "speaker-test -c 2 -t sine"? Do you get the same distortion?
Rockets are loud.
https://astro-pi.org

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Sat May 09, 2020 5:59 pm

No I can't say I do get any problems playing the speaker test sound. I get the feeling if I played it for a really long time perhaps, but if you're checking whether local files or streamed files play a role.. I've tried mpg321, aplay, MPC add and play. Methods of streaming or local both quickly or eventually produces a dying static noise.

I'm at a loss of understanding the culprit, amp, Pi, wiring, something else?

(I will certify whether that test sound eventually recreates noise and come back to you)

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Sat May 09, 2020 8:10 pm

I've been running the noise for over an hour now since 3pm and nothing bad has happened. :shock: what does that tell us exactly??

(edit) I've left it on for a few hours now so just playing this audio tone definitely defeats that scratching sound coming through the speakers.

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Sat May 09, 2020 9:52 pm

additionally a lot of this information is too technical for me but could help a lot , it's the datasheet for the 98357A amp I'm using:

https://cdn-shop.adafruit.com/product-f ... 98357B.pdf


this is my boot/config.txt by the way:

Code: Select all

# 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

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README
#dtoverlay=gpio-shutdown,gpio_pin=4,active_low=1,gpio_pull=up

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap
#enable_uart=1
#force_pwm_open=0



this is f9ound in my ~/.asoundrc

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"
}


and this is found in my /etc/asound.conf :

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"
}


Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Sun May 10, 2020 1:17 am

this is the strangest thing. Is there any way playing a simple speaker test with what you gave me set something up? I'm trying my best to recreate the problem now, there's no way that fixed something??? Just a fluke? I played that sine sound for over 3 hours. Went back to Mopidy software to play some music after, it hasn't reoccurred since? I've tried reboot'ing the Pi and playing music for close to an hour now.

The only thing I tried doing to solve this was snip the connection where I made a bridge from GAIN and GROUND on the Amp which gives it a nice +3DB boost, but I was convinced that wasn't a problem and I DID test my sound after removing the gain boost and it still happened.. It's only since putting in your command and playing music after that the problem disappeared so far today..

Crossing fingers but there's no way this fixed itself :mrgreen: :?: :?: :?:

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2351
Joined: Thu Jul 11, 2013 2:37 pm

Re: PWM audio playback Noise/Screech after few moments

Mon May 11, 2020 11:59 am

The command just proves that there is a case where it *can* work correctly, but doesn't necessarily mean that it caused the setup to work correctly.

One thing that the distortion does sound like is a bit inversion or shift - if your signed audio samples get shifted up by one, then a magnitude bit can end up in the sign bit position - so the distortion is a) loud b) random.

There's several things that could cause this
- Frame sync is in the wrong place with respect to data
- Data is transmitted on the wrong clock edge
- The clock signal is of poor quality so the edge is sampled twice

I'd double check your wiring, and signal integrity with an oscilloscope if possible. Failing that, can you play different sample rates or bit formats and see if the problem comes back?
Rockets are loud.
https://astro-pi.org

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Mon May 11, 2020 4:51 pm

I swear to you, the absolute last thing I did before implementing your command and testing was unbridged ground and gain to remove 3db of boost to the Amp. Absolutely nothing else, and doing that was not the answer, still had noise.

I cannot explain it, but I've tried higher volumes , different types of music, if the problem was going to come back it would have already. It really doesn't make sense to me but I think just submitting the speaker to that test sound fixed something even though it didn't configure anything. Its mind boggling to me.

When I setup the speakers originally there is a speaker test but it's not the same c 2 -t sine as you've suggested.

-So you say Frame sync could be in the wrong place, I have no idea how or what that could mean..

-data transmitted on wrong clock edge? Well BCLK and lrck or however they are titled are definitely wired from correct output/input and source on the Pi, would it even work at all if they weren't?

-clock signal bad quality -edge sampled twice. Makes a bit more sense to me, I have resoldered what I thought were weak wires in the past but it turns out they were fine and the signal wires seem pretty sturdy and have a good connection as does everything now .

Honestly though, it's going on 3 days of testing now and it honestly has been flawless so far, I plan on adding Gain back to the amp to raise the lower/volume and I don't think the problem will come back otherwise that would be the culprit

I'm not that technical to have an oscilloscope lying around unfortunately haha, do you have some suggestions on how to play different sample rates or bit formats so we can further test this?

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Tue May 12, 2020 6:07 am

There very well could be a cold solder or maybe even damage to pin 4 for 5v to the amp. After a longg time the noise came back for a moment and then my wire snapped at the solder on that pin, I had to order new solder wire so I will test after repair and see how it holds up

Remembered
Posts: 13
Joined: Wed May 06, 2020 11:45 pm

Re: PWM audio playback Noise/Screech after few moments

Wed May 20, 2020 10:33 pm

Nope, the problem really is still there. Audio seems a little better as it doesn't completely die, it comes back but there are these intermittent terrible scratching noises. See this new video; https://www.youtube.com/watch?v=gjb2gMtDP38

:S is it a buffering issue maybe? What's happening :shock:

Return to “Advanced users”