[Converter] Change utility function for safety

Surprised I didn't catch this sooner. This could have resulted in a
division by zero error if either sample rate somehow was zero.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-11 13:39:14 -07:00
parent 7c8a270ed2
commit da8288eeee
1 changed files with 1 additions and 1 deletions

View File

@ -42,7 +42,7 @@ static inline unsigned local_gcd(unsigned a, unsigned b)
*/
static void samples_len(unsigned* r1, unsigned* r2, unsigned N, unsigned M) // example: r1 = 44100, r2 = 48000, N = 20, M = 8192
{
if (r1 == 0 || r2 == 0) return;
if (r1 == 0 || r2 == 0 || *r1 == 0 || *r2 == 0) return;
unsigned v = local_gcd(*r1, *r2); // v = 300
*r1 /= v; *r2 /= v; // r1 = 147; r2 = 160 == 1/300th of second
unsigned n = (v + N-1) / N; // n = 300/20 = 15 times