blob: 55cd2a3c70c342429a047633147d77eaf51222db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/*
* alCents2Ratio()
*
* Calculates the pitch shift ratio from the number of cents according to
* ratio = 2^(cents/1200)
*
* This is accurate to within one cent for ratios up and octave and down
* two ocataves.
*/
#include <libaudio.h>
f32 alCents2Ratio(s32 cents)
{
f32 x;
f32 ratio = 1.0f;
if (cents >= 0) {
x = 1.00057779f; /* 2^(1/1200) */
} else {
x = 0.9994225441f; /* 2^(-1/1200) */
cents = -cents;
}
while (cents) {
if (cents & 1)
ratio *= x;
x *= x;
cents >>= 1;
}
return ratio;
}
|