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: 186
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: 2215
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: 186
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: 315
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: 2587
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: 315
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: 2587
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: 315
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: 5451
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: 315
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: 2587
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: 315
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: 21633
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.....
Retired disgracefully.....
......to a more gentile life !

Return to “Advanced users”