diff carfac/carfac_test.cc @ 654:a1b82b240328

Rename variables to be consistent with the rest of the library.
author ronw@google.com
date Thu, 27 Jun 2013 15:30:46 +0000
parents aaa4f60ebf9c
children 263a05be98c4
line wrap: on
line diff
--- a/carfac/carfac_test.cc	Wed Jun 26 23:35:47 2013 +0000
+++ b/carfac/carfac_test.cc	Thu Jun 27 15:30:46 2013 +0000
@@ -68,8 +68,8 @@
 // Reads a size rows vector of size columns Container objects from a
 // multi-column text file generated by the Matlab version of CARFAC.
 template <typename Container = ArrayX, bool ColMajor = true>
-vector<Container> Load2dTestData(const string& filename, const int rows,
-                                 const int columns) {
+vector<Container> Load2dTestData(const string& filename, int rows,
+                                 int columns) {
   string fullfile = kTestSourceDir + filename;
   ifstream file(fullfile.c_str());
   vector<Container> output;
@@ -96,19 +96,22 @@
 // Reads a two dimensional vector of audio data from a text file
 // containing the output of the Matlab wavread() function.
 vector<vector<float>> Load2dAudioVector(string filename, int timepoints,
-                                        int channels) {
-  return Load2dTestData<vector<float>, false>(filename, timepoints, channels);
+                                        int num_channels) {
+  return Load2dTestData<vector<float>, false>(filename, timepoints,
+                                              num_channels);
 }
 
 class CARFACTest : public testing::Test {
  protected:
-  deque<vector<ArrayX>> LoadTestData(
-      const string& basename, int n_timepoints, int n_ears, int n_ch) const {
-    deque<vector<ArrayX>> test_data(n_timepoints, vector<ArrayX>(n_ears));
-    for (int ear = 0; ear < n_ears; ++ear) {
+  deque<vector<ArrayX>> LoadTestData(const string& basename,
+                                     int num_samples,
+                                     int num_ears,
+                                     int num_channels) const {
+    deque<vector<ArrayX>> test_data(num_samples, vector<ArrayX>(num_ears));
+    for (int ear = 0; ear < num_ears; ++ear) {
       string filename = basename + std::to_string(ear + 1) + ".txt";
-      vector<ArrayX> data = Load2dTestData(filename, n_timepoints, n_ch);
-      for (int i = 0; i < n_timepoints; ++i) {
+      vector<ArrayX> data = Load2dTestData(filename, num_samples, num_channels);
+      for (int i = 0; i < num_samples; ++i) {
         test_data[i][ear] = data[i];
       }
     }
@@ -117,10 +120,12 @@
 
   void AssertCARFACOutputNear(const deque<vector<ArrayX>>& expected,
                               const deque<vector<ArrayX>>& actual,
-                              int n_timepoints, int n_ears, int n_ch) const {
-    for (int timepoint = 0; timepoint < n_timepoints; ++timepoint) {
-      for (int ear = 0; ear < n_ears; ++ear) {
-        for (int channel = 0; channel < n_ch; ++channel) {
+                              int num_samples,
+                              int num_ears,
+                              int num_channels) const {
+    for (int timepoint = 0; timepoint < num_samples; ++timepoint) {
+      for (int ear = 0; ear < num_ears; ++ear) {
+        for (int channel = 0; channel < num_channels; ++channel) {
           const float kPrecisionLevel = 1.0e-7;
           ASSERT_NEAR(expected[timepoint][ear](channel),
                       actual[timepoint][ear](channel),
@@ -136,12 +141,12 @@
 };
 
 TEST_F(CARFACTest, BinauralData) {
-  const int n_timepoints = 882;
-  const int n_ears = 2;
-  const int n_ch = 71;
+  const int kNumSamples = 882;
+  const int kNumEars = 2;
+  const int kNumChannels = 71;
   vector<vector<float>> sound_data =
-      Load2dAudioVector("file_signal_binaural_test.txt", n_timepoints, n_ears);
-  CARFAC carfac(n_ears, 22050, car_params_, ihc_params_, agc_params_);
+      Load2dAudioVector("file_signal_binaural_test.txt", kNumSamples, kNumEars);
+  CARFAC carfac(kNumEars, 22050, car_params_, ihc_params_, agc_params_);
   CARFACOutput output(true, true, false, false);
   const bool kOpenLoop = false;
   const int length = sound_data[0].size();
@@ -153,22 +158,22 @@
   WriteNAPOutput(output, "cpp_nap_output_2_binaural_test.txt", 1);
 
   deque<vector<ArrayX>> expected_nap =
-      LoadTestData("binaural_test_nap", n_timepoints, n_ears, n_ch);
+      LoadTestData("binaural_test_nap", kNumSamples, kNumEars, kNumChannels);
   AssertCARFACOutputNear(expected_nap, output.nap(),
-                         n_timepoints, n_ears, n_ch);
+                         kNumSamples, kNumEars, kNumChannels);
   deque<vector<ArrayX>> expected_bm =
-      LoadTestData("binaural_test_bm", n_timepoints, n_ears, n_ch);
+      LoadTestData("binaural_test_bm", kNumSamples, kNumEars, kNumChannels);
   AssertCARFACOutputNear(expected_bm, output.bm(),
-                         n_timepoints, n_ears, n_ch);
+                         kNumSamples, kNumEars, kNumChannels);
 }
 
 TEST_F(CARFACTest, LongBinauralData) {
-  const int n_timepoints = 2000;
-  const int n_ears = 2;
-  const int n_ch = 83;
+  const int kNumSamples = 2000;
+  const int kNumEars = 2;
+  const int kNumChannels = 83;
   vector<vector<float>> sound_data =
-      Load2dAudioVector("file_signal_long_test.txt", n_timepoints, n_ears);
-  CARFAC carfac(n_ears, 44100, car_params_, ihc_params_, agc_params_);
+      Load2dAudioVector("file_signal_long_test.txt", kNumSamples, kNumEars);
+  CARFAC carfac(kNumEars, 44100, car_params_, ihc_params_, agc_params_);
   CARFACOutput output(true, true, false, false);
   const bool kOpenLoop = false;
   const int length = sound_data[0].size();
@@ -180,11 +185,11 @@
   WriteNAPOutput(output, "cpp_nap_output_2_long_test.txt", 1);
 
   deque<vector<ArrayX>> expected_nap =
-      LoadTestData("long_test_nap", n_timepoints, n_ears, n_ch);
+      LoadTestData("long_test_nap", kNumSamples, kNumEars, kNumChannels);
   AssertCARFACOutputNear(expected_nap, output.nap(),
-                         n_timepoints, n_ears, n_ch);
+                         kNumSamples, kNumEars, kNumChannels);
   deque<vector<ArrayX>> expected_bm =
-      LoadTestData("long_test_bm", n_timepoints, n_ears, n_ch);
+      LoadTestData("long_test_bm", kNumSamples, kNumEars, kNumChannels);
   AssertCARFACOutputNear(expected_bm, output.bm(),
-                         n_timepoints, n_ears, n_ch);
+                         kNumSamples, kNumEars, kNumChannels);
 }