beast r4462 - in trunk: . tools



Author: stw
Date: Sun Apr 27 17:41:47 2008
New Revision: 4462
URL: http://svn.gnome.org/viewvc/beast?rev=4462&view=rev

Log:
2008-04-27 18:39:56  Stefan Westerfeld  <stefan space twc de>

	* tools/bsewavetool.cc: Added chunk selection options (like
	--chunk-key) to upsampling and downsampling commands.


Modified:
   trunk/ChangeLog
   trunk/tools/bsewavetool.cc

Modified: trunk/tools/bsewavetool.cc
==============================================================================
--- trunk/tools/bsewavetool.cc	(original)
+++ trunk/tools/bsewavetool.cc	Sun Apr 27 17:41:47 2008
@@ -2579,11 +2579,14 @@
 
 class Upsample2 : public Command {
 private:
-  int precision_bits;
+  vector<gfloat> m_freq_list;
+  bool           m_all_chunks;
+  int            m_precision_bits;
 public:
   Upsample2 (const char *command_name) :
     Command (command_name),
-    precision_bits (24)
+    m_all_chunks (false),
+    m_precision_bits (24)
   {
   }
   void
@@ -2593,21 +2596,31 @@
     if (bshort)
       return;
     g_print ("    Resample wave data to twice the sampling frequency.\n");
-    g_print ("    --precision <bits>      set resampler precision bits [%d]\n", precision_bits);
+    g_print ("    --precision <bits>      set resampler precision bits [%d]\n", m_precision_bits);
     g_print ("                            supported precisions: 1, 8, 12, 16, 20, 24\n");
     g_print ("                            1 is a special value for linear interpolation\n");
+    g_print ("    -f <osc-freq>           oscillator frequency to select a wave chunk\n");
+    g_print ("    -m <midi-note>          alternative way to specify oscillator frequency\n");
+    g_print ("    --chunk-key <key>       select wave chunk using chunk key from list-chunks\n");
+    g_print ("    --all-chunks            upsample all chunks\n");
     /*       "**********1*********2*********3*********4*********5*********6*********7*********" */
   }
   guint
   parse_args (guint  argc,
               char **argv)
   {
+    bool seen_selection = false;
+
     for (guint i = 1; i < argc; i++)
       {
 	const gchar *str = NULL;
-	if (parse_str_option (argv, i, "--precision", &str, argc))
-	  precision_bits = atoi (str);
+	if (parse_chunk_selection (argv, i, argc, m_all_chunks, m_freq_list))
+          seen_selection = true;
+	else if (parse_str_option (argv, i, "--precision", &str, argc))
+	  m_precision_bits = atoi (str);
       }
+    if (!seen_selection) /* default to all chunks */
+      m_all_chunks = true;
     return 0; // no missing args
   }
   bool
@@ -2616,36 +2629,40 @@
     /* get the wave into storage order */
     wave->sort();
     for (list<WaveChunk>::iterator it = wave->chunks.begin(); it != wave->chunks.end(); it++)
