fredfs
Posts: 58
Joined: Sun Jun 07, 2015 12:22 am

Re: Analogue audio redux

Tue May 28, 2019 11:41 pm

On most recent firmware (archlinux-arm)
using audio_pwm_mode=2
makes MPD music sound slower, like some frequency rate error.
audio_pwm_mode=1, sound good.

pik33
Posts: 198
Joined: Thu Sep 10, 2015 4:26 pm

Re: Analogue audio redux

Thu Jul 11, 2019 7:24 am

Some time ago I wrote this driver for a RPi bare metal environment (Ultibo). It uses 2nd order noise shaping filter and ~960 kHz 8-bit samples. It can still be improved, but as it is now, it is clip free and doesn't create distorted sound even at 100% volume.

https://github.com/pik33/SimpleAudio

Maybe it can be used to improve the RPi audio jack sound quality.

Can someone tell the addresses of the hardware registers in RPi4 so maybe I can try it on this machine?

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

Re: Analogue audio redux

Thu Jul 11, 2019 5:50 pm

From my reading of the assembler loop, you are "oversampling" by repeating the input sample used for the quantisation and noise shaping, correct?

This is suboptimal as zero-order-hold (what you're doing) does not significantly band-limit the input spectrum. Noise shaping only works effectively if the input signal is a fraction of the total input bandwidth. The firmware uses a much more sophisticated oversampling scheme to bandlimit the input signal - a length=512/x8 FIR filter followed by a length=4/x2 FIR filter for a very sharp cutoff and minimal stop-band leakage.
Rockets are loud.
https://astro-pi.org

pik33
Posts: 198
Joined: Thu Sep 10, 2015 4:26 pm

Re: Analogue audio redux

Thu Jul 11, 2019 8:26 pm

Yes, the oversampling is simply repeating the sample. I don't need any fitering before oversampling (what for?), and yes, the filter after the oversampling is useful. I have done such filter (simple IIR one) today and I will try to add it and compare the results. The lack of this filter may be a reason I didn't get any good result trying to set the sampling frequency higher than 960 KHz. I have an idea is to use PWM in serializer mode outputting 2nd or 3rd order noiseshaper output at 1bit/7.2 MHz. Using the serializer mode will significantly lower the memory bandwidth needed.

As it is now, in my subjective opinion my driver (on RPi3) gives better sound quality than the original RPi4's driver: I use my RPi3 with my (far from finished) driver, player and GUI code as an audio player :) - everyday :)

The only problem is I had to overclock memory/core subsystem on RPi3 to get a click-free audio @ 960 kHz. There is possibility to lower the frequency to 640 kHz in the code - as I read here you used something about 700 kHz and I think it means fractional divisor on PLL - is it safe to use non-integer division rate for audio? (jitter?)

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Wed Dec 25, 2019 7:39 am

Hi, so I'm very close to starting to use my Pi 4 as desktop, but the static in the headphone jack is a nono.

Any plans of fixing this now around 10 years later?

I mean you can't make an ad stating the latest Pi makes it a desktop and then expect people to listen to static / remove headphones every time they stop the music?

Just realized the Raspberry doesn't have a mic. Oh well I just have to wait until the Raspberry 5 to save the planet.

So close, but yet so far away!

Edit: looked at DAC ADC hats, but the Raspberry 4 has heat issues so the large heatsink I use needs air to cool passively. A Zero sized hat would maybe work but I struggle to find one with a 4-way headphone jack!
Last edited by bullen on Wed Dec 25, 2019 9:39 am, edited 1 time in total.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

LTolledo
Posts: 4833
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Analogue audio redux

Wed Dec 25, 2019 9:34 am

what are your trying to listen to? :shock: audio file with inherent static? :mrgreen:

on my RPi4B-4G Raspbian Buster Full Desktop, I just tried the on-board analog audio using a wired headphone (not those puny earphones), watching youtube videos and vlc video...

no static... no hums.... no distortions.....

are you sure you're powering your RPi4B board properly? using a power supply unit?
if you're trying to power your RPi board using a phone charger..... then all bets are off!!!!

you'll have to wait 10 more years..... while most of us enjoy the current model...
Last edited by LTolledo on Wed Dec 25, 2019 9:42 am, edited 1 time in total.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Wed Dec 25, 2019 9:41 am

I'm using the official Pi 4 power adapter.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

LTolledo
Posts: 4833
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Analogue audio redux

Wed Dec 25, 2019 9:42 am

and I'm not... :D

so you're interested in a DAC HAT the size of a Zero..... try getting the Pimoroni pHAT DAC (offer good while supply last). ;)
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Wed Dec 25, 2019 10:24 am

I need it to have ADC so line in/input/mic.

Atleast this one has a screen: https://shop.pimoroni.com/products/pira ... dphone-amp
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

User avatar
PeterO
Posts: 6095
Joined: Sun Jul 22, 2012 4:14 pm

Re: Analogue audio redux

Wed Dec 25, 2019 11:17 am

bullen wrote:
Wed Dec 25, 2019 7:39 am
Hi, so I'm very close to starting to use my Pi 4 as desktop, but the static in the headphone jack is a nono.
Are you sure your headphone jack is wired correctly ?
The composite video is also on that socket and there is more than one way that the four rings are wired up.
See https://www.raspberrypi-spy.co.uk/2014/ ... ideo-jack/

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Thu Dec 26, 2019 4:46 am

Well it doesn't really matter if there is no microphone you still need another plug.

The foundation really dropped the ball on this one. Composite is not more valuable than microphone.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

LTolledo
Posts: 4833
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Analogue audio redux

Thu Dec 26, 2019 9:17 am

I dont see the microphone as important, and I have no use for it.

if coerced to use one, I'll just plug a cheapo USB sound dongle for that task. :mrgreen:
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Thu Dec 26, 2019 9:32 am

Kids like to talk to each other on the computer.

Nothing is going to change that.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

fruitoftheloom
Posts: 25837
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Analogue audio redux

Thu Dec 26, 2019 9:40 am

bullen wrote:
Thu Dec 26, 2019 9:32 am
Kids like to talk to each other on the computer.

Nothing is going to change that.

A cheapo £2 USB Sound Card is sufficient:

https://www.ebay.co.uk/itm/External-Vir ... 1898196952

The reason composite out was included is that it is already in the VC4 SoC, whereas Mic in is not.....
The information is out there....you just have to let it in.

My other Linux machines are a ChromeBox & Intel CoreDuo Desktop

GeorgS
Posts: 19
Joined: Fri Aug 07, 2020 8:15 pm

Re: Analogue audio redux

Thu Aug 27, 2020 7:01 pm

Is there any chance to provide an alternative actual firmware with the audio redux reverted?

I've been able to use an older firmware ( 3ca4cf4a663c5351eaec08b29d50d6e8324981b4 ) on all my Raspberries until now, was always overwriting the firmware in /boot after updates. It did work with all the 4.x kernels, but doesn't work anymore with the latest 5.4.51 due to some graphics driver changes.
I get the boot rainbow image always showing while the systems are booting. And, some errors in the kernel log:
[ 0.059174] bcm2835-mbox 3f00b880.mailbox: mailbox enabled
[ 0.080384] raspberrypi-firmware soc:firmware: Request 0x00000002 returned status 0x80000001
[ 0.080460] raspberrypi-firmware soc:firmware: Attached to firmware from 2017-04-05 11:49, variant cmd unsupported
[ 0.090406] raspberrypi-firmware soc:firmware: Request 0x00000003 returned status 0x80000001
[ 0.100431] raspberrypi-firmware soc:firmware: Request 0x00030046 returned status 0x80000001
...
[ 1.296107] raspberrypi-firmware soc:firmware: Request 0x00040013 returned status 0x80000001
[ 1.296179] bcm2708_fb soc:fb: Unable to determine number of FBs. Disabling driver.
[ 1.296249] bcm2708_fb: probe of soc:fb failed with error -2
...
[ 6.136821] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned.
[ 6.152520] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 6.158860] [vc_sm_connected_init]: start
[ 6.163435] vc_sm_cma_vchi_init: failed to open VCHI service (-1)
[ 6.163445] [vc_sm_connected_init]: failed to initialize shared memory service
...
[ 6.470784] bcm2835-isp bcm2835-isp: bcm2835_isp_probe: ril.isp returned 1 i/p (1 expected), 1 o/p (3 expected) ports
[ 6.481550] bcm2835-isp bcm2835-isp: Unregister from media controller
...

I'm now in a position to choose between broken sound or broken video.

Thanks!

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

Re: Analogue audio redux

Thu Aug 27, 2020 7:50 pm

Up-to-date firmware is required for 5.4 kernels. You can select the original audio driver with the config.txt parameter audio_pwm_mode=1

Why is your sound broken? Describe your use-case.
Rockets are loud.
https://astro-pi.org

GeorgS
Posts: 19
Joined: Fri Aug 07, 2020 8:15 pm

Re: Analogue audio redux

Thu Aug 27, 2020 9:15 pm

Thanks for the quick reply.
audio_pwm_mode=1 is not an option, quality (hiss) is really bad.

I own a few Pi2B boards, two of them dedicated for multimedia. On one I run Kodi (stuck at LibreELEC 8.5.2 - last release with the working audio firmware) and on the other one I switch between volumio and a web radio app. The audio is crackling constantly on these systems with the audio-redux enabled firmware for both audio and video playback with audio_pwm_mode=2. But this issue has been already repeatedly mentioned in this thread.
Also tested this by playing audio/video/youtube under the latest Raspberry Pi OS, the crackling is there.

I could upload a recording to exemplify, should you need it. Not yet sure where to put it, maybe zippyshare.com

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

Re: Analogue audio redux

Thu Aug 27, 2020 10:31 pm

GeorgS wrote:
Thu Aug 27, 2020 9:15 pm
Thanks for the quick reply.
audio_pwm_mode=1 is not an option, quality (hiss) is really bad.
How is a new firmware with audio_pwm_mode=1 set different from an old firmware with no config options set? They both run the same code.
Rockets are loud.
https://astro-pi.org

GeorgS
Posts: 19
Joined: Fri Aug 07, 2020 8:15 pm

Re: Analogue audio redux

Thu Aug 27, 2020 11:56 pm

I never said I ever used audio_pwm_mode=1 It was your suggestion I replied to.
audio_pwm_mode=2 works fine in all use cases with the older firmware 3ca4cf4a663c5351eaec08b29d50d6e8324981b4

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Fri Aug 28, 2020 9:29 am

@fruitoftheloom No those are worse than the jack on the pi.

But I found two that are $10 and they even look "nice" and have mic input too!

I'll report back when I get the time to try them out!

https://www.amazon.com/gp/product/B07L56C28R/
https://www.amazon.com/gp/product/B07Q1NT97X/

Feeding the Amazon monster... these where shipped from LA to Sweden!?

Image
Image

Trond looks smaller which is a nobrainer if the quality is the same... we'll see!
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

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

Re: Analogue audio redux

Fri Aug 28, 2020 10:58 am

GeorgS wrote:
Thu Aug 27, 2020 11:56 pm
I never said I ever used audio_pwm_mode=1 It was your suggestion I replied to.
audio_pwm_mode=2 works fine in all use cases with the older firmware 3ca4cf4a663c5351eaec08b29d50d6e8324981b4
Ah you're using an intermediate version of the new driver, which means one of a few updates could have caused a regression.

