summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-09-07 14:09:16 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-09-07 14:09:16 +0000
commitbd737477bf77c426cd79ca08f94f4ac16c35d615 (patch)
tree16cbc8d1cf1a9764a6cb86ff453178ac1f461526
parent791d425ff1391772b23add013e69734a97eb9399 (diff)
downloadrockbox-bd737477bf77c426cd79ca08f94f4ac16c35d615.zip
rockbox-bd737477bf77c426cd79ca08f94f4ac16c35d615.tar.gz
rockbox-bd737477bf77c426cd79ca08f94f4ac16c35d615.tar.bz2
rockbox-bd737477bf77c426cd79ca08f94f4ac16c35d615.tar.xz
pitch_detector: build with -std=gnu99
casts in const tables declaration seesm to confuse gcc into thinking the initializers are not constant Also merge struct declaration and typedef git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28020 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/pitch_detector.c86
1 files changed, 44 insertions, 42 deletions
diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c
index 2b80f5c..4518403 100644
--- a/apps/plugins/pitch_detector.c
+++ b/apps/plugins/pitch_detector.c
@@ -71,11 +71,10 @@
/* Some fixed point calculation stuff */
typedef int32_t fixed_data;
-struct _fixed
+typedef struct
{
fixed_data a;
-};
-typedef struct _fixed fixed;
+} fixed;
#define FIXED_PRECISION 18
#define FP_MAX ((fixed) {0x7fffffff})
#define FP_MIN ((fixed) {-0x80000000})
@@ -83,8 +82,11 @@ typedef struct _fixed fixed;
#define int2mantissa(x) ((fixed){x})
#define fixed2int(x) ((int)((x).a >> FIXED_PRECISION))
#define fixed2float(x) (((float)(x).a) / ((float)(1 << FIXED_PRECISION)))
-#define float2fixed(x) \
- ((fixed){(fixed_data)(x * (float)(1 << FIXED_PRECISION))})
+
+/* cast in tables confuse gcc -std=gnu99 */
+#define float2fixed_decl(x) {(fixed_data)(x * (float)(1 << FIXED_PRECISION))}
+#define float2fixed(x) ((fixed)float2fixed_decl(x))
+
/* I adapted these ones from the Rockbox fixed point library */
#define fp_mul(x, y) \
((fixed){(((int64_t)((x).a)) * ((int64_t)((y).a))) >> (FIXED_PRECISION)})
@@ -150,20 +152,20 @@ typedef struct _fixed fixed;
#define DEFAULT_YIN_THRESHOLD 5 /* 0.10 */
static const fixed yin_threshold_table[] IDATA_ATTR =
{
- float2fixed(0.01),
- float2fixed(0.02),
- float2fixed(0.03),
- float2fixed(0.04),
- float2fixed(0.05),
- float2fixed(0.10),
- float2fixed(0.15),
- float2fixed(0.20),
- float2fixed(0.25),
- float2fixed(0.30),
- float2fixed(0.35),
- float2fixed(0.40),
- float2fixed(0.45),
- float2fixed(0.50),
+ float2fixed_decl(0.01),
+ float2fixed_decl(0.02),
+ float2fixed_decl(0.03),
+ float2fixed_decl(0.04),
+ float2fixed_decl(0.05),
+ float2fixed_decl(0.10),
+ float2fixed_decl(0.15),
+ float2fixed_decl(0.20),
+ float2fixed_decl(0.25),
+ float2fixed_decl(0.30),
+ float2fixed_decl(0.35),
+ float2fixed_decl(0.40),
+ float2fixed_decl(0.45),
+ float2fixed_decl(0.50),
};
/* Structure for the reference frequency (frequency of A)
@@ -178,17 +180,17 @@ static const struct
const fixed logratio; /* log2(factor) */
} freq_A[] =
{
- {435, float2fixed(1.011363636), float2fixed( 0.016301812)},
- {436, float2fixed(1.009090909), float2fixed( 0.013056153)},
- {437, float2fixed(1.006818182), float2fixed( 0.009803175)},
- {438, float2fixed(1.004545455), float2fixed( 0.006542846)},
- {439, float2fixed(1.002272727), float2fixed( 0.003275132)},
- {440, float2fixed(1.000000000), float2fixed( 0.000000000)},
- {441, float2fixed(0.997727273), float2fixed(-0.003282584)},
- {442, float2fixed(0.995454545), float2fixed(-0.006572654)},
- {443, float2fixed(0.993181818), float2fixed(-0.009870244)},
- {444, float2fixed(0.990909091), float2fixed(-0.013175389)},
- {445, float2fixed(0.988636364), float2fixed(-0.016488123)},
+ {435, float2fixed_decl(1.011363636), float2fixed_decl( 0.016301812)},
+ {436, float2fixed_decl(1.009090909), float2fixed_decl( 0.013056153)},
+ {437, float2fixed_decl(1.006818182), float2fixed_decl( 0.009803175)},
+ {438, float2fixed_decl(1.004545455), float2fixed_decl( 0.006542846)},
+ {439, float2fixed_decl(1.002272727), float2fixed_decl( 0.003275132)},
+ {440, float2fixed_decl(1.000000000), float2fixed_decl( 0.000000000)},
+ {441, float2fixed_decl(0.997727273), float2fixed_decl(-0.003282584)},
+ {442, float2fixed_decl(0.995454545), float2fixed_decl(-0.006572654)},
+ {443, float2fixed_decl(0.993181818), float2fixed_decl(-0.009870244)},
+ {444, float2fixed_decl(0.990909091), float2fixed_decl(-0.013175389)},
+ {445, float2fixed_decl(0.988636364), float2fixed_decl(-0.016488123)},
};
/* Index of the entry for 440 Hz in the table (default frequency for A) */
@@ -266,18 +268,18 @@ static const struct
const fixed logfreq; /* log2(frequency) */
} notes[] =
{
- {"A" , float2fixed(440.0000000f), float2fixed(8.781359714f)},
- {"A#", float2fixed(466.1637615f), float2fixed(8.864693047f)},
- {"B" , float2fixed(493.8833013f), float2fixed(8.948026380f)},
- {"C" , float2fixed(523.2511306f), float2fixed(9.031359714f)},
- {"C#", float2fixed(554.3652620f), float2fixed(9.114693047f)},
- {"D" , float2fixed(587.3295358f), float2fixed(9.198026380f)},
- {"D#", float2fixed(622.2539674f), float2fixed(9.281359714f)},
- {"E" , float2fixed(659.2551138f), float2fixed(9.364693047f)},
- {"F" , float2fixed(698.4564629f), float2fixed(9.448026380f)},
- {"F#", float2fixed(739.9888454f), float2fixed(9.531359714f)},
- {"G" , float2fixed(783.9908720f), float2fixed(9.614693047f)},
- {"G#", float2fixed(830.6093952f), float2fixed(9.698026380f)},
+ {"A" , float2fixed_decl(440.0000000f), float2fixed_decl(8.781359714f)},
+ {"A#", float2fixed_decl(466.1637615f), float2fixed_decl(8.864693047f)},
+ {"B" , float2fixed_decl(493.8833013f), float2fixed_decl(8.948026380f)},
+ {"C" , float2fixed_decl(523.2511306f), float2fixed_decl(9.031359714f)},
+ {"C#", float2fixed_decl(554.3652620f), float2fixed_decl(9.114693047f)},
+ {"D" , float2fixed_decl(587.3295358f), float2fixed_decl(9.198026380f)},
+ {"D#", float2fixed_decl(622.2539674f), float2fixed_decl(9.281359714f)},
+ {"E" , float2fixed_decl(659.2551138f), float2fixed_decl(9.364693047f)},
+ {"F" , float2fixed_decl(698.4564629f), float2fixed_decl(9.448026380f)},
+ {"F#", float2fixed_decl(739.9888454f), float2fixed_decl(9.531359714f)},
+ {"G" , float2fixed_decl(783.9908720f), float2fixed_decl(9.614693047f)},
+ {"G#", float2fixed_decl(830.6093952f), float2fixed_decl(9.698026380f)},
};
/* GUI */