Pirate Radio Audio Issue - Scratchy

Hi –

I received two Pimoroni Pirate Radio kits for Christmas and, although they work, the
audio is really, really scratchy. I’ve run though the forums and can’t find anyone
whose had the same problem.

I followed the mechanical assembly instructions at

https://learn.pimoroni.com/tutorial/sandyj/assembling-pirate-radio

which went quite well. I then installed Raspian Stretch lite
(2017-11-29-raspbian-stretch-lite.zip), then followed the instructions
to install Pirate Radio at

https://learn.pimoroni.com/tutorial/sandyj/internet-radio-on-your-pirate-radio

which also went well. I was able to add my own radio stations and to SSH into
the Raspi, so all was well.

However, I was very unsatisified with the audio, which sounds clipped and
scratchy. I replaced the Pirate Radio speaker with a different, higher-quality
speaker. No joy. I then connected an oscilloscope across the two terminals of the
original Pirate Radio speaker and saw:

DS1Z_QuickPrint1.png

which was not what I was expecting. The volume was fairly low at this point
(only one LED of the VU meter lit). Zooming in on waveform above revealed:

DS1Z_QuickPrint2.png

(See next post. New users can upload only one image per post)

which is a pulsed signal at about 650 kHz. I tried several variations of
radio stations and re-installed a couple of times. No joy.

When I run

speaker-test -t sine -f 1000

which generates a 1 kHz sine wave, I see the following across the speaker
terminals:

DS1Z_QuickPrint7.png

(See next post. New users can upload only one image per post)

I have two Pimoroni Pirate Radio kits and they both behave the same. Of course, I
could have made the same mistake on both of them.

Any help? Thanks.
Kevin

DS1Z_QuickPrint2.png, for previous post

DS1Z_QuickPrint7.png, from previous post

Sorry for the radio silence, I’m trying to get this under the nose of our engineers who might have an idea what’s gone awry.

There seem to be a few people reporting scratchy/distorted audio and I’m not yet sure if there’s any relation between these.

I’m an oscilloscope newbie so without the intuitive link of the audio playing and the scope trace running live I can’t draw any conclusions from it. Something in this case doesn’t look quite right, though, since although there should be a very high-frequency PWM component I would expect to see an approximation of a sine wave and not what appears to be a clipped, low-amplitude sine with weird offsetting.

With some artistic license, it does look like there’s an extremely distorted sine wave in there:

hidden-sine-crouching-tiger

Could you try this experimental Pirate Radio distro and see if it helps? http://get.pimoroni.com/pirateradio-v20171113.zip

Needs to be unzipped to the root of a blank SD card, and the wpa_supplicant.conf edited with WiFi details.

Thx. Will try today.

The sine wave almost looks like you’re sending the wrong format of data to the MAX98357 (e.g. sending signed data instead of unsigned data). As the value fed to the MAX chip increases from zero to max, the most significant bit flips. If the MAX IC misinterprets the most significant bit as a sign bit, it would cause the sine wave as shown on the scope trace.

Even with this kind of distortion, the human ear is pretty good at pulling out recognizable information.

Kevin

Yes. That sounds much better. Will you be rolling that into the main branch? Any idea what the difference is?

Kevin

One minor note: This version exhibits some nasty clicking when you change stations and when it first powers on.

Kevin

The main difference between the two is that the PiratePython Radio image lacks Pulse Audio, and instead has a low-level kernel tweak to prevent the i2s bus going into a state that the PCM5102A doesn’t like. This means the i2s stops and starts between tracks and causes popping- which is what Pulse Audio is installed - for better or worse - to prevent.

It looks like the problem lies in the Pulse configuration, but this has worked for me in the past! I don’t get back into the office until tomorrow, so I can’t run any tests yet, but your hypothesis about a format mismatch seems fairly promising and would be the sort of thing Pulse might introduce.

No worries. Figured the holidays would cause delays. The Pirate Radio kit is a neat little box. Very capable.

Kevin

I’ve imaged a fresh copy of Raspbian Stretch Lite 2017-11-29, from here: https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-12-01/

Used our installer: curl get.pimoroni.com/vlcradio | bash

And rebooted to thunderously loud audio (not the best start).

But once I get the volume down to sane levels, it seems reasonable. Not the best audio quality, but not scratchy. No matter what I try with the scope (connecting it across the speaker terminals seems to result in bad times) I can’t reproduce what you’re seeing. I see a clean square wave with a 3us period.

Hi Gadgetoid –

Thanks for the response. Unfortunately, I’m away for a week and don’t have my equipment with me so I can’t play with hardware, take screenshots, etc.

