summaryrefslogtreecommitdiffstats
path: root/apps/gui/pitchscreen.c
diff options
context:
space:
mode:
authorAlexander Levin <al.le@rockbox.org>2009-07-12 17:14:01 +0000
committerAlexander Levin <al.le@rockbox.org>2009-07-12 17:14:01 +0000
commit76e62917803f5567bd5978c79db6ec9f25837034 (patch)
tree9275d92a7f6ed6039f548105aeffecdbda33b05b /apps/gui/pitchscreen.c
parent4930b328177049589c06c3a35ccdeec8c537094c (diff)
downloadrockbox-76e62917803f5567bd5978c79db6ec9f25837034.tar.gz
rockbox-76e62917803f5567bd5978c79db6ec9f25837034.tar.bz2
rockbox-76e62917803f5567bd5978c79db6ec9f25837034.zip
Unify semitone and cent macros and make the formula a bit more obvious
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21814 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/pitchscreen.c')
-rw-r--r--apps/gui/pitchscreen.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c
index a699d4a7b4..2d0412d822 100644
--- a/apps/gui/pitchscreen.c
+++ b/apps/gui/pitchscreen.c
@@ -80,43 +80,44 @@ enum
All that math in each entry simply converts the float constant
to an integer equal to PITCH_SPEED_PRECISION times the float value,
- with as little precision loss as possible.
+ with as little precision loss as possible (i.e. correctly rounding
+ the last digit).
*/
-#define SEMITONE_VALUE(x) \
- ( (int)(((x) + 0.5 / PITCH_SPEED_PRECISION) * PITCH_SPEED_PRECISION) )
+#define TO_INT_WITH_PRECISION(x) \
+ ( (int)(((x) * PITCH_SPEED_PRECISION * 10 + 5) / 10) )
static const int semitone_table[] =
{
- SEMITONE_VALUE(50),
- SEMITONE_VALUE(52.97315472),
- SEMITONE_VALUE(56.12310242),
- SEMITONE_VALUE(59.46035575),
- SEMITONE_VALUE(62.99605249),
- SEMITONE_VALUE(66.74199271),
- SEMITONE_VALUE(70.71067812),
- SEMITONE_VALUE(74.91535384),
- SEMITONE_VALUE(79.3700526 ),
- SEMITONE_VALUE(84.08964153),
- SEMITONE_VALUE(89.08987181),
- SEMITONE_VALUE(94.38743127),
- SEMITONE_VALUE(100 ),
- SEMITONE_VALUE(105.9463094),
- SEMITONE_VALUE(112.2462048),
- SEMITONE_VALUE(118.9207115),
- SEMITONE_VALUE(125.992105 ),
- SEMITONE_VALUE(133.4839854),
- SEMITONE_VALUE(141.4213562),
- SEMITONE_VALUE(149.8307077),
- SEMITONE_VALUE(158.7401052),
- SEMITONE_VALUE(168.1792831),
- SEMITONE_VALUE(178.1797436),
- SEMITONE_VALUE(188.7748625),
- SEMITONE_VALUE(200 )
+ TO_INT_WITH_PRECISION(50.00000000), /* Octave lower */
+ TO_INT_WITH_PRECISION(52.97315472),
+ TO_INT_WITH_PRECISION(56.12310242),
+ TO_INT_WITH_PRECISION(59.46035575),
+ TO_INT_WITH_PRECISION(62.99605249),
+ TO_INT_WITH_PRECISION(66.74199271),
+ TO_INT_WITH_PRECISION(70.71067812),
+ TO_INT_WITH_PRECISION(74.91535384),
+ TO_INT_WITH_PRECISION(79.37005260),
+ TO_INT_WITH_PRECISION(84.08964153),
+ TO_INT_WITH_PRECISION(89.08987181),
+ TO_INT_WITH_PRECISION(94.38743127),
+ TO_INT_WITH_PRECISION(100.0000000), /* Normal sound */
+ TO_INT_WITH_PRECISION(105.9463094),
+ TO_INT_WITH_PRECISION(112.2462048),
+ TO_INT_WITH_PRECISION(118.9207115),
+ TO_INT_WITH_PRECISION(125.9921049),
+ TO_INT_WITH_PRECISION(133.4839854),
+ TO_INT_WITH_PRECISION(141.4213562),
+ TO_INT_WITH_PRECISION(149.8307077),
+ TO_INT_WITH_PRECISION(158.7401052),
+ TO_INT_WITH_PRECISION(168.1792831),
+ TO_INT_WITH_PRECISION(178.1797436),
+ TO_INT_WITH_PRECISION(188.7748625),
+ TO_INT_WITH_PRECISION(200.0000000) /* Octave higher */
};
#define NUM_SEMITONES ((int)(sizeof(semitone_table) / sizeof(int)))
-#define SEMITONE_START -12
-#define SEMITONE_END 12
+#define SEMITONE_END (NUM_SEMITONES/2)
+#define SEMITONE_START (-SEMITONE_END)
/* A table of values for approximating the cent curve with
linear interpolation. Multipy the next lowest semitone
@@ -126,19 +127,15 @@ static const int semitone_table[] =
x(n) = 100 * 2^(n * 20/1200)
*/
-#define CENT_INTERP(x) \
- ( (int)(((x) + 0.5 / PITCH_SPEED_PRECISION) * PITCH_SPEED_PRECISION) )
-
-
static const int cent_interp[] =
{
- PITCH_SPEED_100,
- CENT_INTERP(101.1619440),
- CENT_INTERP(102.3373892),
- CENT_INTERP(103.5264924),
- CENT_INTERP(104.7294123),
+ TO_INT_WITH_PRECISION(100.0000000),
+ TO_INT_WITH_PRECISION(101.1619440),
+ TO_INT_WITH_PRECISION(102.3373892),
+ TO_INT_WITH_PRECISION(103.5264924),
+ TO_INT_WITH_PRECISION(104.7294123),
/* this one's the next semitone but we have it here for convenience */
- CENT_INTERP(105.9463094),
+ TO_INT_WITH_PRECISION(105.9463094),
};
/* Number of cents between entries in the cent_interp table */