dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Crackly audio through 3.5mm jack

Wed Sep 26, 2012 7:08 pm

wondras wrote: 1. Will these firmware tweaks result in any significant CPU overhead while audio is playing?
Possibly on millerpuckette's test app as that will run on the ARM, but once we've found a "best quality" algorithm, the code will be run on the GPU, so no affect on the ARM.
The GPU has a 16-way simd engine for things like this, and the cost is likely to be negligable.

millerpuckette
Posts: 22
Joined: Tue Sep 11, 2012 4:25 am

Re: Crackly audio through 3.5mm jack

Thu Sep 27, 2012 4:29 am

wondras wrote: 2. Have you considered using any audio measurement tools to evaluate the quality as you experiment with changes to PWM/dither/etc? There are some free tools that may be helpful:

- RightMark Audio Analyzer
http://audio.rightmark.org/

RMAA uses test WAV files to measure frequency response, noise, THD, etc. It's not perfect, but it can be rather revealing. Even a basic PC sound card should be accurate enough to acquire meaningful results from the Pi's analog outputs.
I've just been using Audacity and looking at the time domain signal so far, but you're right, doing
an FFT or 2 could be a good way to verify things. Being a low-level sort I'll probably just use
Audacity's spectrum plots - they're quite dependable and easy to use.

thanks
Miller

sbp
Posts: 128
Joined: Wed Sep 26, 2012 7:54 pm

Re: Crackly audio through 3.5mm jack

Thu Sep 27, 2012 6:38 am

salts633 wrote:Also squeezeplayer (which has a resource intensive gui) is now working for the first time ever. It used to clip/pop so badly it was unusable. I have noticed that there have been lua library updates recently so this may have contributed to the improvement in squeezeplayer.
Hi I'm very interested in using SqueezePlay, but I haven't been able to find a Raspberry version.
Could you please tell me how you were able to use SqueezePlay on Raspberry?
piCorePlayer webpage: https://sites.google.com/site/picoreplayer/home

Killerbee
Posts: 62
Joined: Tue Sep 20, 2011 6:38 pm

Re: Crackly audio through 3.5mm jack

Fri Sep 28, 2012 3:22 pm

sbp wrote:
salts633 wrote:Also squeezeplayer (which has a resource intensive gui) is now working for the first time ever. It used to clip/pop so badly it was unusable. I have noticed that there have been lua library updates recently so this may have contributed to the improvement in squeezeplayer.
Hi I'm very interested in using SqueezePlay, but I haven't been able to find a Raspberry version.
Could you please tell me how you were able to use SqueezePlay on Raspberry?
Squeezeslave for raspbian can be found here.
http://allthingspi.webspace.virginmedia.com/lms.php

User avatar
Paul Webster
Posts: 822
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: Crackly audio through 3.5mm jack

Fri Sep 28, 2012 5:11 pm

and I wrote about doing it from first principles here
http://dabdig.blogspot.co.uk/2012/05/ru ... ry-pi.html

sbp
Posts: 128
Joined: Wed Sep 26, 2012 7:54 pm

Re: Crackly audio through 3.5mm jack

Sat Sep 29, 2012 8:48 am

Hi Paul, yes I have seen your fine blog about SqueezeSlave,

But do you know how to do the same using SqueezePlay? The reason is that some of my favourite radio streams can't be played through SqueezeSlave (wrong sample rate) whereas SqueezePlay can play these streams fine.
piCorePlayer webpage: https://sites.google.com/site/picoreplayer/home

User avatar
t1ger
Posts: 38
Joined: Sat Aug 18, 2012 12:08 pm

Re: Crackly audio through 3.5mm jack

Sat Sep 29, 2012 3:56 pm

sbp wrote:Hi Paul, yes I have seen your fine blog about SqueezeSlave,

But do you know how to do the same using SqueezePlay? The reason is that some of my favourite radio streams can't be played through SqueezeSlave (wrong sample rate) whereas SqueezePlay can play these streams fine.
Hi

I prefer squeezeplay big time , but you can make squeezeslave to work with radio @ 48KHz

What you need is a custom-convert.conf to resample 48 -> 44.1 KHz in yor LMS
ex mp3 lame resample or aac (faad)

salts633
Posts: 9
Joined: Sat Sep 01, 2012 7:37 pm

Re: Crackly audio through 3.5mm jack

Sat Sep 29, 2012 4:25 pm

I got squeezeeplay to compile following these instructions


http://www.raspberrypi.org/phpBB3/viewt ... 35&t=15555,

there's a more recent post about it here

http://www.raspberrypi.org/phpBB3/viewt ... 35&t=18395.

However it's not working perfectly. After several minutes of good playback it starts stuttering and eventually breaks up really badly.

User avatar
t1ger
Posts: 38
Joined: Sat Aug 18, 2012 12:08 pm

Re: Crackly audio through 3.5mm jack

Sat Sep 29, 2012 6:34 pm

salts633 wrote:I got squeezeeplay to compile following these instructions


http://www.raspberrypi.org/phpBB3/viewt ... 35&t=15555,

there's a more recent post about it here

http://www.raspberrypi.org/phpBB3/viewt ... 35&t=18395.

However it's not working perfectly. After several minutes of good playback it starts stuttering and eventually breaks up really badly.
Hi, My playback work flawless (44.1KHz)
My version of Squeezplay is ,Firmware: 7.8.0-r9704M.
And i'm using usb dac for playback.
I'm using 240MB Firmware setting and cpu usage is about 30%.
I have 2 of them (RPI's) and one of them has alsa filter also.

sbp
Posts: 128
Joined: Wed Sep 26, 2012 7:54 pm

Re: Crackly audio through 3.5mm jack

Sat Sep 29, 2012 7:10 pm

Hi t1ger

I really would like to try your version, would it be possible for you to allow me to try download and try your Squeezeplay for Raspberry?

I know that I can make a conversion in LMS to 44100 for squeezeslave, but then synchronization to my Logitech Duet becomes impossible, whereas I think SqueezePlay would synch nicely (at least the windows version do)
piCorePlayer webpage: https://sites.google.com/site/picoreplayer/home

User avatar
truehl
Posts: 642
Joined: Sun Mar 04, 2012 6:47 pm
Contact: Website

Re: Crackly audio through 3.5mm jack

Sun Sep 30, 2012 2:14 pm

The official version for Debian hf can be find here: http://code.google.com/p/squeezeslave/d ... z&can=2&q=
truehl
http://www.squeezeplug.de

kilokahn
Posts: 22
Joined: Sun Sep 09, 2012 3:41 am
Location: Tallmadge, OH, USA
Contact: Website

Re: Crackly audio through 3.5mm jack

Thu Oct 04, 2012 9:34 pm

I am curious the update on this, especially initializing the DAC on boot up, so it's always live and active and then stopping the crackle when the CPU is getting taxed. I am just using MPD for my solutions, so that may help matters some.

Thanks!
Chris Haslage, Owner
NexMix.com Productions

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: Crackly audio through 3.5mm jack

Mon Oct 08, 2012 2:36 pm

kilokahn wrote:I am curious the update on this, especially initializing the DAC on boot up, so it's always live and active and then stopping the crackle when the CPU is getting taxed. I am just using MPD for my solutions, so that may help matters some.

Thanks!
The popping between songs is a killer for me. I'm curious as well regarding this being fixed in the PI, is it a hardware issue or just some more tweaking with the drivers?

One way around the popping that works for me is to use gapless playback

Code: Select all

#!/bin/bash
# mpgapless

case "$@" in
   *.m3u) PL="-playlist"
   ;;
esac

rm /tmp/audiofifo
mkfifo /tmp/audiofifo
aplay -t raw -c 2 -f S16_LE -r 48000 /tmp/audiofifo &> \
/tmp/aplayfifo.log & mplayer -noconfig all -nolirc -nojoystick \
-novideo -benchmark -vc null -vo null -ao pcm:fast -af resample=48000 -nocache \
-ao pcm:nowaveheader:file=/tmp/audiofifo $PL "$@"

User avatar
truehl
Posts: 642
Joined: Sun Mar 04, 2012 6:47 pm
Contact: Website

Re: Crackly audio through 3.5mm jack

Mon Oct 08, 2012 8:58 pm

Hi,
I found an issue with SqueezeSlave and the latest Firmware!

The firmware on my actual testing Image for the new SqueezePlug image is Kernel 3.2.27+ #244 from 6.10. FW is 342154. It seems there is a bug in this FW. SqueezeSlave stops after only a few songs! If you downgrade to Kernel 3.2.27+ #168 from 22.9. FW 338882 everything is running stable. I'm running SqueezeSlave with this FW for over 7 days now without any fault.

Do you have an idea about this?
truehl
http://www.squeezeplug.de

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Crackly audio through 3.5mm jack

Mon Oct 08, 2012 9:24 pm

truehl wrote:Hi,
I found an issue with SqueezeSlave and the latest Firmware!

The firmware on my actual testing Image for the new SqueezePlug image is Kernel 3.2.27+ #244 from 6.10. FW is 342154. It seems there is a bug in this FW. SqueezeSlave stops after only a few songs! If you downgrade to Kernel 3.2.27+ #168 from 22.9. FW 338882 everything is running stable. I'm running SqueezeSlave with this FW for over 7 days now without any fault.

Do you have an idea about this?
Yes. Known issue. It is being worked on:
http://www.raspberrypi.org/phpBB3/viewt ... 4&p=190335

nickb
Posts: 1
Joined: Tue Nov 27, 2012 7:34 am

Re: Crackly audio through 3.5mm jack

Tue Nov 27, 2012 8:19 am

Sorry to resurrect an older necro-thread, but I thought I'd add a smidgen of background to the PWM audio thing. At the moment it seems like RPi is attempting to use the PWM mark/space mode to produce audio output (as per Miller's code posted earlier in the thread) -- if in-fact you've got something better in the firmware please feel free to ignore everything I have to say!

