diff branches/carfac_cpp/src/CARFAC.cpp @ 564:9c4c3675c3f8

* Added class Ear, and moved the CARFAC members AGC CAR IHC into Ear. CARFAC now holds an array of Ear. TBD what is best. * Moved the files around, and introduced a makefile that builds unittests using GTest. (Note, GTest path is configured in makefile atm.). - two moronic tests implemented. :)
author Ulf.Hammarqvist@gmail.com
date Sun, 20 May 2012 22:36:47 +0000
parents 0fde611fcd10
children f3dde307f4b8
line wrap: on
line diff
--- a/branches/carfac_cpp/src/CARFAC.cpp	Sat May 12 04:31:59 2012 +0000
+++ b/branches/carfac_cpp/src/CARFAC.cpp	Sun May 20 22:36:47 2012 +0000
@@ -4,18 +4,17 @@
 #include "CAR.h"
 #include "IHC.h"
 #include "AGC.h"
+#include "Ear.h"
 
 #include "CARFAC_common.h"
 
 CARFAC::CARFAC(int fs = kDefaultFs,
               CAR_parameters* car_params = new CAR_parameters(),
               IHC_parameters* ihc_params = new IHC_parameters(),
-              AGC_parameters* agc_params = new AGC_parameters()) : n_ears_(0) {
+              AGC_parameters* agc_params = new AGC_parameters(),
+              int n_ears = 1){
 
-  // Design is to take ownership. Preferences? Make copies, call by value, etc?
-  car_params_ = car_params;
-  ihc_params_ = ihc_params;
-  agc_params_ = agc_params;
+  fs_ = fs;
 
   float pole_hz = car_params->first_pole_theta_* fs / (2*kPi);
   while (pole_hz > car_params->min_pole_hz_){
@@ -25,14 +24,11 @@
                     car_params->erb_q_);
   }
   n_ch_ = pole_freqs_.size();
-
   max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]);
 
-  //TODO: pass const references?
-  car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_);
-  ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_);
-  agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_);
-
+  n_ears_ = n_ears;
+  Ear* ear = new Ear(car_params, ihc_params, agc_params, pole_freqs_, n_ch_, fs);
+  ears_.assign(n_ears_, *ear);
 }
 
 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
@@ -40,14 +36,5 @@
 }
 
 CARFAC::~CARFAC() {
-  delete car_coeffs_;
-  delete ihc_coeffs_;
-  delete agc_coeffs_;
-
-  //TODO: as the current design takes ownership OR creates news params,
-  //deletion is a ambiguos. Revise this design?
-
-  //delete car_params_;
-  //delete ihc_params_;
-  //delete agc_params_;
+  //TODO: clean up
 }