From: Jari Tenhunen Date: Thu, 18 Mar 2010 10:22:49 +0000 (+0000) Subject: make the leds display the difference in steps of two cents X-Git-Tag: fremantle/0.1.3~7 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=88ab0403d5537f185bdd04362fc74e870eb572cf;p=tunertool make the leds display the difference in steps of two cents --- diff --git a/src/tuner.c b/src/tuner.c index 5856674..edae737 100644 --- a/src/tuner.c +++ b/src/tuner.c @@ -59,6 +59,8 @@ #define between(x,a,b) (((x)>=(a)) && ((x)<=(b))) #define MAGIC (1.059463094359f) /* 2^(1/2) */ +#define CENT (1.0005777895f) /* 1/100th of a half-tone */ +#define LOG_CENT (0.00057762265046662109f) /* ln (CENT) */ extern gboolean plugin_pitch_init (GstPlugin * plugin); extern gboolean plugin_tonesrc_init (GstPlugin * plugin); @@ -101,7 +103,7 @@ enum -#define NUM_LEDS (66) +#define NUM_LEDS (50) #define NUM_WKEYS (15) /* # of white keys in the piano keyboard */ #define WKEY_WIDTH (45) @@ -324,6 +326,14 @@ draw_leds (AppData * appdata, gint n) } } +/* translate the interval (ratio of two freqs) into cents */ +gfloat +interval2cent (gfloat freq, gfloat note) +{ + //return (gfloat) (log (freq / note) / log (CENT)); + return (gfloat) (log (freq / note) / LOG_CENT); +} + /* update frequency info */ static void update_frequency (AppData * appdata, gfloat frequency) @@ -353,7 +363,9 @@ update_frequency (AppData * appdata, gfloat frequency) gtk_label_set_text (GTK_LABEL (appdata->currentFrequency), buffer); g_free (buffer); - draw_leds (appdata, (gint) roundf (min_diff)); + /* make leds display the difference in steps of two cents */ + diff = interval2cent (frequency, equal_tempered_scale[j].frequency); + draw_leds (appdata, (gint) roundf (diff / 2.0)); } /* receive spectral data from element message */