r4030 - in trunk: . tools



Author: stw
Date: 2006-10-25 15:39:27 -0400 (Wed, 25 Oct 2006)
New Revision: 4030

Modified:
   trunk/ChangeLog
   trunk/tools/bsefextract.cc
Log:
Wed Oct 25 17:47:44 2006  Stefan Westerfeld  <stefan space twc de>

	* tools/bsefextract.cc: Implemented --join-spectrum-slices, which
	allows joining multiple 30ms spectrums (generated by the --spectrum
	option) into one. The main motivation is getting the file size of
	the reference files in the SVN/tarball down.
	If the filesize doesn't matter, don't use this option, as it makes
	the comparision less accurate.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-10-24 21:56:07 UTC (rev 4029)
+++ trunk/ChangeLog	2006-10-25 19:39:27 UTC (rev 4030)
@@ -1,3 +1,12 @@
+Wed Oct 25 17:47:44 2006  Stefan Westerfeld  <stefan space twc de>
+
+	* tools/bsefextract.cc: Implemented --join-spectrum-slices, which
+	allows joining multiple 30ms spectrums (generated by the --spectrum
+	option) into one. The main motivation is getting the file size of
+	the reference files in the SVN/tarball down.
+	If the filesize doesn't matter, don't use this option, as it makes
+	the comparision less accurate.
+
 Sun Oct 22 17:19:40 2006  Tim Janik  <timj gtk org>
 
 	* web/news.doxi: minor fixups, rotate news.

Modified: trunk/tools/bsefextract.cc
===================================================================
--- trunk/tools/bsefextract.cc	2006-10-24 21:56:07 UTC (rev 4029)
+++ trunk/tools/bsefextract.cc	2006-10-25 19:39:27 UTC (rev 4030)
@@ -52,6 +52,7 @@
   gdouble             base_freq_hint;
   gdouble             focus_center;
   gdouble             focus_width;
+  guint               join_spectrum_slices;
 
   FILE               *output_file;
 
@@ -59,6 +60,7 @@
   void parse (int *argc_p, char **argv_p[]);
   static void print_usage ();
   void validate_percent (const string& option, gdouble value);
+  void validate_int (const string& option, int value, int vmin, int vmax);
 } options;
 
 class Signal
@@ -284,8 +286,9 @@
 struct SpectrumFeature : public Feature
 {
   vector< vector<double> > spectrum;
+  vector< vector<double> > joined_spectrum;
 
-  SpectrumFeature() : Feature ("--spectrum", "generate 30ms spaced frequency spectrums")
+  SpectrumFeature() : Feature ("--spectrum", "generate 30ms sliced frequency spectrums")
   {
   }
 
@@ -347,6 +350,28 @@
     return result;
   }
 
+  vector<double>
+  static join_slices (vector< vector<double> >::const_iterator start,
+		      vector< vector<double> >::const_iterator end,
+		      double                                   normalize)
+  {
+    g_return_val_if_fail ((end - start) > 0, vector<double>());
+
+    vector<double> result (start->size());
+
+    for (vector< vector<double> >::const_iterator spect_it = start; spect_it != end; spect_it++)
+      {
+	g_return_val_if_fail (spect_it->size() == result.size(), result);
+
+	for (size_t i = 0; i < result.size(); i++)
+	  result[i] += (*spect_it)[i];
+      }
+    for (size_t i = 0; i < result.size(); i++)
+      result[i] /= normalize;
+
+    return result;
+  }
+
   void
   compute (const Signal& signal)
   {
@@ -379,11 +404,35 @@
 	    spectrum.push_back (collapse_frequency_vector (fvector, signal.mix_freq(), 50, 1.6));
 	  }
       }
