Pirate Radio Audio Issue - Scratchy

The two I listen to most frequently are

http://wtmd-ice.streamguys1.com/wtmd.m3u
http://wtmd-ice.streamguys1.com/hd2.m3u

You can often hear the difference if you play the same stream simultaneously on vlc and on the PirateRadio board. Also, I’m not convinced that the distortion happens all the time (which, of course, makes debugging harder). However, I and others noticed the distortion enough to comment.

The hard part is that the MAX98357 doesn’t send clean audio to the speaker. It sends a pulse width modulated waveform, which is more difficult to examine for problems like this.

1 Like

Hallo to the Team,
Firstly, the radio kit was a Christmas Present from my sister, probably bought in December 2017.
I installed “Stretch”, with no GUI.
The radio worked immediately, my first impressions were that the VU Meter was not very active, and on some of the pre-programmed audio streams I could hear clipping type distortion.
Then I created my own playlist :

http://sc3.radiocaroline.net:8030
http://sc6.radiocaroline.net:8040
http://icecast.omroep.nl/radio5-bb-mp3
http://icecast.100p.nl/100pctnl.mp3
http://icecast.omroep.nl/radio2-bb-mp3
http://listen.shoutcast.com/abcloungeradio
http://stream01048.westreamradio.com:80/wsm-am-mp3

Before I compiled the playlist, I tested all the audio streams using VLC Player running on my desktop computer, and they all performed well.

When I listened to the same streams on the “Pirate Radio”, I could hear varying amounts of distortion due to clipping at the higher audio levels.
The WSM stream was just a complete distorted mess, although on “music fades”, the audio would become clear at very low levels. Due to the heavy processing, those intervals were quite rare !
It sounded like I needed to reduce the gain in the VLC Player Module, but I couldn’t find that control. I did reduce the alsamixer volume control, and it did seem to help to a small extent, but the clipping was occuring earlier in the signal path.

The WSM stream is 64 k mp3.
The Caroline :8030 stream is 96k aacPlus.
The Caroline :8040 stream is 128K mp3.

Since removing pulseaudio the radio sounds very good and to my ears, the audio sounds clean.

I hope you will be able to reproduce my results, and that this will prove helpful.
Best Regards, Peter.

1 Like

Hi, further to what I have already written, I have just checked the operation of the radio.
Now, without pulseaudio, when I “pause” the stream, middle top button, I measure 5 Volts DC across the speaker.
I don’t use this button, but did have the audio stream stop a short while ago.
I am now wondering whether the 5 Volts would also appear under those circumstances.
So long as the radio plays normally, there is no DC across the speaker.
Regards, Peter.

Hallo Team,
after removing pulseaudio I had the problem of an overheated speaker coil due to application of 5 Volts DC. The audio stream had stopped, and the output device placed the DC supply voltage across the speaker.
Today I re-installed the original software from Pimoroni.
The heavy clipping problem re-appeared immediately, and I have spent the day tracking down the problem.
In the ~/.config/vlc Directory I have edited the vlcrc file.
Scrolling down the file contents, about page 76, there is a series of audio controls.
In the entry :

Audio gain (float)

#gain=1.000000
I have added (new line) :
gain=0.25

I tried a value of 0.5
That was noticeably better, but still with clipping.
Using 0.25 seems about right.
ymmv.
I just read the latest posting from Kevin.
The clipping is due to the output from the VLC Player module overdriving the later stages.
Removing pulseaudio fixes the problem, but introduces the serious problem of DC applied across the speaker.
Changing the VLC gain allows pulseaudio to work properly.
On my radio, the audio is now excellent, and the VU Meter is operating at a better level, more responsive.

Best Regards, Peter.

All –

I spent some time today grabbing captures from my oscilloscope and playing around with them. Unless specified, pulseaudio is running. I connected the oscilloscope probe and ground directly across the speaker supplied with the Pimoroni Pirate radio so there are the waveforms the speaker sees.

First, I put a 1 kHz sine wave on the speaker with

speaker-test -t sine -f 1000 -S 80

and took the following screenshot from the scope:

Note how the scope plot looks like it might have problems at the peak of the waveform.

I captured the raw data from the scope and applied a 10kHz low-pass filter, which produced

filtered

The blue trace is the data captured from the scope and the orange trace is the filtered data.

This surprised me. I though I would definitely see clipping but the digital mess from the scope produces a pretty clean sine wave once you filter it. So, the speaker-test utility is working correctly.

Next, I captured some audio from the Pimoroni Pirate radio. I turned the volume up until about half the LRDs were lit and captured the following data from the scope:

I filtered at 10kHz to produced

pkl

I believe you can see the clipping in the filtered signal (e.g. the flat parts around -2V and +2V).

With the volume turned down such that only the lower LEDs are lit, I captured and produced

Filtering =>

filtered

I had to zoom in on the filtered signal, but you can still see the clipping.

When I disabled pulseaudio, I captured (at 50% volume)

hich produced a filtered signal of

filtered

and the clipping seems to be gone.

Thanks @mcckevin that’s some really useful sleuthing, and it seems to correlate now with what I hear when enabling/disabling PUlse.

Lots of bashing my head against Pulse and while I can definitely re-create these problems to varying degrees I can’t seem any way to properly solve them.

The closest to a solution is @G3WZG’s suggestion to reduce VLCs gain setting, but Pulse Audio is still applying a tremendous amount of gain that it shouldn’t be applying. This means the VU Meter activity is pathetic, lighting the first couple of LEDs until volume is unbearably loud.

I have a VU Scale option coming in Pi VU Meter to compensate for this, but crushing the gain in VLC and then expanding it in Pulse can’t be doing the sound quality any favours.

I wonder if this is related to: https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1311525

