/* vim: set sts=2 sw=2 et: */
/* Tuner
* Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
+ * 2008-2009 Jari Tenhunen <jari.tenhunen@iki.fi>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#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);
-#define NUM_LEDS (66)
+#define NUM_LEDS (50)
#define NUM_WKEYS (15) /* # of white keys in the piano keyboard */
#define WKEY_WIDTH (45)
}
}
+/* 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, gint frequency)
+update_frequency (AppData * appdata, gfloat frequency)
{
gchar *buffer;
gint i, j;
gtk_label_set_text (GTK_LABEL (appdata->targetFrequency), buffer);
g_free (buffer);
- buffer = g_strdup_printf ("Played frequency is %d Hz", frequency);
+ buffer = g_strdup_printf ("Played frequency is %.2f Hz", 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 */
const gchar *name = gst_structure_get_name (s);
if (strcmp (name, "pitch") == 0) {
- gint frequency;
+ gfloat frequency;
- frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
+ frequency = g_value_get_float (gst_structure_get_value (s, "frequency"));
if (frequency != 0)
update_frequency (data, frequency);
}
return FALSE;
}
+#ifdef FAKE_FREQUENCY
static gboolean
fake_frequency (gpointer user_data)
{
AppData * appdata = (AppData *) user_data;
- update_frequency (appdata, 440);
+ update_frequency (appdata, 440.0);
return TRUE;
}
+#endif
#ifdef MAEMO
static void
gtk_init (&argc, &argv);
app = HILDON_PROGRAM (hildon_program_get_instance ());
- g_set_application_name ("Tuner Tool");
+ g_set_application_name ("Tuner");
appdata->app = app;
if (appdata->display_keepalive)
display_keepalive (appdata);
+ draw_leds (appdata, 0);
+
set_pipeline_states (appdata, GST_STATE_PLAYING);
- //g_timeout_add (2000, (GSourceFunc) fake_frequency, appdata);
+#ifdef FAKE_FREQUENCY
+ g_timeout_add (2000, (GSourceFunc) fake_frequency, appdata);
+#endif
gtk_main ();