Hydrogenaudio Forums

Hosted Forums => foobar2000 => 3rd Party Plugins - (fb2k) => Topic started by: Case on 2018-01-15 12:54:20

Title: Secret Rabbit Code resampler
Post by: Case on 2018-01-15 12:54:20
I was asked to make Secret Rabbit Code (http://www.mega-nerd.com/SRC/) resampler component for foobar2000 now that its license isn't restrictive GPL anymore.

Its quality has also been improved since the earlier days.

First version of the component is ready and can be downloaded from http://www.foobar2000.org/components/view/foo_dsp_src_resampler (http://www.foobar2000.org/components/view/foo_dsp_src_resampler).
Title: Re: Secret Rabbit Code resampler
Post by: lvqcl on 2018-01-15 17:38:45
I wonder why this component is so slow even in fastest sinc mode.
Maybe you changed config.h so that HAVE_LRINT and HAVE_LRINTF are defined? These functions are awfully slow in MSVC, it's better to use inline asm.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-01-15 19:07:34
Thanks for looking after me. Indeed I had disabled those when debugging a problem and forgot to enable them. Faster versions uploaded.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-01-17 19:37:43
Rollin's post (https://hydrogenaud.io/index.php/topic,114960.msg947760.html#msg947760) about resampling ruining gaplessness has been bothering me ever since reading it. I implemented the extrapolation used in Vorbis and Opus to SRC resampler v1.0.2 (http://www.foobar2000.org/components/view/foo_dsp_src_resampler) and it appears to perform quite well. At least those sample files from the linked post can be resampled without glitches.

Edit: added two comparison screenshots of the transition position. One is resampled with SoX using hiqhest quality and the other one is SRC with extrapolation.
Title: Re: Secret Rabbit Code resampler
Post by: Rollin on 2018-01-27 20:27:49
Quote
1.0.3 (2018-01-21): Added resampler service entry. Priority of the service can be configured in advanced preferences
Some things about resampler's service priority are unclear for me.
In what situations priority of resampler's service is used? Replaygain scanning with upsampling, replaygain scanning with downsampling (BTW: to what samplerate is downsamling performed on Replaygain scanning when option "Use downsampling" is enabled?), playing files with high samplerates to directsound or something else?
Also, i did some testing that lead me to next conclusions (please correct me if i'm wrong):
1)If there are no 3rd party resamplers, then built-in dBpoweramp/SSRC is used (at least when playing files with high samplerates to directsound)
2)Resampler with priority 100 will be used over built-in resampler
But i still have some questions:
1)What priority should resampler have not to be used over built-in resampler or is this not possible?
2)If there are 2 (or more) 3rd party resamplers with the same priority, which one will be used?
Title: Re: Secret Rabbit Code resampler
Post by: Rollin on 2018-01-27 20:31:06
Please delete. I quote myself instead of editing.
Title: Re: Secret Rabbit Code resampler
Post by: Rollin on 2018-01-27 21:48:23
If there are no 3rd party resamplers, then built-in dBpoweramp/SSRC is used (at least when playing files with high samplerates to directsound)
Correction: PPHS (not in ultra mode) is used
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-01-28 00:04:52
My understanding is that the core sorts resamplers by priority but the order between services with the same priority is random as the component loading order is randomized on each launch.

Priority affects all the situations where a component requests resampling. Highest priority is preferred and lower priority resampler services only get used if the requested ratio isn't supported by the earlier contenders.

I'm not sure about priorities of all the resamplers bundled in the standard DSP component but I know SSRC at least has the highest priority. I have suggested Peter to make internal resampler priorities configurable too or extend the priority concept to allow taking resampler qualities and speeds into account. For example SoX offers fastest high quality resampling speeds and it would make sense to prefer it in those conversions. ReplayGain's peak scanner requests lowest quality and SRC's linear mode would be sufficient. It works several times faster than SoX's lowest quality mode so it might make sense to be in use there.

(BTW: to what samplerate is downsamling performed on Replaygain scanning when option "Use downsampling" is enabled?)
44.1 kHz. The most common sample rate without too much inaudible content present.

Edit: I thought about defaulting SRC component's priority a little lower than the max, but it's still faster than SSRC component and quality is sufficiently good. Also the lower quality modes are faster than anything. But if someone wishes to have Secret Rabbit installed but not utilize it in resampler services, the priority can be lowered and other resamplers will be used instead.
Title: Re: Secret Rabbit Code resampler
Post by: lvqcl on 2018-01-28 09:31:56
I'm not sure about priorities of all the resamplers bundled in the standard DSP component but I know SSRC at least has the highest priority.
But it means that it's not possible to always prefer external resamplers to internal. If SRC or SoX priority is 99 or lower then internal resampler is used, and if it's equal to 100 then the winner is randomly chosen at each fb2k start.
(and if Rollin is right then PPHS has max. priority, not SSRC. Or they have the same priority, but PPHS is always preferred).

ReplayGain's peak scanner requests lowest quality and SRC's linear mode would be sufficient.
But how?? Peak scanner oversamples to detect intersample overflows, and these don't exist with linear or ZOH resampling: values of new samples can't be higher than values of existing samples.

But if someone wishes to have Secret Rabbit installed but not utilize it in resampler services, the priority can be lowered
By the way: the name of the setting is "Resampler service priority (0-100)" but its minimum possible value is actually 1, not 0 (not that it matters much...)
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-01-28 10:17:43
I'm not sure about priorities of all the resamplers bundled in the standard DSP component but I know SSRC at least has the highest priority.
But it means that it's not possible to always prefer external resamplers to internal. If SRC or SoX priority is 99 or lower then internal resampler is used, and if it's equal to 100 then the winner is randomly chosen at each fb2k start.
Indeed. Needs clarification/fixing.

ReplayGain's peak scanner requests lowest quality and SRC's linear mode would be sufficient.
But how?? Peak scanner oversamples to detect intersample overflows, and these don't exist with linear or ZOH resampling: values of new samples can't be higher than values of existing samples.
Good point. I hadn't thought it through and I think neither had Peter. I requested highest quality resampling in the old True Peak scanner I made before core implemented the feature. I have lost the ability to think since then apparently.
Not sure whether to convince Peter to request higher quality resampling in the peak scanner or disable the ability to use the non-sinc modes in my component. At least the fastest sinc mode in Rabbit is still faster than SSRC.

By the way: the name of the setting is "Resampler service priority (0-100)" but its minimum possible value is actually 1, not 0 (not that it matters much...)
Oh damn. I mixed up config order priority and the minimum value on the parameters. Thanks.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-02-02 14:18:00
The just released foobar2000 v1.4 beta 4 (http://www.foobar2000.org/download) has a solution for the resampler priority mess. ReplayGain scanner now has special configuration to decide which resamplers and settings to use. And under Tools section of Advanced Preferences there's configuration for resampler service order.
Title: Re: Secret Rabbit Code resampler
Post by: eagleray on 2018-03-14 20:06:57
I suppose there is no way to just resample certain frequencies or exclude certain frequencies.  Any chance of a mod version?

FWIW,  on a low powered N3700 the highest quality setting caused audio to skip when resampling to 352800.  I guess it's too much for my puny Pentium.  Medium quality worked, although with much higher CPU usage than SOX.  However, still not enough load to cause the fan to ramp up to audible levels.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-03-15 14:19:25
I just released a new version that allows excluding frequencies. The edit field in the configuration accepts both individual frequencies and ranges. Values are separated with commas or semicolons. For example to exclude everything below and including 44.1 kHz and 48 kHz you could type: "0-44100, 48000".
Title: Re: Secret Rabbit Code resampler
Post by: eagleray on 2018-03-15 20:02:35
I just released a new version that allows excluding frequencies. The edit field in the configuration accepts both individual frequencies and ranges. Values are separated with commas or semicolons. For example to exclude everything below and including 44.1 kHz and 48 kHz you could type: "0-44100, 48000".

Yay, thanks!
Title: Re: Secret Rabbit Code resampler
Post by: lvqcl on 2018-03-16 11:34:34
I took 10-second audio (44100 Hz, 441000 samples) and converted to 96 kHz (Best Sinc). The resulting file has duration 9.98 seconds (958482 samples instead of 960000).
I have only 1.0.4 and 1.0.5 versions on my computer, and both versions are affected.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-03-16 14:30:00
Nice find, thanks. Stupid bug in the extrapolation clipping code and I had only tested it with downsampling. Fixed versions uploaded.
Title: Re: Secret Rabbit Code resampler
Post by: TuNk77 on 2018-03-18 13:52:00
I get an error message when I seek. The message is displayed when I seek a minute ahead, when it's less than a minute left on the track.
"Unrecoverable playback error: SRC_DATA->data_out or SRC_DATA->data_in is NULL."

I'm using foobar2000 v1.3.17 on Windows 7 x64.

Please ignore this message, it was foo_dsp_nogaps causing the problem.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-03-19 18:57:10
My foo_dsp_nogaps (http://www.saunalahti.fi/~cse/foobar2000/?changes=foo_dsp_nogaps) or Acropolis' modification? If my component has a bug I'd very much like to fix it.
Title: Re: Secret Rabbit Code resampler
Post by: TuNk77 on 2018-03-21 15:26:56
My foo_dsp_nogaps (http://www.saunalahti.fi/~cse/foobar2000/?changes=foo_dsp_nogaps) or Acropolis' modification? If my component has a bug I'd very much like to fix it.

Hello Case. I am using you version of foo_dsp_nogaps (v0.4). I have not tried Acropolis' version.
The error message also when I seek on the end of the track.
Let's say ther's 8 seconds left and I seek 10 seconds ahead or 1 minute ahead (scrolling with the mouse courser over the seek bar).
The error massage appears as posted above.

Code: [Select]
Core (2017-11-24 08:00:06 UTC)
    foobar2000 core 1.3.17
foo_ac3.dll (2018-01-26 15:55:06 UTC)
    AC3 decoder 0.9.10
foo_albumlist.dll (2017-11-24 07:58:40 UTC)
    Album List 4.5
foo_audioscrobbler.dll (2016-08-23 18:35:02 UTC)
    Audioscrobbler 1.4.7
foo_cdda.dll (2017-11-24 07:58:36 UTC)
    CD Audio Decoder 3.0
foo_converter.dll (2017-11-24 07:58:34 UTC)
    Converter 1.5
foo_cuefilter.dll (2016-08-28 20:29:01 UTC)
    CUE Playlist Filter 0.1.7.0
foo_dsp_centercut.dll (2017-01-01 21:04:57 UTC)
    Center Cut 1.0.1u
foo_dsp_delta.dll (2018-02-05 16:25:25 UTC)
    Noise Sharpening DSP 1.0.0
foo_dsp_effect.dll (2017-11-27 00:40:52 UTC)
    Effect DSP 0.22
foo_dsp_eq.dll (2017-11-24 07:58:56 UTC)
    Equalizer 1.2
foo_dsp_nogaps.dll (2018-01-09 21:24:40 UTC)
    Gap Killer DSP 0.4
foo_dsp_skip_silence.dll (2018-01-09 21:24:41 UTC)
    Skip Silence 1.0.2
foo_dsp_src_resampler.dll (2018-03-18 13:52:16 UTC)
    SRC Resampler 1.0.6
foo_dsp_std.dll (2017-11-24 07:58:42 UTC)
    Standard DSP Array 1.3.1
foo_fileops.dll (2017-11-24 07:57:40 UTC)
    File Operations 2.2.2
foo_freedb2.dll (2017-11-24 07:57:34 UTC)
    Online Tagger 0.7
foo_input_std.dll (2017-11-24 08:23:10 UTC)
    FFmpeg Decoders 3.2.4
    Standard Input Array 1.0
foo_keep_queue.dll (2016-08-23 18:35:17 UTC)
    Keep Queue 0.3.5
foo_midi.dll (2018-02-10 19:37:42 UTC)
    MIDI Player 2.0.22
foo_openmpt54.dll (2018-02-05 16:25:25 UTC)
    OpenMPT component (kode54 fork) 0.3.6
foo_out_wasapi.dll (2017-08-01 09:38:09 UTC)
    WASAPI output support 3.3
foo_playcount.dll (2016-08-23 18:35:22 UTC)
    Playback Statistics 3.0.2
foo_r128norm.dll (2017-02-05 10:43:31 UTC)
    EBU R128 Normalizer 1.12
foo_rgscan.dll (2017-11-24 08:03:34 UTC)
    ReplayGain Scanner 2.2.2
foo_skip.dll (2016-08-23 18:35:33 UTC)
    Skip Track 1.9.8
foo_ui_std.dll (2017-11-24 07:58:50 UTC)
    Default User Interface 0.9.5
foo_verifier.dll (2017-12-07 10:13:39 UTC)
    File Integrity Verifier 1.2.1
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-03-21 17:25:14
I don't see anything wrong in the foo_dsp_nogaps source. It never sends empty audio chunks out. Also I have tried my best to replicate the error but I fail.
But if it's only Rabbit resampler erroring out I can add more checks against invalid audio chunks. Can you see if everything works properly with the attached version?

Edit: attachment removed. Changes included in the new release.
Title: Re: Secret Rabbit Code resampler
Post by: TuNk77 on 2018-03-21 18:46:17
I don't see anything wrong in the foo_dsp_nogaps source. It never sends empty audio chunks out. Also I have tried my best to replicate the error but I fail.
But if it's only Rabbit resampler erroring out I can add more checks against invalid audio chunks. Can you see if everything works properly with the attached version?

That fixed it, thank you very much :)
Title: Re: Secret Rabbit Code resampler
Post by: archy121 on 2018-03-23 12:09:45
After some testing I have come to prefer SRC over the SOX and very much appreciatre the work by @Case.
Overall I'm finding the sound more clearer than SRX.

Is there a way to specify only 44100Hz to be sampled up ?

I would like my Hi Res 24/96-192 tracks to remain untouched.

EDIT-Upgraded to version 1.07 and now see an Exclude option.

Will the Excluded rates be left untouched and what should be used to seperate more than one value ?
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-03-23 14:57:07
Will the Excluded rates be left untouched and what should be used to seperate more than one value ?
Excluded rates will be left completely untouched. Same as when the input sample rate matches the target sample rate. You separate multiple exclusions with comma (,) or semicolon (;), whichever you prefer. Note that it supports ranges too so to exlude rates between 96 kHz and 192 kHz just enter 96000-192000.
Title: Re: Secret Rabbit Code resampler
Post by: sveakul on 2018-03-24 02:55:13
Ivqcl, I am currently using your excellent Sox resampler mod2, and have noted your comments here about Case's improved SRC.  Am wondering as to how you would compare the two as to performance..  We've got two geniuses at work here who respect each other, so I'm very curious as to both of their impressions!
Title: Re: Secret Rabbit Code resampler
Post by: lvqcl on 2018-03-24 09:50:07
Well, first, the algorithms of SoX resampler and Secret Rabbit Code were written by Rob Sykes and Erik de Castro Lopo, so kudos to them.

Second, not sure what you mean by performance. Speed-wise, SoX is faster than SRC (mostly because of their algorithms). Quality-wise, they are mostly the same. All high quality resamplers are the same: transparent.

The feature with signal extrapolation is neat though.
Title: Re: Secret Rabbit Code resampler
Post by: sveakul on 2018-03-24 23:12:30
Thanks Ivqcl!  Seeing as I only resample if the original rate is not compatible with my device (which means a few odd radio streams at 22050;24000;32000;88200) that means I'll stick with SoX.  Yes that is cool though how Case added a solution to SRC for gapless playback issues.
Title: Re: Secret Rabbit Code resampler
Post by: 350519263 on 2018-04-04 16:11:15
Love this resampler, SMOOTHING the song while increasing clarity, other resamplers lack this property. Just want to give some feedback.
I use Cheat Engine to minimize the buffer length to 0ms. When I use other resamplers like SoX or Resampler-V there is no issue, but when I use SRC 1.0.8, some glitches happen just after switching songs. Guessing the plugin is not fast enough, I hope the resampler may be faster. BTW the "exclude rates" may be slow as well, by manipulating the order of DSPs I can hear the differences.
Title: Re: Secret Rabbit Code resampler
Post by: Rollin on 2018-04-04 19:14:01
Love this resampler, SMOOTHING the song while increasing clarity, other resamplers lack this property.
Are you using ZOH or linear interpolation mode?

I use Cheat Engine to minimize the buffer length to 0ms.
:o  Why?
Title: Re: Secret Rabbit Code resampler
Post by: lvqcl on 2018-04-04 19:52:13
from Kohlrabi (https://hydrogenaud.io/index.php?action=profile;u=20561)'s signature: "It's only audiophile if it's inconvenient."
Title: Re: Secret Rabbit Code resampler
Post by: magicgoose on 2018-04-04 20:47:17
Love this resampler, SMOOTHING the song while increasing clarity, other resamplers lack this property.
Do you mean you actually hear the difference?
Title: Re: Secret Rabbit Code resampler
Post by: kode54 on 2018-04-06 03:02:56
I use Cheat Engine to minimize the buffer length to 0ms.
:o  Why?
It doesn't matter anyway, as with zero buffer, it wouldn't play at all. So, it programmatically enforces its own minimum buffer size, regardless of what the setting says. Anyone with half a brain knows that the magical "zero" latency is physically impossible. Or maybe someone thinks that throwing around the word "quantum" would magically make it possible to have literally instant output without any buffering or transit in between.
Title: Re: Secret Rabbit Code resampler
Post by: Rollin on 2018-04-07 13:35:35
extrapolation used in Vorbis and Opus
Is this crosslappping, which is described here - https://xiph.org/vorbis/doc/vorbisfile/crosslap.html (https://xiph.org/vorbis/doc/vorbisfile/crosslap.html)?
And, @Case , is there any reason why you didn't publish foo_dsp_amp and foo_hardclip on you site (http://www.saunalahti.fi/~cse/foobar2000/)? Also, something about components themselves.
In foo_dsp_amp it is impossible to set some values, for example +0.7 dB and +1.4 dB (or maybe this is just GUI which displays wrong values). foo_hardclip doesn't work without SSE2 (verified on real AthlonXP). Is this by intention?
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-04-07 18:43:46
Is this crosslappping, which is described here - https://xiph.org/vorbis/doc/vorbisfile/crosslap.html (https://xiph.org/vorbis/doc/vorbisfile/crosslap.html)?
Overlapping would require information from two tracks to get the transition smoothed. When the DSP is used in multi-threaded converter there's only information from a single track available. The component uses extrapolation to estimate how the signal was before the track start and how it would continue at the track end. The extrapolated samples are included in the signal fed to the resampler and cut away to retain proper length.

is there any reason why you didn't publish foo_dsp_amp and foo_hardclip on you site (http://www.saunalahti.fi/~cse/foobar2000/)?
Just laziness. Putting them there requires for example writing some description texts.

In foo_dsp_amp it is impossible to set some values, for example +0.7 dB and +1.4 dB (or maybe this is just GUI which displays wrong values). foo_hardclip doesn't work without SSE2 (verified on real AthlonXP). Is this by intention?
The first issue was a rounding problem. The second was carelessness. I should know to check settings when upgrading project files to new Visual Studio but apparently made a mistake that year.

Fixed components are up on my site with dynamic 1.4 versions and larger legacy 1.1 versions.
Title: Re: Secret Rabbit Code resampler
Post by: fireattack on 2018-05-24 08:26:47
I assume if the input has the same sample rate as the target (44100hz for example), it (this DSP) won't be used at all, right?

I'm trying to convert a mix of hi-res and 44.1k files together, hence the question.

Thanks!
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-05-24 10:04:20
That's correct. When the source sample rate matches the target the resampler is fully bypassed.
Title: Re: Secret Rabbit Code resampler
Post by: Sandrine on 2018-11-21 18:35:34
The just released foobar2000 v1.4 beta 4 (http://www.foobar2000.org/download) has a solution for the resampler priority mess,  under Tools section of Advanced Preferences there's configuration for resampler service order.

I need some pointers, please: In the priority dialogue, do I enter the descriptive name like "SRC resampler" or "foo_dsp_src_resampler"?
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2018-11-21 18:47:56
You use the name of the DSP entry as listed on the DSP configuration screen. So for SRC resampler that would be "Resampler (SRC)" without the quotes.
Title: Re: Secret Rabbit Code resampler
Post by: Oswyn on 2019-03-08 07:01:32
Hello Case.
Is it possible to let the user control LPF parameters such as cutoff frequency and slope when resampling?
Thanks you.
Title: Re: Secret Rabbit Code resampler
Post by: Case on 2019-03-08 18:40:00
Not possible with the resampling library.
SimplePortal 1.0.0 RC1 © 2008-2019