Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Sample rate conversion (Read 24270 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Sample rate conversion

Reply #25
I still don´t get how any sample can be exactly the same when a lowpass is applied to it in the output!? I hope i only need a small hint

Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency; if all the frequencies in the input signal are below the cutoff frequency, and the filter is implemented in a 'perfect' way, then the signal is unaffected.  E.g. an input signal comprising a sine wave swept from 0-22kHz has no frequency component at or above the cutoff (~23kHz), so is unaffected.

Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

Quote
Is there any sample intact? And how to tell?


Using the 'code' I provided above; it uses a little trick  to throw away the interpolated samples from the 96k file thus rendering it back to a 48k file (without filtering, but that's okay in this instance), which is then file-compared to the original.  The files are identical barring a few samples at the beginning and end (which are the result of filtering discontinuties).

Sample rate conversion

Reply #26
Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency;

It does! — by definition of the cutoff frequency (-3 dB point).

Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

For other filters it's highly unlikely that they will preserve the original samples (which is not a flaw).
However SoX may well be the half-band filter (unless ordered a shifted cutoff frequency).

Sample rate conversion

Reply #27
Using the 'code' I provided above; it uses a little trick  to throw away the interpolated samples from the 96k file thus rendering it back to a 48k file (without filtering, but that's okay in this instance), which is then file-compared to the original.  The files are identical barring a few samples at the beginning and end (which are the result of filtering discontinuties).

Interesting. So this is more by accident here because we have a 440Hz tone that has no content near the lowpass. On normal music i suppose sox does have to apply it to almost every sample. Will this be the same in this special case when we use a uneven resample to lets say 88.2? I doubt. So all these claims about a resampler is more precise in upsampling by even numbers has some evidence.

Edit: Lol, just read Mr. Lukins answer... So how does it come your trick to throw away the interpolated samples show the original samples!? Does sox use Half-Band. From the frequency plot i doubt this.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Sample rate conversion

Reply #28
I am getting slowly mad in here or lowpass myself

So many real experts and no simple words for an average human being like me.
May we take a snapshot and can someone please answer me 4 questions?

1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k
2. If it isn´t, is there one you are aware of.
3. Is the reasoning that all apply a lowpass on upsampling and so change EVERY single sample correct?
4. Does it play a role at all then to upsample with an even or uneven number?

To my understanding atm it is No-No-Yes-No
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Sample rate conversion

Reply #29
Because (by definition) the lowpass doesn't affect frequencies below its cutoff frequency;

It does! — by definition of the cutoff frequency (-3 dB point).

Yes, but not by much  (And of course, with sinc filters, it's usual to use the -6dB point but I was trying to simplify for Wombat's benefit)

Quote
Whilst half-band filters may leave samples unaffected, other FIRs may too—sox's filter is not half-band (a half-band upsampling filter always has some imaging remaining).

For other filters it's highly unlikely that they will preserve the original samples (which is not a flaw).
However SoX may well be the half-band filter (unless ordered a shifted cutoff frequency).

In fact, I  checked 3 resamplers: sox, ssrc, & sndfile-resample. Allowing for the fact the ssrc prepends a couple of spurious samples and sndfile-resample truncates by one sample, all 3 did pretty well on the test: alternate output samples were the same as the input samples (tested at bit-depth 16, input: a 440Hz tone).

According to its design, SoX does not use a half-band filter. Checks on its output (including those at http://src.infinitewave.ca) confirm this as they show no imaging (a characteristic of half-band filters).

So this is more by accident here because we have a 440Hz tone that has no content near the lowpass.

No accident, it was part of the test design.  The test also included tones up to 22kHz and a sweep from 0 to 22kHz—these all passed. A tone of 23kHz did not pass but no real surprises here. (These other tests were performed only on SoX)

Quote
On normal music i suppose sox does have to apply it to almost every sample. Will this be the same in this special case when we use a uneven resample to lets say 88.2? I doubt. So all these claims about a resampler is more precise in upsampling by even numbers has some evidence.

The filter is always applied to every sample regardless of the input signal content and sampling rate.  However, if resampling to 88.2, there are very few samples in the output that one might expect (or, in general, care) not to have changed (and I haven't tested this case).

With 'normal' music, it is likely that the test would not pass. One situation where it might would be if the music had started life at 96k, and been downsampled to 48k using a filter with a lower cutoff used when subsequently upsampling.
Quote
Edit: Lol, just read Mr. Lukins answer... So how does it come your trick to throw away the interpolated samples show the original samples!? Does sox use Half-Band. From the frequency plot i doubt this.

Hopefully covered above and previously.

Sample rate conversion

Reply #30
Okay, curiousity got the better of me: in the 48k --> 88.2k example below, every 80th sample of the input matches every 147th sample of the output.

Code: [Select]
sox -b 16 -n 1.wav synth 10 sin 0:12k
sox -D 1.wav 2.wav rate 88.2k
sox -c 80 -r 600 1.wav 1a.wav remix 1
sox -c 147 -r 600 2.wav 2a.wav remix 1
cmp -l 1a.wav 2a.wav


1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k
Depending on 3 things: the input signal bandwidth, the selected filter characteristics, and the selected bit-depth, sometimes yes, sometimes no.

Not checked, but I suspect that if you select -q (cubic interpolation) then the answer is always yes (but the interpolated samples will be much noisier than with band-limited interpolation).

Quote
2. If it isn´t, is there one you are aware of.
See previous post for a brief mention of some other resamplers.

Quote
3. Is the reasoning that all apply a lowpass on upsampling and so change EVERY single sample correct?
No, every sample is processed by the filter but not necessarily changed by it.

Quote
4. Does it play a role at all then to upsample with an even or uneven number?
Not especially, as demonstrated by the 88.2 example above.

Just to bring things back into perspective a little, whilst output samples being the same as input samples might indicate that a certain care has been taken in the implementation, the converse is not necessarily true, and that resampler performance for a given application is generally measured in other terms, see e.g. the graphs and discussion at http://src.infinitewave.ca

Sample rate conversion

Reply #31
Many thanks bandpass for your efforts. Very interesting explanations and simple held for me to understand
Lets hope all your assumptions are true but to me it all makes perfect sense!
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

 

Sample rate conversion

Reply #32
I've just verified that SoX never preserves the values of original samples because its bandwidth (-b) parameter cannot be set to 100%, it's limited between 74 and 99.7%.

Sample rate conversion

Reply #33
I've just verified that SoX never preserves the values of original samples because its bandwidth (-b) parameter cannot be set to 100%, it's limited between 74 and 99.7%.


Now what!? That is what i say from the beginning and bandpass always tells me that with a sample that has no HF content near the cutooff there are untouched samples in the output.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Sample rate conversion

Reply #34
All I have told you is what I have observed through simple experimentation, and since the experiments involved nothing more than running sox a few times and a file comparison program, you can repeat them and draw your own conclusions.

One final experiment.

Create an input signal:
Code: [Select]
sox -b 16 -n 1.wav synth noise gain -4 sinc -22k fade h .01 1 .01

(which looks like this:)


Upsample:
Code: [Select]
sox -D 1.wav 2.wav rate 96k

Dump the input and output files to text:
Code: [Select]
sox 1.wav -t dat 1.txt
sox 2.wav -t dat 2.txt

and check them in a text editor, or, use a graphical diff program:

(1st column is time, 2nd column is sample value)

For good measure, here are the freq. responses of the filter used in the input signal generation (blue, obtained via sox's --plot option) and the resampling filter (red, obtained via resampling an impulse) which, as can be seen, is not a half-band response:

Sample rate conversion

Reply #35
This is only due to the fact that you used the sinc filter during signal generation. Real music is not like that and its sample values will change.

Sample rate conversion

Reply #36
This is only due to the fact that you used the sinc filter during signal generation.

Not only that—at the risk of repeating myself:
1. Is sox a resampler that upsamples with leaving samples intact when upsampling from 48k to 96k

Depending on 3 things: the input signal bandwidth, the selected filter characteristics, and the selected bit-depth, sometimes yes, sometimes no.

Quote
Real music is not like that and its sample values will change.

Not necessarily so. It's not a question of whether the music is real or not, it's whether the recording/mastering/etc. has left any headroom in the frequency domain. For example, MP3 usually lowpasses at 16k and some commercially produced music CDs can also be seen to roll-off well before the nyquist.

Sample rate conversion

Reply #37
Agreed.