• Welcome to ASR. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

The Perfect CD Sample Rate Converter (Shannon Interpolation)

Maybe I should give up because I don't understand the math or coding. But how is it possible to get a single solution for values between the original samples without implementing a filter in some way.
Okay, I had AI create an explanation in plain English to make it easier to understand:

The simplest way to explain it is probably this:


Imagine you have the samples of a 44.1 kHz recording and want to double the sample rate. You keep all the original samples exactly where they are, and you need to work out one new sample between every pair.


A normal resampler does this by inserting empty samples and then running the result through a low-pass reconstruction filter. That filter calculates sensible values for those empty positions and removes the unwanted images created by the insertion.


Julian’s method approaches the same problem from the other direction. It says:


If the original signal contained nothing above 22.05 kHz, there is exactly one band-limited waveform that can pass through all these samples. What value does that waveform have halfway between each pair?


Mathematics lets you calculate that value directly. Each original sample contributes a little bit to every new sample, with the contribution determined by its distance from it. Add all those contributions together and you get the new sample value.


So it isn’t:


insert samples → filter them


but rather:


calculate directly what the missing samples must be for a perfectly band-limited reconstruction.


That’s why saying “there is no filter” can be slightly misleading. There is no separate filtering operation, but the mathematics used to calculate the missing samples is the same mathematics as an ideal brick-wall reconstruction filter.


A decent everyday analogy would be reconstructing a curve from known points. He’s not drawing some arbitrary smooth line between adjacent points. He’s saying “only curves containing frequencies below this limit are allowed”. With that constraint and the complete set of samples, the allowed curve is determined, so he simply asks that curve for its value at the new positions.


And that’s also the important limitation: it isn’t recovering information that was lost when the original recording was made. It’s reconstructing the band-limited waveform represented by the existing samples. If the original ADC/filter/44.1-kHz conversion already altered the signal, this process can’t know what was there beforehand.
 
Okay, I had AI create an explanation in plain English to make it easier to understand:
Well I get that. But if you have a 44.1 file of all zeros and upsample to 88.2 without band limiting, is the result silence or a sine wave?
 
Well I get that. But if you have a 44.1 file of all zeros and upsample to 88.2 without band limiting, is the result silence or a sine wave?
Obviously, it will still be silent. Why would it be anything else?
 
Obviously, it will still be silent. Why would it be anything else?
Because mathematically a 22.05KHz sine wave is a valid result without band limiting. I assume there is some mechanism in the code to band limit in a way that is equivalent to a brick wall, so I am just trying to get some idea of how this is done.
 
Obviously, it will still be silent. Why would it be anything else?
To be pedantic, the AI summary contains "If the original signal contained nothing above 22.05 kHz," and it should rather be "nothing at or above 22.05 kHz".
 
No! It is not. Read the sampling theorem again, and then check the comment above from @danadam :)
Right, but how is this put into code in a different way than how PGGB does it. If it is so obvious why does PGGB do it in what would seem to be a roundabout and overcomplicated manner.

If the band limit rule is put into code, that is a filter, right? Maybe there is a fairly easy way to throw out solutions that violate the rule. That is kind of what I am trying to get at.
 
Last edited:
Right, but how is this put into code in a different way than how PGGB does it.
It's just a totally different algorithm..
If it is so obvious why does PGGB do it in what would seem to be a roundabout and overcomplicated manner.
That is the USP, using silly math precision sells..
If the band limit rule is put into code, that is a filter, right? Maybe there is a fairly easy way to throw out solutions that violate the rule. That is kind of what I am trying to get at.
Again, two totally different algorithms; one needs a dedicated filter, the other has none explicitly. The algorithm itself makes sure it does not violate the sampling theorem because it's kind of a derivation of the proof itself.
 
Again, two totally different algorithms; one needs a dedicated filter, the other has none explicitly. The algorithm itself makes sure it does not violate the sampling theorem because it's kind of a derivation of the proof itself.
Thanks. That is pretty much the kind of answer I was looking for.
 
Thanks. That is pretty much the kind of answer I was looking for.
Exact64 is less an attempt to design a better resampling filter and more an attempt to turn the Shannon reconstruction formula itself into a correctly-rounded binary64 computation.


P96 and P128 are simply the internal precision used to make sure that final rounding is correct. They are not output bit depths and they are not different quality modes — the output is always 64-bit floating point.


Think of it like calculating an answer with extra decimal places before rounding it. Exact64 first calculates with roughly 96 bits of precision. If that is enough to determine the correct final binary64 value with certainty, it is done.


In the rare case where the exact result lies so close to the boundary between two possible binary64 numbers that 96 bits are not enough to prove which one is correct, Exact64 recalculates the certification at 128-bit precision.


So P128 does not mean that 96-bit calculation was “bad” or inaccurate. It simply means that more precision was required to prove which of two extremely close 64-bit numbers is the correctly rounded answer.


The easiest analogy is calculating 1.23456… before writing the answer as 1.235. Usually a few extra digits are enough to know how to round. If the value happens to be extremely close to 1.2345…, you calculate more digits before making the decision.


That is essentially what P96 → P128 does — just at binary64 precision and for every interpolated sample.
 
Thanks. That is pretty much the kind of answer I was looking for.
There is also a reason why Exact64 currently focuses specifically on 44.1 → 88.2 kHz. The exact 2× ratio is an unusually favourable special case: every second output sample is simply an original input sample, so only the samples in between require Shannon reconstruction and certification.


With an arbitrary non-integer conversion ratio, much of that convenient structure disappears and the computational cost of this exact/certified approach would increase dramatically.


The current implementation is also deliberately conservative from a performance perspective. It is single-threaded and intentionally kept small and self-contained, with minimal runtime and hardware dependencies. The priority was deterministic, reproducible behaviour and an implementation that is easy to audit — not extracting every last bit of performance from a particular CPU.
 
The algorithm @JulianW uses does not do brickwall filtering, which makes it operate fairly differently from the more traditional upsamplers. Where traditional upsamplers approximate the ideal, Shannon interpolation is the ideal (within the confines of the math precision).
@pjug is asking about PGGB specifically. AFAICT from their page they also use Shannon interpolation without windowing:
The best way to look at the current approach used by PGGB is that it considers the track as a whole. [...], PGGB keeps all of the original samples intact, then creates intermediate samples all at once by time shifting all of the original samples. Our method approaches the theoretical limit of reconstruction accuracy possible for a track of given length and sample rate. This is more accurate than using pure Whittaker-Shannon coefficients with windowing. As the sample rate increases, and the track length increases, our method approaches the mathematical equivalence of using pure sinc based interpolation.
 
@JulianW , please take note of the ASR AI policy:

 
Just for transparency: I use AI to help phrase some of my posts in English. I’m German, and it’s simply the quickest way for me to express exactly what I mean without constantly pulling out a translator

And I’m completely open to independent scrutiny of Exact64. If anyone wants to verify the algorithm, I’m happy to provide the source code, implementation details, test vectors, reference outputs, certification data, or whatever else would be useful for examining and reproducing the results. There’s nothing intended to be a black box here.
 
Just for transparency: I use AI to help phrase some of my posts in English. I’m German, and it’s simply the quickest way for me to express exactly what I mean without constantly pulling out a translator
I thought something like that was going on. The trouble is that you should ask your AI to do a faithful translation. That’s not what it’s doing now. The telltale sign of this are super obvious.
 
If that is the case then it seem to be equivalent to the method the OP uses.
when the specific goal is to determine exactly where Shannon reconstruction says each sample should land in binary64, i think Exact64 has an advantage over PGGB

But idk
Maybe pggb handles this ithe same way
‍♂️
 
I thought something like that was going on. The trouble is that you should ask your AI to do a faithful translation. That’s not what it’s doing now. The telltale sign of this are super obvious.
writing code with ai is one thing, but telling him to be rigor and validate in a suffixient way another cup of tea
 
I am just a white collar worker and no MIT Data specialist
 
I am just a white collar worker and no MIT Data specialist
That's the problem, your posts do sound like that ;) You also don't have to be an actual data specialist to ask: "Please translate this text as faithfully and direct as you can from German to English".
 
Back
Top Bottom