Skip to content
Snippets Groups Projects
Commit 14fb264a authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Fix sampling bug for 16-bit rand()

According to David Rowe, when rand() returns RAND_MAX (which is likely
for 16-bit output), we end up producing a click.
parent 8f887b62
No related branches found
No related tags found
No related merge requests found
......@@ -392,10 +392,10 @@ int sample_from_pdf(const float *pdf, int N, float exp_boost, float pdf_floor)
tmp[i] = tmp[i-1] + MAX16(0, norm*tmp[i] - pdf_floor);
}
/* Do the sampling (from the cdf). */
r = tmp[N-1] * ((float)rand()/RAND_MAX);
r = tmp[N-1] * ((rand()+.5f)/(RAND_MAX+1.f));
for (i=0;i<N-1;i++)
{
if (r < tmp[i]) return i;
if (r <= tmp[i]) return i;
}
return N-1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment