Hacker News new | ask | show | jobs
by pxndxx 155 days ago
Sampling does not lose information below the Nyquist limit, but quantization does introduce errors that can't be fixed. And resampling at a different rate might introduce extra errors, like when you recompress a JPEG.
2 comments

I see I lose data on the [18kHz..) range, but at the same time as a male I'm not supposed to hear that past in my early 30s, sprinkle concerts on top and make it more like 16kHz :/

At least I don't have tinnitus.

Here's my test,

    ```fish
    set -l sample ~/Music/your_sample_song.flac  # NOTE: Maybe clip a 30s sample beforehand
    set -l borked /tmp/borked.flac # WARN: Will get overwritten (but more likely won't exist yet)

    cp -f $sample $borked

    for i in (seq 10)
        echo "$i: Resampling to 44.1kHz..."
        ffmpeg -i $borked -ar 44100 -y $borked.tmp.flac 2>/dev/null
        mv $borked.tmp.flac $borked

        echo "$i: Resampling to 48kHz..."
        ffmpeg -i /tmp/borked.flac -ar 48000 -y $borked.tmp.flac 2>/dev/null
        mv $borked.tmp.flac $borked
    end

    echo "Playing original $sample"
    ffplay -nodisp -autoexit $sample 2>/dev/null
    echo "Playing borked file $borked"
    ffplay -nodisp -autoexit $borked 2>/dev/null

    echo "Diffing..."
    set -l spec_config 's=2048x1024:start=0:stop=22000:scale=log:legend=1'
    ffmpeg -i $sample -lavfi showspectrumpic=$spec_config /tmp/sample.png -y 2>/dev/null
    ffmpeg -i $borked -lavfi showspectrumpic=$spec_config /tmp/borked.png -y 2>/dev/null

    echo "Spectrograms,"
    ls -l /tmp/*.spec.png
    ```
In the audio world, quantization is usually discussed in terms of bit-depth rather than sample rate.
Yeah, they know and their comment reflects that knowledge. They're saying that if we had infinite bit depth, we could arbitrarily resample anything to anything as long as the sample rate is above the Nyquist frequency; however we don't have an infinite bit depth, we have a finite bit depth (i.e the samples are quantized), which limits the dynamic range (i.e introduces noise). This noise can compound when resampling.
The key point is that even with finite bit depth (as long as you dither properly), the effect of finite bit depth is easily controlled noise of program chosen spectrum. i.e. as long as your sampling isn't doing anything really dumb, the noise introduced by sampling is well below noise floor.
Yeah, but that noise keeps compounding every time you resample.
I've been trying to figure out whether this is true or not, and I've only been able to find that it doesn't compound: the noise from the original quantization and the noise from the second (post-resample) quantisation aren't independent, both arise from rounding the data to the same 16-bit grid. Somehow, this seems to mean the noise doesn't compound.

I wish I understood this better and at least knew whether it's true or false. I have to do more reading on it.

Sure, but you will resample ~5 times max.