Which is the first failing firmware revision? Can you run rpi-update in turn on progressively newer firmware - take the list of commits from https://github.com/Hexxeh/rpi-firmware/commits/master starting from round about

https://github.com/Hexxeh/rpi-firmware/ ... 2f7a14fb3e

and force installation of a particular variant with rpi-update <hash>

(note: these are not the same hashes as reported by vcgencmd)
Rockets are loud.
https://astro-pi.org

GeorgS
Posts: 19
Joined: Fri Aug 07, 2020 8:15 pm

Re: Analogue audio redux

Fri Aug 28, 2020 9:27 pm

@jdb

Got the firmware you proposed:
rpi-update 0065c82b95aed1150c19ff7a6244832f7a14fb3e
...
*** Updating firmware
*** Updating kernel modules
*** depmod 4.9.21+
*** depmod 4.9.21-v7+
...
*** If no errors appeared, your firmware was successfully updated to 0065c82b95aed1150c19ff7a6244832f7a14fb3e
Rebooted and checked the version with vcgencmd:
root@raspberrypi:~# /opt/vc/bin/vcgencmd version
Apr 4 2017 18:41:29
Copyright (c) 2012 Broadcom
version 3ca4cf4a663c5351eaec08b29d50d6e8324981b4 (clean) (release)
It works fine with audio_pwm_mode=2 in all use cases.

Just checked and learned it's the same version (vcgencmd output) as what I've been using before, the firmware bundled in the 2017-07-05 Raspbian release - kernel 4.4.50.
/opt/vc/bin/vcgencmd version
Apr 5 2017 11:49:52
Copyright (c) 2012 Broadcom
version 3ca4cf4a663c5351eaec08b29d50d6e8324981b4 (clean) (release)

Confirmed this by comparing the md5sum hashes on the files. The hashes for bootcode.bin / fixup_cd.dat / fixup.dat / fixup_db.dat / fixup_x.dat are matching, just the start* files are different.

Correct me if wrong, but I believe the firmware related files I should care about for the Pi2B are:
bootcode.bin
fixup_cd.dat
fixup.dat
fixup_db.dat
fixup_x.dat
start_cd.elf
start_db.elf
start.elf
start_x.elf
And I can download them manually for future tests - other firmware hashes, easier and cleaner - no need to download 57MB with rpi-update and upgrade the kernel and vc libs too, by simply:
wget https://github.com/Hexxeh/rpi-firmware/ ... otcode.bin
wget https://github.com/Hexxeh/rpi-firmware/ ... /fixup.dat
wget https://github.com/Hexxeh/rpi-firmware/ ... xup_cd.dat
wget https://github.com/Hexxeh/rpi-firmware/ ... xup_db.dat
wget https://github.com/Hexxeh/rpi-firmware/ ... ixup_x.dat
wget https://github.com/Hexxeh/rpi-firmware/ ... /start.elf
wget https://github.com/Hexxeh/rpi-firmware/ ... art_cd.elf
wget https://github.com/Hexxeh/rpi-firmware/ ... art_db.elf
wget https://github.com/Hexxeh/rpi-firmware/ ... tart_x.elf

To provide some orientation, the last firmware that was working fine with audio_pwm_mode=2 was the one bundled in the 2017-07-05 Raspbian release - kernel 4.4.50.
https://downloads.raspberrypi.org/raspb ... _notes.txt
Everything I tried afterwards, manually extracting the firmware files from the released Raspbian/Raspberry Pi OS images, already contained the new "audio redux" algorithm and the sound was crackling with audio_pwm_mode=2
The release_notes.txt missed providing details about the firmware (hash) and kernels until 2018-03-13, not really helpful.
Please let me know what other firmware release (hash) you like me to test. Note that I'm using the official Raspberry provided kernel 4.14.79 on all my Raspberry boards at the moment.

GeorgS
Posts: 19
Joined: Fri Aug 07, 2020 8:15 pm

Re: Analogue audio redux

