Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resampler quality #153

Closed
baranovmv opened this issue Feb 5, 2018 · 5 comments
Closed

Resampler quality #153

baranovmv opened this issue Feb 5, 2018 · 5 comments
Labels
postponed We decided to postpone the issue for an indefinite period

Comments

@baranovmv
Copy link
Member

What's wrong

While running roc-resample with bypassed resampler:

bool Resampler::resample_buff(Frame& out) {
    roc_panic_if(!prev_frame_);
    roc_panic_if(!curr_frame_);
    roc_panic_if(!next_frame_);

    static size_t window_i = 0;

    for (; out_frame_i_ < out.size(); out_frame_i_ += channels_num_) {
        if(window_i >= window_size_){
            window_i = 0;
            return false;
        }
        out.data()[out_frame_i_] = curr_frame_[window_i];
        out.data()[out_frame_i_+1] = curr_frame_[window_i+1];
        window_i += channels_num_;
    }
    out_frame_i_ = 0;
    return true;
}

so that the output of resampler is a copy of the input, the spectrum of the resulting wav-file looks like that:

screenshot from 2018-02-05 13 29 56

How to reproduce

  1. modify resampler.cpp with the snippet from above and compile,
  2. generate sample signal with singen.py,
  3. bin/x86_64-pc-linux-gnu/roc-resample -i /tmp/sin.wav -o /tmp/sin_out.wav -r48000 --interp=2048 --window=128 --frame=2048
  4. compare input signal spectrum vs. output: ./double_spectrum.py -f /tmp/sin_out.wav -i /tmp/sin.wav
@baranovmv
Copy link
Member Author

@gavv gavv added this to the 0.1 milestone Feb 7, 2018
@gavv gavv added the defect Something isn't working label Feb 7, 2018
@gavv gavv self-assigned this Jan 9, 2019
@gavv
Copy link
Member

gavv commented Jan 10, 2019

It seems that you forget to cut the first and last 1024 samples (frame_size / channel_num) from the original signal. Resampler always cuts them so I guess we should exclude them from the comparison. Also, SoX writer drops some samples at the end.

After taking this into account, I got the following results:

spectrum

So it's not a leakage, it's how the original signal looks like. When the resampler is hacked to copy its input, the output is indeed identical to the input. When the resampler is functioning, the spectrum is changed, but there is no leakage, as I understand it.

I've also prepared a script that plots the difference between the input and output signals. Results:

diff

My scripts: https://gist.github.com/gavv/56fa6c81eb26244e8d891da5293eaef8

Command to run resampler:

$ roc-conv -vv -i original.wav -o resampler_sc1.wav -r 48000 \
  --resampler-interp=2048 --resampler-window=128 --resampler-frame=2048

It is also possible now to disable resampler completely and just copy the signal using SoX:

$ roc-conv -vv -i original.wav -o resampler_sc1.wav -r 48000 \
  --no-resampling

The output is also identical to the input, as well as with the hacked resampler from your comment above.

@gavv
Copy link
Member

gavv commented Jan 10, 2019

Another thing that I noticed is that the resampler gains the signal a bit (just like the SoX resampler, for example).

@gavv gavv removed their assignment Feb 19, 2019
@gavv gavv added discussion Thoughts, discussions and removed defect Something isn't working labels Feb 19, 2019
@gavv gavv removed this from the 0.1 milestone Feb 19, 2019
@gavv
Copy link
Member

gavv commented Apr 29, 2019

One more sample.

Input signal:

Zoomed input:

Zoomed input vs output:

image

diff(input) vs diff(output):

image

Zoomed diff(input) vs diff(output):

image

@gavv
Copy link
Member

gavv commented Jun 9, 2019

See also #105, which provides example spectrum on resampled white noise:

s1
s2
s3
s4

@gavv gavv changed the title Resampler tool produces leaked spectrum Resampler quality Jun 9, 2019
@gavv gavv added postponed We decided to postpone the issue for an indefinite period and removed discussion Thoughts, discussions labels May 27, 2020
@gavv gavv closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
postponed We decided to postpone the issue for an indefinite period
Projects
Status: Done
Development

No branches or pull requests

2 participants