Rockbox Technical Forums

Support and General Use => Audio Playback, Database and Playlists => Topic started by: asymsucon on January 02, 2017, 03:08:42 AM

Title: Pitch error in 48kHz mode
Post by: asymsucon on January 02, 2017, 03:08:42 AM
When my Clip+ runs in 48kHz mode, 1kHz sine is outputted as 1.007kHz, in AB test very noticeable difference. In 44.1kHz, it's almost dead center on 1.000kHz.
This is a bit unfortunate as 99.5% of my music collection is in 48kHz sampling-rate and running Clip+ in 44.1kHz could impact quality and battery life.

Issue spotted on firmware ac0fc74
Title: Re: Pitch error in 48kHz mode
Post by: Mihail Zenkov on January 02, 2017, 06:07:29 AM
I look at code: to get more precision 48 kHz we should switch main frequency (PPL) when we switch from 44.1 to 48 and back. It bit tricky but possible.

Just curious: why all your music in 48 kHz?
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on January 02, 2017, 06:15:29 AM
I'm using Opus as my primary lossy compression codec and Opus runs only at 48kHz.
One of the reasons why I opted for purchasing Clip+ was Opus support (no other non-Rockboxed player claims support) so that I could fit in my entire collection at 140kbps onto 64GB microSDXC without any subjectively perceivable audio degradation ;)
Title: Re: Pitch error in 48kHz mode
Post by: Mihail Zenkov on January 02, 2017, 06:28:28 AM
Ok, I got your point.

But you got resampling from 44.1 to 48 - probably with minor sound degradation but ...
With 48 kHz your runtime from battery will be less for ~8%.
Opus by itself consume to much cpu and your runtime from battery will be significantly less.
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on January 02, 2017, 06:36:46 AM
Yes, opus resamples everything to 48kHz during encoding, so some resampling degradation can be expected, however most if not all of it would be inaudible or below 16bit noise floor.

Decoding of 140kbps Opus should run at about 550% realtime, which is not that far from 680% for Lame-320 or 660% for AAC-LC based on tests on 18fecd9 (https://www.rockbox.org/wiki/CodecPerformanceComparison#Sansa_Clip_43_40ARM9E_41
So in the end the CPU power required, while higher shouldn't contribute too much to the battery runtime.
Title: Re: Pitch error in 48kHz mode
Post by: Mihail Zenkov on January 02, 2017, 06:48:33 AM
~40 mHz for Opus and ~27 mHz for mp3 - 50% difference. When we play mp3 we can decode it at very low cpu frequency but for decoding opus we should boost cpu frequency time to time.
It not mean that your runtime will be less for 50% with opus but 20-30% can be expected.
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on January 02, 2017, 07:01:33 AM
It still managed to last a week of medium usage on a single charge with 20% battery left.  :)
"Max. delay" encoding parameter seems to also affect decoding speed. As there's no sync or latency to worry about, perhaps increasing it a bit (to 50-100ms) might help with the CPU load.
Title: Re: Pitch error in 48kHz mode
Post by: saratoga on January 03, 2017, 11:28:55 AM
Opus could use further optimization, it needs an unusual FFT length so it can't share the ones written for the other codecs.
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on January 11, 2017, 07:43:28 AM
Until is this resolved, is it better to use 44.1kHz even for Opus, or to adjust pitch by -0.7%?
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on February 01, 2017, 03:47:19 PM
With 48 kHz your runtime from battery will be less for ~8%.
If you don't mind me asking, what causes the consumption to rise by 8% ?
Assuming we're comparing two FLACs, one at 44.1k and one at 48k.
Would it be also possible to implement automatic switching based on source file sampling rate?
Title: Re: Pitch error in 48kHz mode
Post by: Mihail Zenkov on February 02, 2017, 05:59:17 AM
If you don't mind me asking, what causes the consumption to rise by 8% ?
Assuming we're comparing two FLACs, one at 44.1k and one at 48k.

As audio stream (compressed and decompressed) will be bigger for 8%.
We have quite big overhead even on playing wav: http://forums.rockbox.org/index.php/topic,51184.0.html
DAC also consume more power on bigger frequency.

Would it be also possible to implement automatic switching based on source file sampling rate?
http://forums.rockbox.org/index.php/topic,51300.0.html
Title: Re: Pitch error in 48kHz mode
Post by: saratoga on February 02, 2017, 01:17:29 PM
If you don't mind me asking, what causes the consumption to rise by 8% ?
Assuming we're comparing two FLACs, one at 44.1k and one at 48k.

As audio stream (compressed and decompressed) will be bigger for 8%.
We have quite big overhead even on playing wav: http://forums.rockbox.org/index.php/topic,51184.0.html
DAC also consume more power on bigger frequency.

I don't think the actual hit to battery life will be 8% though, since some power will be consumed no matter what (nand, Dram, etc). 

It would be easy to battery bench if anyone is interested in trying.  Just get a 44.1k album and a 48k album and run the battery bench plugin twice. 
Title: Re: Pitch error in 48kHz mode
Post by: Mihail Zenkov on February 02, 2017, 02:02:04 PM
I don't think the actual hit to battery life will be 8% though, since some power will be consumed no matter what (nand, Dram, etc). 

You right. I check on clip zip with CVDD2 scaling (without sd card) on flac:
44.1 consume 8.0 mA, 48.0 - 8.5 mA. But better do battery bench as you say.
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on February 02, 2017, 02:53:24 PM
It would be easy to battery bench if anyone is interested in trying.  Just get a 44.1k album and a 48k album and run the battery bench plugin twice.
I'd disagree, it seems wasteful to spend two more li-ion cycles on a test, for which ammeter/miliwattmeter should be enough.
Thanks for the figures Mihail. I asked that because I have never seen any measurable difference in consumption on any DAP so far when comparing 44.1k and 48k.
I reckon majority of content is in 44.1k so it's clear why you're pushing that way (MP3/Flac @ 44.1k), but 48k isn't uncommon or rare (and IMO better target for downsampling). Even more so with Opus in the way  :)
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on May 19, 2017, 12:52:15 AM
Any hope for a fix now that 3.14 has been released?
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on September 28, 2017, 08:50:52 AM
Any hope for a fix at this point?
Title: Re: Pitch error in 48kHz mode
Post by: jhMikeS on October 07, 2017, 03:04:04 PM
Any hope for a fix now that 3.14 has been released?

Mine would be to remove any sample rates that are inaccurate enough to have an audible difference from a known good reference, even under direct comparison.
Title: Re: Pitch error in 48kHz mode
Post by: asymsucon on January 03, 2018, 03:50:39 AM
Here's what I measured with test_sampr on 3.14:
8k - 974Hz
11.025k - 1000Hz
12k - 997Hz
16k - 997Hz
22.050k - 1000Hz
24k - 991Hz
32k - 997Hz
44.1k - 1000Hz
48k - 1007Hz
64k - 1018Hz
88.2k - 1000Hz
96k - 976Hz