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

Non-deterministic output #8

Open
AllianceDarkSylinc opened this issue Oct 21, 2022 · 2 comments
Open

Non-deterministic output #8

AllianceDarkSylinc opened this issue Oct 21, 2022 · 2 comments

Comments

@AllianceDarkSylinc
Copy link

Each run of soxr will produce different results.

In certain contexts this can be undesirable.

We stumbled on this problem today.

As far as I could research on the Internet, this problem has been brought up at least twice:

The Stack Overflow narrowed down the problem to the SOXR_NO_DITHER flag, as it indeed uses a seed that depends on time() and the random address of a variable:

p->seed = (unsigned long)time(0) ^ (unsigned long)(size_t)p;

The solution is obvious & straightforward: Allow to provide the seed externally, instead of setting it to a different value on each run:

void soxr_setseed(soxr_t resampler, soxr_seed_t new_seed)
{  
    resampler->seed = new_seed;
}

soxr_seed_t soxr_getseed(soxr_t resampler)
{  
    return resampler->seed;
}
@AllianceDarkSylinc
Copy link
Author

If anyone arrives here, as a quick hack I've forked the project so that ffmpeg can generate deterministic outputs.

Works on macOS & Linux

@Philippe91
Copy link

The seed value is only used if the soxr output is 16 samples. In that case, some dithering process is applied. This means some noise is added to the signal to somehow mask quantization errors. Hence this is not a bug but a feature.

This being said, using a fixed seed to produce a deterministic result won't harm the result. What is essential is the apparent randomization from sample to sample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants