changeset 246:0a3342606855

- Allow processing without re-initialization.
author tom@acousticscale.org
date Tue, 26 Oct 2010 04:48:56 +0000
parents cf4ebaf2f845
children 4039da654583
files experiments/scripts/cnbh-syllables/feature_generation/ssi_profile_features.aimcopycfg src/Modules/Input/ModuleFileInput.cc src/Modules/SAI/ModuleSAI.cc src/Modules/SSI/ModuleSSI.cc src/Modules/SSI/ModuleSSI.h src/Support/SignalBank.cc src/Support/SignalBank.h
diffstat 7 files changed, 40 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/experiments/scripts/cnbh-syllables/feature_generation/ssi_profile_features.aimcopycfg	Tue Oct 26 04:09:31 2010 +0000
+++ b/experiments/scripts/cnbh-syllables/feature_generation/ssi_profile_features.aimcopycfg	Tue Oct 26 04:48:56 2010 +0000
@@ -48,6 +48,9 @@
 
 module10.name = SAI
 module10.id = weighted_sai
+module10.parameters = <<<ENDPARAMS
+sai.frame_period_ms=20.0
+ENDPARAMS
 module10.child1 = SSINoPitchCutoff
 module10.child2 = SSIPitchCutoff
 
--- a/src/Modules/Input/ModuleFileInput.cc	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Modules/Input/ModuleFileInput.cc	Tue Oct 26 04:48:56 2010 +0000
@@ -52,20 +52,12 @@
 }
 
 void ModuleFileInput::ResetInternal() {
-  // If there's a file open, rewind to the beginning.
-  if (file_handle_ != NULL) {
-    sf_seek(file_handle_, 0, SEEK_SET);
-    file_position_samples_ = 0;
-  }
-}
-
-bool ModuleFileInput::InitializeInternal(const SignalBank& input) {
   // If there's a file open. Close it.
   if (file_handle_ != NULL) {
     sf_close(file_handle_);
     file_handle_ = NULL;
   }
-  // Open the file
+  // Open a file
   SF_INFO sfinfo;
   memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO));
 
@@ -79,7 +71,7 @@
      */
     LOG_ERROR(_T("Couldn't read audio file '%s'"),
               global_parameters_->GetString("input_filename"));
-    return false;
+    return;
   }
   
   file_loaded_ = true;
@@ -90,12 +82,15 @@
 
   if (audio_channels_ < 1 || buffer_length_ < 1 || sample_rate_ < 0.0f) {
     LOG_ERROR(_T("Problem with file: audio_channels = %d, buffer_length_ = %d, sample_rate = %f"), audio_channels_, buffer_length_, sample_rate_);
-    return false;
+    return;
   }
 
   output_.Initialize(audio_channels_, buffer_length_, sample_rate_);
   output_.set_start_time(0);
-  
+}
+
+bool ModuleFileInput::InitializeInternal(const SignalBank& input) {
+  ResetInternal();
   return true;
 }
 
--- a/src/Modules/SAI/ModuleSAI.cc	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Modules/SAI/ModuleSAI.cc	Tue Oct 26 04:48:56 2010 +0000
@@ -107,6 +107,8 @@
 
 void ModuleSAI::ResetInternal() {
   // Active Strobes
+  output_.Clear();
+  sai_temp_.Clear();
   active_strobes_.clear();
   active_strobes_.resize(channel_count_);
   fire_counter_ = frame_period_samples_ - 1;
--- a/src/Modules/SSI/ModuleSSI.cc	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Modules/SSI/ModuleSSI.cc	Tue Oct 26 04:48:56 2010 +0000
@@ -103,6 +103,21 @@
     output_.set_centre_frequency(i, input.centre_frequency(i));
   }
   