Sat Aug 29, 2020 12:03 am

Spent some time browsing the firmware commits on github, trying to make sure that the new PWM algorithm is the one causing the audio to crackle.
From here:
https://github.com/Hexxeh/rpi-firmware/ ... nch=master

I was able to identify the last working firmware commit with audio_pwm_mode=2: 63899229b09d22184ee4d2ab9662e9b32b9ec875
https://github.com/Hexxeh/rpi-firmware/ ... b32b9ec875
/opt/vc/bin/vcgencmd version
Oct 10 2017 14:23:57
Copyright (c) 2012 Broadcom
version 7d8a5ead990e3dd90d322921499935e3eebd3b53 (clean) (release)

And the first commit that breaks my audio with audio_pwm_mode=2: d7a6e668ca0fb79518fd1063d27e741fd300c60d
https://github.com/Hexxeh/rpi-firmware/ ... 1fd300c60d
/opt/vc/bin/vcgencmd version
Oct 11 2017 23:23:59
Copyright (c) 2012 Broadcom
version e5ad4a8e9f183413eb4f7fc4a7687886c715f739 (clean) (release)

According to its description, the commit d7a6e668ca0fb79518fd1063d27e741fd300c60d is where the new PWM algorithm was introduced.

Coming back to my original request: could someone at Raspberry be so kind, build and make available for d/l an actual version of the Raspberry firmware with the commit d7a6e668ca0fb79518fd1063d27e741fd300c60d reverted?
I'd like to keep and use for multimedia some of the Raspberry boards I own, load the latest kernel 5.4.x on them.

Thank you!

bullen
Posts: 409
Joined: Sun Apr 28, 2013 2:52 pm

Re: Analogue audio redux

Mon Aug 31, 2020 1:43 pm

Just to confirm, these cheapo USB things work now... no static! Mic too! Phew!

Edit: and btw they are exactly the same...
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

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

Re: Analogue audio redux

Tue Sep 01, 2020 9:46 am

GeorgS wrote:
Sat Aug 29, 2020 12:03 am
Spent some time browsing the firmware commits on github, trying to make sure that the new PWM algorithm is the one causing the audio to crackle.
From here:
https://github.com/Hexxeh/rpi-firmware/ ... nch=master

I was able to identify the last working firmware commit with audio_pwm_mode=2: 63899229b09d22184ee4d2ab9662e9b32b9ec875
https://github.com/Hexxeh/rpi-firmware/ ... b32b9ec875
/opt/vc/bin/vcgencmd version
Oct 10 2017 14:23:57
Copyright (c) 2012 Broadcom
version 7d8a5ead990e3dd90d322921499935e3eebd3b53 (clean) (release)

And the first commit that breaks my audio with audio_pwm_mode=2: d7a6e668ca0fb79518fd1063d27e741fd300c60d
https://github.com/Hexxeh/rpi-firmware/ ... 1fd300c60d
/opt/vc/bin/vcgencmd version
Oct 11 2017 23:23:59
Copyright (c) 2012 Broadcom
version e5ad4a8e9f183413eb4f7fc4a7687886c715f739 (clean) (release)

According to its description, the commit d7a6e668ca0fb79518fd1063d27e741fd300c60d is where the new PWM algorithm was introduced.

Coming back to my original request: could someone at Raspberry be so kind, build and make available for d/l an actual version of the Raspberry firmware with the commit d7a6e668ca0fb79518fd1063d27e741fd300c60d reverted?
I'd like to keep and use for multimedia some of the Raspberry boards I own, load the latest kernel 5.4.x on them.

Thank you!
The change won't be reverted, as there are multiple other use-cases that break if the driver doesn't support multiple writers.

- Please upload a sample of garbled audio somewhere downloadable (preferably captured by a sound card line-in port, not a microphone)
- Do you have composite video enabled on any of your devices?
Rockets are loud.
https://astro-pi.org

Return to “Advanced users”