+
+    if (options.join_spectrum_slices > 1)
+      {
+	typedef vector< vector<double> >::const_iterator SpectrumConstIterator;
+	const guint jslices = options.join_spectrum_slices; 
+
+	/* for N-fold joining, we "truncate" the spectrum so that we only
+	 * have complete sets of N 30ms spectrum buckets to join
+	 */
+	for (size_t i = 0; i + jslices <= spectrum.size(); i += jslices)
+	  {
+	    SpectrumConstIterator jstart_it = spectrum.begin();
+	    SpectrumConstIterator jend_it = spectrum.begin() + jslices;
+	    joined_spectrum.push_back (join_slices (jstart_it, jend_it, jslices));
+	  }
+      }
   }
 
   void print_results() const
   {
-    print_matrix ("spectrum", spectrum);
+    if (options.join_spectrum_slices > 1)
+      {
+	fprintf (options.output_file,
+	         "# this spectrum was computed with --join-spectrum-slices=%d\n",
+	         options.join_spectrum_slices);
+	print_matrix ("spectrum", joined_spectrum);
+      }
+    else
+      print_matrix ("spectrum", spectrum);
   }
 };
 
@@ -966,7 +1015,8 @@
 };
 
 
-Options::Options ()
+Options::Options () :
+  join_spectrum_slices (1)
 {
   program_name = "bsefextract";
   channel = 0;
@@ -991,6 +1041,18 @@
     }
 }
 
+void
+Options::validate_int (const string& option, int value, int vmin, int vmax)
+{
+  if (value < vmin || value > vmax)
+    {
+      fprintf (stderr, "%s: invalid argument `%d' for `%s'\n\n", program_name.c_str(), value, option.c_str());
+      fprintf (stderr, "Valid arguments are between %d and %d.\n", vmin, vmax);
+      fprintf (stderr, "Try `%s --help' for more information.\n", program_name.c_str());
+      exit (1);
+    }
+}
+
 static bool
 check_arg (uint         argc,
            char        *argv[],
@@ -1109,11 +1171,16 @@
       else if (check_arg (argc, argv, &i, "--focus-width", &opt_arg))
         validate_percent ("--focus-width", focus_width = g_ascii_strtod (opt_arg, NULL));
       else if (check_arg (argc, argv, &i, "--focus-center", &opt_arg))
-        validate_percent ("--focus-center", focus_center = g_ascii_strtod (opt_arg, NULL));
+	validate_percent ("--focus-center", focus_center = g_ascii_strtod (opt_arg, NULL));
       else if (check_arg (argc, argv, &i, "--base-freq-hint", &opt_arg))
-        base_freq_hint = g_ascii_strtod (opt_arg, NULL);
+	base_freq_hint = g_ascii_strtod (opt_arg, NULL);
       else if (check_arg (argc, argv, &i, "--channel", &opt_arg))
-        channel = atoi (opt_arg);
+	channel = atoi (opt_arg);
+      else if (check_arg (argc, argv, &i, "--join-spectrum-slices", &opt_arg))
+	{
+	  join_spectrum_slices = atoi (opt_arg);
+	  validate_int ("--join-spectrum-slices", join_spectrum_slices, 1, 100000);
+	}
       else
         for (list<Feature*>::const_iterator fi = feature_list.begin(); fi != feature_list.end(); fi++)
           if (check_arg (argc, argv, &i, (*fi)->option))
@@ -1155,6 +1222,7 @@
   fprintf (stderr, " --focus-center=X            center focus region around X%% [50]\n");
   fprintf (stderr, " --focus-width=Y             width of focus region in %% [100]\n");
   fprintf (stderr, " --base-freq-hint            expected base frequency (for the pitch detection)\n");
+  fprintf (stderr, " --join-spectrum-slices=N    when extracting a spectrum, join N 30ms slices\n");
   fprintf (stderr, " -o <output_file>            set the name of a file to write the features to\n");
   fprintf (stderr, "\n");
   fprintf (stderr, "(example: %s --start-time --end-time t.wav).\n", options.program_name.c_str());




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