4c2fdd7f09e29f5fdb1ecd876d66647775f37f77
diff --git a/bse/ChangeLog b/bse/ChangeLog
index a59b277..8939f02 100644
--- a/bse/ChangeLog
+++ b/bse/ChangeLog
@@ -1,3 +1,20 @@
+Wed Oct 31 22:13:53 2007  Stefan Westerfeld  <stefan@space.twc.de>
+
+	Merge BSE_FINE_TUNE_FACTOR() and bse_cent_factor(), bug #450490.
+
+	* bse/bseglobals.h:
+	* bsemathsignal.[hc]: Merge BSE_FINE_TUNE_FACTOR() and
+	bse_cent_factor() to bse_cent_tune_fast(). The resulting function
+	automatically clamps its input and uses the cent table to compute its
+	result.
+
+	* bse/bseinfo.c:
+	* bse/bsenote.cc:
+	* bse/bsepart.h:
+	* bse/bsesong.proc:
+	* bse/gsloscillator-aux.c:
+	* bse/tests/misctests.cc: Use bse_cent_tune_fast() where appropriate.
+
 Wed Oct 31 21:50:15 2007  Stefan Westerfeld  <stefan@space.twc.de>
 
 	* tests/misctests.cc: Added test for bse_cent_tune().
diff --git a/bse/bseglobals.h b/bse/bseglobals.h
index fbd0633..ea89ddf 100644
--- a/bse/bseglobals.h
+++ b/bse/bseglobals.h
@@ -78,7 +78,6 @@ guint	  bse_idle_timed	(guint64	usec_delay,
  * (SFI_KAMMER_NOTE + 12) -> 2.0
  * etc...
  */
-#define	BSE_FINE_TUNE_FACTOR(ft)	(bse_cent_factor (CLAMP ((ft), BSE_MIN_FINE_TUNE, BSE_MAX_FINE_TUNE)))
 #define	BSE_TRANSPOSE_FACTOR(st)	(bse_transpose_factor (CLAMP (st, -132, +132)))	/* BSE_MAX_TRANSPOSE */
 
 
diff --git a/bse/bseinfo.c b/bse/bseinfo.c
index 5e5669e..437cef5 100644
--- a/bse/bseinfo.c
+++ b/bse/bseinfo.c
@@ -48,7 +48,7 @@ print_fine_tune (const gchar *tune_name,
 {
   g_print ("%s =%-4d \tfactor=%"FLF"f\n",
 	   tune_name, tune,
-	   BSE_FINE_TUNE_FACTOR (tune));
+	   bse_cent_tune_fast (tune));
 }
 
 int
diff --git a/bse/bsemathsignal.c b/bse/bsemathsignal.c
index 7ab0acd..19505c4 100644
--- a/bse/bsemathsignal.c
+++ b/bse/bsemathsignal.c
@@ -29,7 +29,7 @@ bse_frequency_modulator (const BseFrequencyModulator *fm,
   gfloat *bound, fine_tune, fm_strength;
   gboolean with_fine_tune;
 
-  fine_tune = bse_cent_factor (fm->fine_tune);
+  fine_tune = bse_cent_tune_fast (fm->fine_tune);
   with_fine_tune = fm->fine_tune != 0;
   fm_strength = fm->fm_strength;
   
@@ -219,8 +219,8 @@ const double * const bse_cent_table = cent_table201 + 100;
  *
  * This function computes a factor which corresponds to a given fine tuning in
  * cent.  The result can be used as factor for the frequency or the play speed.
- * It is similar to the bse_cent_factor(); however, it doesn't use a table
- * internally, so the input is not limited in any way (i.e. 777.777 is a valid
+ * It is similar to the bse_cent_tune_fast(). It doesn't use a table internally,
+ * so the input is not limited in any way (i.e. a double like 777.777 is a valid
  * fine_tune argument). However, it is computationally more expensive.
  */
 double
diff --git a/bse/bsemathsignal.h b/bse/bsemathsignal.h
index fd98424..739d534 100644
--- a/bse/bsemathsignal.h
+++ b/bse/bsemathsignal.h
@@ -399,10 +399,19 @@ double        bse_transpose_factor           (BseMusicalTuningType musical_tunin
                                               int                  index /* [-132..+132] */);
 
 /* --- cents (1/100th of a semitone) --- */
-extern const double * const bse_cent_table;
-#define	bse_cent_factor(index /* -100..+100 */)		(bse_cent_table[index])
+double                  bse_cent_tune (double fine_tune);
 
-double  bse_cent_tune (double fine_tune);
+/**
+ * @param fine_tune	fine tuning in cent between -100 and 100
+ * @return		a factor corresponding to this
+ *
+ * This function computes a factor which corresponds to a given fine tuning in
+ * cent.  The result can be used as factor for the frequency or the play speed.
+ * It is a faster alternative to bse_cent_tune(), and can only deal with
+ * integer values between -100 and 100. The input is always CLAMPed to ensure
+ * that it lies in this range.
+ */
+static inline double	bse_cent_tune_fast (int fine_tune /* -100..+100 */)   G_GNUC_CONST;
 
 /* --- implementation details --- */
 static inline double  G_GNUC_CONST
@@ -707,6 +716,14 @@ bse_saturate_branching (double value,
 
 void    _bse_init_signal (void);
 
+static inline double G_GNUC_CONST
+bse_cent_tune_fast (int fine_tune)
+{
+  extern const double * const bse_cent_table;
+
+  return bse_cent_table[CLAMP (fine_tune, -100, 100)];
+}
+
 G_END_DECLS
 
 #endif /* __BSE_SIGNAL_H__ */
diff --git a/bse/bsenote.cc b/bse/bsenote.cc
index 3a99cf1..ae040f5 100644
--- a/bse/bsenote.cc
+++ b/bse/bsenote.cc
@@ -110,7 +110,7 @@ bse_note_to_tuned_freq (BseMusicalTuningType musical_tuning,
   if (note < BSE_MIN_NOTE || note > BSE_MAX_NOTE)
     return 0.0;
   double semitone_factor = bse_transpose_factor (musical_tuning, note - SFI_KAMMER_NOTE);
-  return BSE_KAMMER_FREQUENCY * semitone_factor * BSE_FINE_TUNE_FACTOR (fine_tune);
+  return BSE_KAMMER_FREQUENCY * semitone_factor * bse_cent_tune_fast (fine_tune);
 }
 
 
diff --git a/bse/bsepart.h b/bse/bsepart.h
index 39f7630..1ad3054 100644
--- a/bse/bsepart.h
+++ b/bse/bsepart.h
@@ -270,7 +270,7 @@ struct _BsePartEventNote
 #define BSE_PART_SEMITONE_FACTOR(part,noteval)  (bse_part_transpose_factor ((part), CLAMP ((noteval), SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE))
 #define BSE_PART_NOTE_FREQ(part,note)           (BSE_KAMMER_FREQUENCY *                                 \
                                                  BSE_PART_SEMITONE_FACTOR ((part), (note)->note) *      \
-                                                 BSE_FINE_TUNE_FACTOR ((note)->fine_tune))
+                                                 bse_cent_tune_fast ((note)->fine_tune))
 
 void              bse_part_note_channel_init          (BsePartNoteChannel *self);
 BsePartEventNote* bse_part_note_channel_lookup        (BsePartNoteChannel *self,
diff --git a/bse/bsesong.proc b/bse/bsesong.proc
index 6421d4a..03b1d8e 100644
--- a/bse/bsesong.proc
+++ b/bse/bsesong.proc
@@ -488,7 +488,7 @@ METHOD (BseSong, synthesize-note) {
   if (BSE_SOURCE_PREPARED (self) && self->midi_receiver_SL)
     {
       double semitone_factor = bse_transpose_factor (self->musical_tuning, CLAMP (note, SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE);
-      double freq = BSE_KAMMER_FREQUENCY * semitone_factor * BSE_FINE_TUNE_FACTOR (fine_tune);
+      double freq = BSE_KAMMER_FREQUENCY * semitone_factor * bse_cent_tune_fast (fine_tune);
       SfiTime tstamp = gsl_tick_stamp () + bse_engine_block_size () * 2;
       BseMidiEvent *eon, *eoff;
       eon  = bse_midi_event_note_on (track->midi_channel_SL, tstamp, freq, velocity);
diff --git a/bse/gsloscillator-aux.c b/bse/gsloscillator-aux.c
index 69448e6..9291dd4 100644
--- a/bse/gsloscillator-aux.c
+++ b/bse/gsloscillator-aux.c
@@ -43,7 +43,7 @@ GSL_INCLUDER_FUNC (GslOscData   *osc,
   gfloat last_pwm_level = osc->last_pwm_level;
   gdouble last_freq_level = osc->last_freq_level;
   const gdouble transpose = osc->config.transpose_factor;
-  const gdouble fine_tune = bse_cent_factor (CLAMP (osc->config.fine_tune, -100, +100));
+  const gdouble fine_tune = bse_cent_tune_fast (osc->config.fine_tune);
   guint32 cur_pos = osc->cur_pos;
   guint32 last_pos = osc->last_pos;
   guint32 sync_pos, pos_inc;
diff --git a/bse/tests/misctests.cc b/bse/tests/misctests.cc
index cfeef10..54335ac 100644
--- a/bse/tests/misctests.cc
+++ b/bse/tests/misctests.cc
@@ -23,14 +23,14 @@
 #define	FLF	"26.20"
 
 static void
-check_cent_table (void)
+check_cent_tune_fast (void)
 {
-  TSTART ("Cent Table");
+  TSTART ("Cent Tune Function (fast Table based implementation)");
   const double epsilon = 1e-15;
   for (int i = -100; i <= +100; i++)
     {
       double setpoint = pow (2.0, 1. / 1200. * i);
-      TCHECK_CMP (fabs (bse_cent_factor (i) - setpoint), <, epsilon);
+      TCHECK_CMP (fabs (bse_cent_tune_fast (i) - setpoint), <, epsilon);
       if (i % 13 == 0)
         TOK();
     }
@@ -127,8 +127,8 @@ main (gint   argc,
 {
   bse_init_test (&argc, &argv, NULL);
 
-  check_cent_table();
   check_cent_tune();
+  check_cent_tune_fast();
   check_equal_tempered_tuning();
 
   BseMusicalTuningType last_tuning = BSE_MUSICAL_TUNING_YOUNG;