Audio over the PWM controller was always supposed to have used the PWM-serialiser mode with a sigma-delta modulator loop running in software to generate the data at an over-sampled rate. Generally this should cause a degree of noise shaping and more importantly the majority of the noise should be pushed to a frequency well above the f_c of the output filter (see this diagram http://upload.wikimedia.org/wikipedia/c ... aNoise.svg on Wikipedia).

I've hacked Miller's play_waveform function to illustrate what should be done; note for this to work it assumes that the PWM peripheral is in the serialiser mode and is outputting bits at 32 x sample_rate (ie over-sampling ratio of 32); I don't have an RPi board or build environment so I'm unsure of how to set up the clock manager from the ARM -- you'll need to do that. Note that I've assumed that the audio input format is actually signed 16-bit integers -- instead of Miller's float samples.

Code: Select all

/* Assume that sample input format is 16-bit / 48kHz */
static void play_waveform(int16_t *samples)
{
    static unsigned acc = 0;
    int i, bit, nprint = 0;
    unsigned data, ir;

    /* control register :- enable fifo serial output mode on both channels */
    poke(BCM2835_PWM_CONTROL, 
         BCM2835_PWM1_USEFIFO | 
         BCM2835_PWM1_SERIAL  |
         BCM2835_PWM1_ENABLE  | 
         BCM2835_PWM0_USEFIFO |
         BCM2835_PWM0_SERIAL |
         BCM2835_PWM0_ENABLE);

    /* NOTE: Use an OSR (over sampling rate) of 32; this means that the PWM clock
     * should be set to a bit rate of 1.536MHz (use the fractional divider to achive
     * this). */

    for (i = 0; i < 2*nsamples;)
    {
        long status =  peek(BCM2835_PWM_STATUS);
        if (!(status & BCM2835_FULL1))
        {
            if (i & 1) /* only compute for left channel; reuse for right */
            {
                /* generate 32 1-bit samples with a sigma-delta
                 * noise shaping scheme */
                for(bit = 0, data = 0; bit < 32; bit++) {
                    ir   = samples[i/2] + 0x8000 + acc;
                    data = (data << 1) | ((ir >> 16) & 1);
                    acc  = ir & 0xffff;
                }
            }
            poke(BCM2835_PWM_FIFO, data);
            i++;  
        }
        if (status & ERRORMASK)
        {
            if (i < MAXPRINT)
                fprintf(stderr, "error %x\n", status);
            nprint++;
                /* clear errors fo next time around */
            poke(BCM2835_PWM_STATUS, ERRORMASK);
        }
    }
}
You would be able to get better noise shaping characteristics with a higher order s-d modulator -- but a 1st order modulator should be okay, and I believe that a lower over-sampling rate of 16x would work fine. The inner loop should be fine to vectorise on the GPU too. You should be able to achieve something much closer to a 16-bit analogue output with this.

Nick B.

pitt
Posts: 13
Joined: Fri Dec 28, 2012 4:06 pm

Re: Crackly audio through 3.5mm jack

Thu Jan 31, 2013 3:07 pm

I agree to ski522,

the popping noise between songs is a real show stopper for all serious sound applications. The issue is known for quite a while now, but nobody seems to take care of it. How can I convince kids in a computer science classroom that the Raspi is a cool thing to have when they hear that popping noise between their favourite songs?? In my eyes this problem is pretty important because it is a pain in the neck for quite a lot of people (in fact for anyone who listens to the Raspi over the 3.5mm jack).
There are a number of workarounds out in the forum, but all have drawbacks and/or bugs that can't be ignored.
Hack! Is this problem that hard to fix?? I'd be really happy to help, if somebody (mahjongg, dom?) would point me to the right piece of software. I have already looked into the 3.6.11 kernel sources, but did not find anything to begin with. Is the problem located in the secret part of the firmware?
HELP!!!

Pitt

User avatar
theoB610
Posts: 233
Joined: Sat Jan 05, 2013 12:40 pm
Location: Devon

Re: Crackly audio through 3.5mm jack

Sat Feb 02, 2013 1:38 pm

dom wrote: But, I've pushed out new firmware with the extra bit. Please test and comment on the quality.
I've got a new de-popping scheme for ALSA (OpenMAX will stil pop for now).
Sorry for being stupid and re-resurrecting this thread.
Put simply, how do I stop the crackles/popping? I haven't really got much of this discussion.

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: Crackly audio through 3.5mm jack

Sat Feb 02, 2013 1:41 pm

Buy a USB sound card...easiest way right now.

salts633
Posts: 9
Joined: Sat Sep 01, 2012 7:37 pm

Re: Crackly audio through 3.5mm jack

Sat Feb 02, 2013 2:19 pm

sorry if 'm stating the obvious but is your system completely up to date? Make sure you've used "rpi-update" and "sudo apt-get update && sudo apt-get upgrade". Don did a lot of work on this several months ago that fixed the sound problems for the built in audio, at least for the squeezeplay/squeezelite players.

User avatar
theoB610
Posts: 233
Joined: Sat Jan 05, 2013 12:40 pm
Location: Devon

Re: Crackly audio through 3.5mm jack

Sat Feb 02, 2013 6:03 pm

I'm still getting distortion and crackles when using yoshimi.

Return to “Graphics, sound and multimedia”