r4103 - in trunk: . tools



Author: stw
Date: 2006-11-26 09:40:26 -0500 (Sun, 26 Nov 2006)
New Revision: 4103

Modified:
   trunk/ChangeLog
   trunk/tools/bseloopfuncs.c
   trunk/tools/bseloopfuncs.h
   trunk/tools/bsewavetool.cc
Log:
Sun Nov 26 15:25:49 2006  Stefan Westerfeld  <stefan space twc de>

	* tools/bseloopfuncs.[hc]: Adapted the API of the highpass handle.
	Fixed a bug in the convolution code.

	* tools/bsewavetool.cc: Improved the user interface of the highpass,
	so that the user just needs to specify one single frequency: the
	cutoff frequency.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-11-25 00:39:23 UTC (rev 4102)
+++ trunk/ChangeLog	2006-11-26 14:40:26 UTC (rev 4103)
@@ -1,5 +1,14 @@
-Sat Nov 25 01:37:18 2006  Tim Janik  <timj gtk org>
+Sun Nov 26 15:25:49 2006  Stefan Westerfeld  <stefan space twc de>
 
+	* tools/bseloopfuncs.[hc]: Adapted the API of the highpass handle.
+	Fixed a bug in the convolution code.
+
+	* tools/bsewavetool.cc: Improved the user interface of the highpass,
+	so that the user just needs to specify one single frequency: the
+	cutoff frequency.
+
+Sat Nov 25 01:37:18 2006  Tim Janik  <timj gtk org> 
+
 	* tests/audio/Makefile.am: 
 	* tests/audio/adsrtest.bse: added a simple adsr test that checks ADSR
 	volume in comparison to a reference signal. used avg-spectrum, spectrum

Modified: trunk/tools/bseloopfuncs.c
===================================================================
--- trunk/tools/bseloopfuncs.c	2006-11-25 00:39:23 UTC (rev 4102)
+++ trunk/tools/bseloopfuncs.c	2006-11-26 14:40:26 UTC (rev 4103)
@@ -54,26 +54,23 @@
 fir_hp (const gfloat *src,
 	const guint   n_samples,
 	gfloat       *dest,
-	gdouble       f1,
-	gdouble       f1_level,
-	gdouble       f2)
+	gdouble       cutoff_freq,
+	guint         iorder)
 {
-  const guint iorder = 64;
   double a[iorder + 1];
 
   //const guint transfer_func_length = 64;
   const guint transfer_func_length = 4;
   double transfer_func_freqs[transfer_func_length];
   double transfer_func_values[transfer_func_length];
-  float f1_level_factor = bse_db_to_factor (f1_level);
 
   transfer_func_freqs[0]  = 0;
-  transfer_func_values[0] = f1_level_factor;
+  transfer_func_values[0] = 0;
 
-  transfer_func_freqs[1]  = f1;
-  transfer_func_values[1] = f1_level_factor;
+  transfer_func_freqs[1]  = cutoff_freq;
+  transfer_func_values[1] = 0;
 
-  transfer_func_freqs[2]  = f2;
+  transfer_func_freqs[2]  = cutoff_freq;
   transfer_func_values[2] = 1.0; // 0 dB
 
   transfer_func_freqs[3]  = PI;
@@ -119,17 +116,16 @@
 	  p -= iorder / 2;
 
 	  if (p >= 0 && p < n_samples)
-	    accu += src[p];
+	    accu += a[j] * src[p];
 	}
       dest[i] = accu;
     }
 }
 
 GslDataHandle*
-gsl_loop_highpass_handle (GslDataHandle *src_handle,
-			  gdouble        freq1,
-			  gdouble        freq1_level_db,
-			  gdouble        freq2)
+gsl_data_handle_new_fir_highpass (GslDataHandle *src_handle,
+				  gdouble        cutoff_freq,
+				  guint          order)
 {
   g_return_val_if_fail (src_handle != NULL, NULL);
   
@@ -151,7 +147,7 @@
   
   /* apply fir filter to new memory buffer */
   gfloat *dest_values = g_new (gfloat, src_handle_n_values);
-  fir_hp (src_values, src_handle_n_values, dest_values, freq1, freq1_level_db, freq2);
+  fir_hp (src_values, src_handle_n_values, dest_values, cutoff_freq / src_handle_mix_freq, order);
   g_free (src_values);
   
   /* create a mem handle with filtered data */

Modified: trunk/tools/bseloopfuncs.h
===================================================================
--- trunk/tools/bseloopfuncs.h	2006-11-25 00:39:23 UTC (rev 4102)
+++ trunk/tools/bseloopfuncs.h	2006-11-26 14:40:26 UTC (rev 4103)
@@ -45,24 +45,21 @@
 } GslDataLoopConfig;
 
 /*
- * 0db ----------           __________
- *                         /
- *                        /
- *                       /
- * f1_level (dB) - _____/
+ *           __________
+ *          /
+ *         /
+ *        /
+ *  _____/
+ *         |
+ *    cutoff_freq
  *
- *                      |   |
- *                      f1 f2
- *
- * @freq1: high pass start frequency [0:PI] (SR = 2*PI)
- * @freq2: high pass end frequency [0:PI] (SR = 2*PI)
- * @freq1_level_db: stopband attenuation
+ * @cutoff_freq: cutoff frequency in Hz in intervall [0..SR/2]
+ * @order:       number of falter coefficients
  */
 