I took my oscilloscope screenshots directly across the speaker terminals. The negative terminal of the speaker isn’t connected to Earth ground so you might have trouble if you’re powering the Raspi from the USB port of a grounded computer. You might have better luck measuring across the speaker terminals if you power the Raspi from a two-prong USB power supply (i.e. one without a ground terminal on the mains plug).

Did you try running “speaker-test -t sine -f 1000” and, if so, did you get a picture like DS1Z_QuickPrint7.png above?

Regarding, “I see a clean square wave with a 3us period.” Do you see something like DS1Z_QuickPrint2.png above? I believe the two ICs on the Phat Beat boards are MAX98357 (correct me if I’m wrong, please). The data sheet is at

The IC sends pulses to the speaker at a 300 kHz rate so your 3us period seems consistent. The pusles are too high in frequency to hear but the scope can see them. You have to put the speaker waveform through a 10 kHz low-pass filter to see the actual audio (and, of course, I didn’t take a screen shot of that but it is clipped).

Sorry to be such a bother about this. I’m pretty stoked about the Pirate Radio kit and would really like to improve the audio.

Kevin

We have the same issue here, scratchy / hot / clipped / distorted / overdriven audio from the Pirate Radio kit. Even with the volume very low the signal is distorted. Loaded the experimental Pirate Radio distro and it sounds much better but then my keyboard doesn’t work with that distro. Reloaded Raspbian lite and piped the script to bash and have the same distorted audio signal result. We also suffered the “thunderously loud audio” following the first reboot.

Thank you Kevin for the thorough description of the problem and thank you gadetoid for looking into it.

@mcckevin no problem- thank you for your report thus far, I’m still investigating. I’ve been using the same 1kHz test sine wave. Unfortunately my scope is thin on the ground with LPF options, and running the low-pass Math routine still doesn’t give me an output resembling a sine wave at any frequency other than that of the AMPs PWM signal into the speaker.

Yes the DAC/AMP chips are MAX98357.

@rockey could you snap a photo of the underside of your board?

Could you also try running:

sudo systemctl stop pulseaudio
sudo systemctl restart vlcd

Don’t reboot, just wait for it to resume playing and see if this improves sound quality.

I’m not sure which is the underside of the pHAT BEAT board. FOO7768 is silk screened on the other side.

I did try running those commands to stop pulseaudio and restart vlcd but vlcd would not restart. I rebooted and just tried restarting vlcd and it would not start. Couldn’t find any log or error describing why.

I didn’t mention earlier the I have been updating Raspbian before piping the script to bash. Not sure if that’s relevant. Sysadmin habit. ;)

  1. boot fresh image of 2017-11-29-raspbian-stretch-lite.img
  2. set wpa_supplicant.conf
  3. sudo apt-get update && sudo apt-get upgrade
  4. curl https://get.pimoroni.com/vlcradio | bash
  5. sudo reboot

I do get different results from speaker-test -t sine -f 1000 before and after stopping pulseaudio. With pulseaudio stopped speaker-test reports that it’s “Using device: phat-beat” When pulseaudio is started speaker-test doesn’t output that Using device line.

sudo systemctl stop pulseaudio
sudo apt-get -y purge "pulseaudio*"
sudo reboot

Much better.

D’oh. I’d feared as much!

I was trying to switch Pulse on/off yesterday and test between the two, but it’s not easy. It did appear to be better without.

Thanks Kevin, Rockey and gadgetoid
I also had similar scratchy sound quality problems with my pirate radio Christmas purchase. Stopping pulseaudio really improved things a lot.

Hallo, like the original poster, I was having severe distortion on my completed Pirate Radio Kit. I am using the Stretch version of Linux.The distortion sounded like severe clipping, I reduced the alsamixer gain to 60% which seemed to help, but the distortion remained. The audio stream for WSMAM was completely distorted. Just a total mess. After reading the above suggestions I have removed pulseaudio as suggested. The sound is now very much improved. The WSM stream is now playing perfectly. I am new to Linux, but the instructions have made sense, and solved my problem. The “clicks”, at first boot, and changing stations, seem no worse without pulseaudio.
Many Thanks, Peter.

The new pHAT BEAT release has a hardware fix for this, so it dampens them quite drastically and Pulse Audio is not needed at all. You can sudo systemctl disable pulseaudio safely.

However the reason Pulse Audio got involved in the first place is to prevent a condition where ALSA would output a bonkers signal to pHAT BEAT and cause it to drive a constant +5v through the speaker :(

For users with the older pHAT BEAT (probably if you purchased before December 2017) - Pulse Audio is recommended to avoid getting into this situation. Or alternatively sticking with Jessie which did not cause the problem at all.