+  h_.resize(ssi_width_samples_, 0.0);
+  float gamma_min = -1.0f;
+  float gamma_max = log2(ssi_width_cycles_);
+  for (int i = 0; i < ssi_width_samples_; ++i) {
+    if (log_cycles_axis_) {
+      float gamma = gamma_min + (gamma_max - gamma_min)
+                                 * static_cast<float>(i)
+                                 / static_cast<float>(ssi_width_samples_);
+      h_[i]= pow(2.0f, gamma);
+    } else {
+      h_[i] = static_cast<float>(i) * ssi_width_cycles_
+              / static_cast<float>(ssi_width_samples_);
+    }
+  }
+  
   output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_);
   return true;
 }
@@ -157,9 +172,6 @@
   if (do_pitch_cutoff_) {
     pitch_index = ExtractPitchIndex(input);
   }
-  
-  float gamma_min = -1.0f;
-  float gamma_max = log2(ssi_width_cycles_);
 
   for (int ch = 0; ch < channel_count_; ++ch) {
     float centre_frequency = input.centre_frequency(ch);
@@ -186,30 +198,20 @@
     
     // Copy the buffer from input to output, addressing by h-value.
     for (int i = 0; i < ssi_width_samples_; ++i) {
-      float h;
-      if (log_cycles_axis_) {
-        float gamma = gamma_min + (gamma_max - gamma_min)
-                                   * static_cast<float>(i)
-                                   / static_cast<float>(ssi_width_samples_);
-        h = pow(2.0f, gamma);
-      } else {
-        h = static_cast<float>(i) * ssi_width_cycles_
-            / static_cast<float>(ssi_width_samples_);
-      }
-
+      
       // The index into the input array is a floating-point number, which is
       // split into a whole part and a fractional part. The whole part and
       // fractional part are found, and are used to linearly interpolate
       // between input samples to yield an output sample.
       double whole_part;
-      float frac_part = modf(h * cycle_samples, &whole_part);
+      float frac_part = modf(h_[i] * cycle_samples, &whole_part);
       int sample = floor(whole_part);
 
       float weight = channel_weight;
       
       if (do_smooth_offset_ && do_pitch_cutoff_) {
         // Smoothing around the pitch cutoff line.
-        float pitch_weight = (1.0f + tanh((pitch_h - h)
+        float pitch_weight = (1.0f + tanh((pitch_h - h_[i])
                                           * smooth_pitch_constant)) / 2.0f;
         weight *= pitch_weight;
         //LOG_INFO("Channel %d, Sample %d. Pitch weight: %f", ch, i, pitch_weight);
--- a/src/Modules/SSI/ModuleSSI.h	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Modules/SSI/ModuleSSI.h	Tue Oct 26 04:48:56 2010 +0000
@@ -24,6 +24,7 @@
 #ifndef AIMC_MODULES_SSI_SSI_H_
 #define AIMC_MODULES_SSI_SSI_H_
 
+#include <vector>
 #include "Support/Module.h"
 
 namespace aimc {
@@ -56,6 +57,7 @@
   int ssi_width_samples_;
   float ssi_width_cycles_;
   float pivot_cf_;
+  vector<float> h_;
 
   bool do_pitch_cutoff_;
   bool weight_by_cutoff_;
--- a/src/Support/SignalBank.cc	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Support/SignalBank.cc	Tue Oct 26 04:48:56 2010 +0000
@@ -94,6 +94,13 @@
   return true;
 }
 
+void SignalBank::Clear() {
+  for (int i = 0; i < channel_count_; ++i) {
+    signals_[i].assign(buffer_length_, 0.0f);
+    strobes_[i].resize(0);
+  }
+}
+
 bool SignalBank::Validate() const {
   if (sample_rate_ <= 0.0f)
     return false;
--- a/src/Support/SignalBank.h	Tue Oct 26 04:09:31 2010 +0000
+++ b/src/Support/SignalBank.h	Tue Oct 26 04:48:56 2010 +0000
@@ -99,6 +99,7 @@
   void set_centre_frequency(int i, float cf);
   bool initialized() const;
   int channel_count() const;
+  void Clear();
  private:
   int channel_count_;
   int buffer_length_;