-      {
-        WaveChunk *chunk = &*it;
-        GslDataHandle *dhandle = chunk->dhandle;
-	sfi_info ("UPSAMPLE2: chunk %f: mix_freq=%f -> mix_freq=%f",
-		  gsl_data_handle_osc_freq (chunk->dhandle),
-		  gsl_data_handle_mix_freq (chunk->dhandle),
-		  gsl_data_handle_mix_freq (chunk->dhandle) * 2);
-	sfi_info ("  using resampler precision: %s\n",
-	          bse_resampler2_precision_name (bse_resampler2_find_precision_for_bits (precision_bits)));
-
-        BseErrorType error = chunk->change_dhandle (bse_data_handle_new_upsample2 (dhandle, precision_bits), 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);
-          }
-      }
+      if (m_all_chunks || wave->match (*it, m_freq_list))
+        {
+          WaveChunk *chunk = &*it;
+          GslDataHandle *dhandle = chunk->dhandle;
+          sfi_info ("UPSAMPLE2: chunk %f: mix_freq=%f -> mix_freq=%f",
+                    gsl_data_handle_osc_freq (chunk->dhandle),
+                    gsl_data_handle_mix_freq (chunk->dhandle),
+                    gsl_data_handle_mix_freq (chunk->dhandle) * 2);
+          sfi_info ("  using resampler precision: %s\n",
+                    bse_resampler2_precision_name (bse_resampler2_find_precision_for_bits (m_precision_bits)));
+
+          BseErrorType error = chunk->change_dhandle (bse_data_handle_new_upsample2 (dhandle, m_precision_bits), 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);
+            }
+        }
     return true;
   }
 } cmd_upsample2 ("upsample2");
 
 class Downsample2 : public Command {
 private:
-  int precision_bits;
+  vector<gfloat> m_freq_list;
+  bool           m_all_chunks;
+  int            m_precision_bits;
 public:
   Downsample2 (const char *command_name) :
     Command (command_name),
-    precision_bits (24)
+    m_all_chunks (false),
+    m_precision_bits (24)
   {
   }
   void
@@ -2655,21 +2672,31 @@
     if (bshort)
       return;
     g_print ("    Resample wave data to half the sampling frequency.\n");
-    g_print ("    --precision <bits>      set resampler precision bits [%d]\n", precision_bits);
+    g_print ("    --precision <bits>      set resampler precision bits [%d]\n", m_precision_bits);
     g_print ("                            supported precisions: 1, 8, 12, 16, 20, 24\n");
     g_print ("                            1 is a special value for linear interpolation\n");
-    /*       "**********1*********2*********3*********4*********5*********6*********7*********" */
+    g_print ("    -f <osc-freq>           oscillator frequency to select a wave chunk\n");
+    g_print ("    -m <midi-note>          alternative way to specify oscillator frequency\n");
+    g_print ("    --chunk-key <key>       select wave chunk using chunk key from list-chunks\n");
+    g_print ("    --all-chunks            downsample all chunks\n");
+     /*       "**********1*********2*********3*********4*********5*********6*********7*********" */
   }
   guint
   parse_args (guint  argc,
               char **argv)
   {
+    bool seen_selection = false;
+
     for (guint i = 1; i < argc; i++)
       {
 	const gchar *str = NULL;
-	if (parse_str_option (argv, i, "--precision", &str, argc))
-	  precision_bits = atoi (str);
+	if (parse_chunk_selection (argv, i, argc, m_all_chunks, m_freq_list))
+          seen_selection = true;
+	else if (parse_str_option (argv, i, "--precision", &str, argc))
+	  m_precision_bits = atoi (str);
       }
+    if (!seen_selection) /* default to all chunks */
+      m_all_chunks = true;
     return 0; // no missing args
   }
   bool
@@ -2678,25 +2705,26 @@
     /* get the wave into storage order */
     wave->sort();
     for (list<WaveChunk>::iterator it = wave->chunks.begin(); it != wave->chunks.end(); it++)
-      {
-        WaveChunk *chunk = &*it;
-        GslDataHandle *dhandle = chunk->dhandle;
-	sfi_info ("DOWNSAMPLE2: chunk %f: mix_freq=%f -> mix_freq=%f",
-		  gsl_data_handle_osc_freq (chunk->dhandle),
-		  gsl_data_handle_mix_freq (chunk->dhandle),
-		  gsl_data_handle_mix_freq (chunk->dhandle) / 2);
-	sfi_info ("  using resampler precision: %s\n",
-	          bse_resampler2_precision_name (bse_resampler2_find_precision_for_bits (precision_bits)));
-
-        BseErrorType error = chunk->change_dhandle (bse_data_handle_new_downsample2 (dhandle, 24), 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);
-          }
-      }
+      if (m_all_chunks || wave->match (*it, m_freq_list))
+        {
+          WaveChunk *chunk = &*it;
+          GslDataHandle *dhandle = chunk->dhandle;
+          sfi_info ("DOWNSAMPLE2: chunk %f: mix_freq=%f -> mix_freq=%f",
+                    gsl_data_handle_osc_freq (chunk->dhandle),
+                    gsl_data_handle_mix_freq (chunk->dhandle),
+                    gsl_data_handle_mix_freq (chunk->dhandle) / 2);
+          sfi_info ("  using resampler precision: %s\n",
+                    bse_resampler2_precision_name (bse_resampler2_find_precision_for_bits (m_precision_bits)));
+
+          BseErrorType error = chunk->change_dhandle (bse_data_handle_new_downsample2 (dhandle, 24), 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);
+            }
+        }
     return true;
   }
 } cmd_downsample2 ("downsample2");



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