-GslDataHandle *gsl_loop_highpass_handle (GslDataHandle *src_handle,
-				         gdouble       freq1,
-				         gdouble       freq1_level_db,
-				         gdouble       freq2);
+GslDataHandle* gsl_data_handle_new_fir_highpass (GslDataHandle *src_handle,
+				                 gdouble        cutoff_freq,
+						 guint          order);
 
 /* mem-cached loop position and size finder. tests through all possible
  * loop sizes around center points determined by block/(analysis_points+1).

Modified: trunk/tools/bsewavetool.cc
===================================================================
--- trunk/tools/bsewavetool.cc	2006-11-25 00:39:23 UTC (rev 4102)
+++ trunk/tools/bsewavetool.cc	2006-11-26 14:40:26 UTC (rev 4103)
@@ -1728,13 +1728,14 @@
 
 class Highpass : public Command {
 public:
-  gdouble freq1, freq1_level, freq2; 
+  gdouble cutoff_freq;
+  guint   order;
+
   Highpass (const char *command_name) :
     Command (command_name)
   {
-    freq1 = 50.0 / 22050.0 * PI;
-    freq1_level = -48;
-    freq2 = PI / 2.0;
+    cutoff_freq = -1;
+    order = 64;
   }
   void
   blurb (bool bshort)
@@ -1743,9 +1744,7 @@
     if (bshort)
       return;
     g_print ("    Apply highpass filter to wave data\n");
-    g_print ("    --freq1 <f>          stopband end freqency in Hz [%f]\n", freq1);
-    g_print ("    --freq1-level <db>   stopband attenuation in dB [%f]\n", freq1_level);
-    g_print ("    --freq2 <f>          passband start freqency in Hz [%f]\n", freq2);
+    g_print ("    --cutoff-freq <f>    filter cutoff frequency in Hz\n");
     /*       "**********1*********2*********3*********4*********5*********6*********7*********" */
   }
   guint
@@ -1755,20 +1754,12 @@
     for (guint i = 1; i < argc; i++)
       {
 	const gchar *str = NULL;
-	if (parse_str_option (argv, i, "--freq1-level", &str, argc))
+	if (parse_str_option (argv, i, "--cutoff-freq", &str, argc))
 	  {
-	    freq1_level = g_ascii_strtod (str, NULL);
+	    cutoff_freq = g_ascii_strtod (str, NULL);
 	  }
-	else if (parse_str_option (argv, i, "--freq1", &str, argc))
-	  {
-	    freq1 = g_ascii_strtod (str, NULL);
-	  }
-	else if (parse_str_option (argv, i, "--freq2", &str, argc))
-	  {
-	    freq2 = g_ascii_strtod (str, NULL);
-	  }
       }
-    return 0; // no missing args
+    return (cutoff_freq <= 0); // missing args
   }
   void
   exec (Wave *wave)
@@ -1779,17 +1770,24 @@
       {
         WaveChunk *chunk = &*it;
         GslDataHandle *dhandle = chunk->dhandle;
-	sfi_info ("HIGHPASS: chunk %f: freq1=%f freq1_level=%f freq2=%f", gsl_data_handle_osc_freq (chunk->dhandle),
-									  freq1, freq1_level, freq2);
-
-        BseErrorType error = chunk->change_dhandle (gsl_loop_highpass_handle (dhandle, freq1, freq1_level, freq2), 0, 0);
-        if (error)
-          {
-            sfi_error ("chunk % 7.2f/%.0f: %s",
-                       gsl_data_handle_osc_freq (chunk->dhandle), gsl_data_handle_mix_freq (chunk->dhandle),
-                       bse_error_blurb (error));
-            exit (1);
-          }
+	sfi_info ("HIGHPASS: chunk %f: cutoff_freq=%f order=%d", gsl_data_handle_osc_freq (chunk->dhandle),
+								 cutoff_freq, order);
+	if (cutoff_freq >= gsl_data_handle_mix_freq (dhandle) / 2.0)
+	  {
+	    sfi_error ("chunk % 7.2f/%.0f: IGNORED - can't filter this chunk, cutoff frequency (%f) too high\n",
+	    gsl_data_handle_osc_freq (chunk->dhandle), gsl_data_handle_mix_freq (dhandle), cutoff_freq);
+	  }
+	else
+	  {
+	    BseErrorType error = chunk->change_dhandle (gsl_data_handle_new_fir_highpass (dhandle, cutoff_freq, order), 0, 0);
+	    if (error)
+	      {
+		sfi_error ("chunk % 7.2f/%.0f: %s",
+			   gsl_data_handle_osc_freq (chunk->dhandle), gsl_data_handle_mix_freq (chunk->dhandle),
+			   bse_error_blurb (error));
+		exit (1);
+	      }
+	  }
       }
   }
 } cmd_highpass ("highpass");




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]