Just happened on this thread after doing a search. I’m having the same poor audio on my Pirate Radio / pHat Beat in Stretch. Pirate Radio poor audio quality. (Rasbian Stretch)
Mine is an older pHat Beat, which, if I’ve read things correctly, is why I’m having this issue. I went to Stretch to get rid of the pops etc when changing channels. I guess I need to go back to Jessie?
The last install I tried to do on Jessie failed though. I got no sound no matter what I tried. Just pops when pressing buttons. Redid it several times with the same results, would not work. I’m currently running a backup image I made way back of a working Jessie full install. Sound quality is good but the pops are annoyingly there when I change channels etc. What do I do now?

Ok, your Pirate Radio installer does not work (for me) with Jessie. I get nothing but a few pop sounds on boot up. No VU meter and no sound at all. Pressed every button repeatedly, the only one that does anything other than generate a pop sound is the power button that does a shut down. I tried it multiple times all with the same results.
In Stretch its very poor audio quality that’s not worth listening too. No pops on channel change though.

So what is one to do now? If I was to buy a new pHat Beat would my problems be solved?

Reading thru lots and lots of conversations on phatbeat forum, I have got the impression there is an updated version hradwarewise on the market. @gadgetoid, could you please explain differences as compared to previous version(s) .

A bit late but here is one stream that definitely sounds better with Pulse Audio disabled

https://energybasel.ice.infomaniak.ch/energybasel-low.mp3

Interestingly the test programmes sound fine.
Thanks for continuing to look into this issue. The support from Pimoroni - and the sense that you guys are really trying to help - definitely makes me consider buying more of your gadgets.

IMHO Pimoroni are top notch, support wise. Much better support than some of the other product support sites I’ve been on. Keep in mind its the weekend. They have a life too. ;) I imagine we’ll get some feedback Monday some time. I’m chilling out to some classic rock on my Pirate Radio as I type this. I had a backup image from an older working install I made a while back. I get a few pops when changing channels but the audio is nice and clean.

@calleblyh

there is an updated version hradwarewise on the market

Yes. We realised shortly after the switch from Jessie to Stretch that Pulse - which was previously installed by default and part of the audio stack - had been removed entirely. This exposed what I still believe to be a bug in ALSA (although I’ve had a whale of a time tracing it back) where it would run the I2S clock even when no data was being output. This has the unfortunate side-effect of causing the attached DAC to clamp the left/right terminals to +5v and GND, causing a constant current through the speaker :( (Note: This is bad!)

After much searching for a viable software fix, we decided to roll a small update to the hardware in the form of a transistor/capacitor gate on the clock signal. A capacitor is charged up by the I2S frame-sync/LRClock (this is the signal that tells the DAC whether the left or right audio data is currently being sent) and this capacitor opens a transistor that otherwise gates the clock line. This elegant fix makes the board immune to otherwise invalid signals.

Now, my conundrum is that software has no way of telling between the old board and the new board so I’m forced, in all cases, to take precautions as if it were the old board to prevent things going awry.

Unfortunately those precautions have had some side-effects in Jessie which I’d failed to catch, and they also produce scratch/awful audio under some circumstances.

In my PiratePython Radio software I cheated. I went right down to the base I2S kernel module and hacked it to squash the bug- eliminating the need for PulseAudio on either version of the hardware.

Welcome to my world ;)

Hi,
I bought the Pirate Radio Kit a few days ago,
did everything as posted in the tutorial and had the same issues.

The scratchy sound could easily be changed to great sound.

Just edit vlcd in /usr/bin:

sudo nano /usr/bin/vlcd

and change: --compressor-makeup-gain 12.0
to: --compressor-makeup-gain 0

this compressor should just be used as a limiter and needs no makeup gain…

I thought about sending it back to Pimoroni but now I’m impressed by the sound.

Greetz, CSX

2 Likes

^ it can’t be this simple? :D

I’d totally overlooked the VLC command-line options I had crafted. How could I be so stupid.

I’m going to have to try this. Thank you @csx333

Welp all!

@csx333’s solution works for me! I’ve changed the code on GitHub so future users should get the scratch-free-audio. If you don’t want to reinstall, then make the change as marked in the solution here, it’s a one-line tweak to /usr/bin/vlcd.

facepalm

I couldn’t see the wood for the trees, and didn’t have a rubber duck to question my intentions!

Thank you @csx333

1 Like

I have a spare SD card so I’ll give it another try with Full Stretch.

EDIT: Have to wait for my wife to get out of bed first though. Last time I tried it, it started on full volume. That wouldn’t go over very well with her still asleep, if you know what I mean. ;)

1 Like

Just did up a new card with Stretch and ran the one line installer. Audio was still scratchy, but after manually doing the edit above it sounds Ok. Mine was showing compressor-makeup-gain 12.0. I changed it to compressor-makeup-gain 0.0. No pops on channel change either. Good sleuthing guys and gals. Insert large thumbs up smiley here.

I do have one further suggestion though. Reduce the volume from max on first boot up.;)
That’s the only time I’ve ever seen all the LED’s on, even the RED ones. lol.

1 Like

Worked for me, as alphanumeric described. New card with Stretch and the sudo curl installer. Still scratchy. Manual edit of /usr/bin/vlcd and all is well.

Thanks, all.
Kevin

1 Like

Allways glad to support the support … ;-)

Thank you @csx333!

I’ll look into the super-loud-audio-on-first-boot issue, there must be a fix for that.

I already have a fix for the VU, but it’s not very elegant. It involves setting a vu-scale value in the asound.conf which controls what the upper-bound is for scaling the LEDs. I really need to get some sort of moving average in place, since the goal is to have a pretty VU, and not necessarily an accurate one.

Pi VU Meter is teetering on the edge of a move to mostly-Python, but it’s one of those cans of worms I’ve been afraid to open!