[FFmpeg-devel] [PATCH 1/4] avfilter/asrc_sine: increase phase precision
Marton Balint
cus at passwd.hu
Fri Nov 8 03:10:39 EET 2024
On Thu, 7 Nov 2024, Nicolas George wrote:
> Thanks for explaining.
>
> You have gotten the math wrong, and therefore are going for an incorrect
> fix. Sure, the 32 bits of precision will push the incorrectness very far
> in the future, but it is still invalid.
>
> The output is not supposed to be periodical for any integer frequency
> (assuming you mean periodical over one period; everything finite is
> eventually periodical). For example, “sine=1000” will NOT be periodical
> over a period, only after the tenth period.
>
> The frequencies that should cause the output to be periodical are the
> frequencies that are integer divisors of the sample rate.
>
> Sure, even for a frequency of 900, the current code uses dphi=87652394
> instead of dphi=4294967296/49=~87652393.80.
>
> Once stated that way, the correct way of getting a periodical output is
> obvious: you need to implement rational arithmetic.
>
> In this particular case, it is quite easy:
>
> 1. Remove the +0.5 in the computation of dphi to get it to round
> downwards, leave everything else as is.
>
> 2. Convert ldexp(sine->frequency, 32) / sine->sample_rate to a rational
> to get a denominator, and subtract the integer part to keep only the
> fractional part, let us call it dphi_rem / dphi_den, with 0 <=
> dphi_rem < dphi_den.
How do you convert the number to rational to get the denominator? Or you
simply want me to use sine->sample_rate?
Thanks,
Marton
>
> 4. Start with phi_rem = -phi_den / 2 (that is the +0.5 we removed).
>
> 5. Each time you add dphi to phi:
>
> 5.1. Add dphi_rem to phi_rem.
>
> 5.2. If phi_rem >= 0, subtract dphi_den to it and increment phi.
>
> Regards,
>
> --
> Nicolas George
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list