[aimc] r302 committed - Simple integration test between CARFAC and SAI....

1 view
Skip to first unread message

ai...@googlecode.com

unread,
Jun 26, 2013, 7:35:57 PM6/26/13
to aimc...@googlegroups.com
Revision: 302
Author: ro...@google.com
Date: Wed Jun 26 16:35:47 2013
Log: Simple integration test between CARFAC and SAI.

The interface between the two classes is pretty clunky because of the
way CARFACOutput stores things. We should work on this, probably by
rotating the outer two dimensions of CARFACOutput (i.e. store outputs
in containers with sizes n_ears x n_samples x n_channels instead of
n_samples x n_ears x n_channels).


http://code.google.com/p/aimc/source/detail?r=302

Modified:
/trunk/carfac/carfac.h
/trunk/carfac/sai_test.cc

=======================================
--- /trunk/carfac/carfac.h Wed Jun 12 12:24:29 2013
+++ /trunk/carfac/carfac.h Wed Jun 26 16:35:47 2013
@@ -66,6 +66,8 @@
void RunSegment(const std::vector<std::vector<float>>& sound_data,
const int32_t start, const int32_t length,
const bool open_loop, CARFACOutput* seg_output);
+
+ int num_channels() const { return num_channels_; }

private:
void DesignCARCoeffs(const CARParams& car_params, const FPType
sample_rate,
=======================================
--- /trunk/carfac/sai_test.cc Tue Jun 11 15:05:10 2013
+++ /trunk/carfac/sai_test.cc Wed Jun 26 16:35:47 2013
@@ -22,8 +22,17 @@
#include <iostream>
#include <vector>

+#include <Eigen/Core>
+
#include "gtest/gtest.h"

+#include "agc.h"
+#include "car.h"
+#include "carfac.h"
+#include "carfac_output.h"
+#include "common.h"
+#include "ihc.h"
+
using testing::Values;
using std::vector;

@@ -34,6 +43,25 @@
}
return segment;
}
+
+void PrintSAIInput(const vector<ArrayX>& input) {
+ for (int i = 0; i < input[0].size(); ++i) {
+ for (int j = 0; j < input.size(); ++j) {
+ std::cout << input[j](i) << " ";
+ }
+ std::cout << "\n";
+ }
+}
+
+void PrintSAIFrame(const ArrayXX& sai_frame) {
+ for (int i = 0; i < sai_frame.rows(); ++i) {
+ for (int j = 0; j < sai_frame.cols(); ++j) {
+ std::cout << sai_frame(i, j) << " ";
+ }
+ std::cout << "\n";
+ }
+ std::cout << "\n";
+}

bool HasPeakAt(const ArrayX& frame, int index) {
if (index == 0) {
@@ -89,22 +117,49 @@
}

std::cout << "Input:\n";
- for (int i = 0; i < n_ch_; ++i) {
- for (int j = 0; j < segment.size(); ++j) {
- std::cout << segment[j](i) << " ";
- }
- std::cout << "\n";
- }
-
+ PrintSAIInput(segment);
std::cout << "Output:\n";
- for (int i = 0; i < sai_frame.rows(); ++i) {
- for (int j = 0; j < sai_frame.cols(); ++j) {
- std::cout << sai_frame(i, j) << " ";
- }
- std::cout << "\n";
- }
- std::cout << "\n";
+ PrintSAIFrame(sai_frame);
}
INSTANTIATE_TEST_CASE_P(PeriodicInputVariations, SAIPeriodicInputTest,
testing::Combine(Values(25, 10, 5, 2), // periods.
Values(1, 2, 15))); // n_ch.
+
+TEST(SAITest, CARFACIntegration) {
+ const int n_ears = 1;
+ const int length = 300;
+ vector<vector<float>> segment(n_ears, vector<float>(length, 0.0));
+
+ // Sinusoid input.
+ const float kFrequency = 10;
+ Eigen::Map<Eigen::ArrayXf> segment_array(&segment[0][0],
segment[0].size());
+ segment_array.setLinSpaced(length, 0.0, 2 * kFrequency * kPi);
+ segment_array.sin();
+
+ CARParams car_params;
+ IHCParams ihc_params;
+ AGCParams agc_params;
+ CARFAC carfac(n_ears, 800, car_params, ihc_params, agc_params);
+ CARFACOutput output(true, false, false, false);
+ const bool kOpenLoop = false;
+ carfac.RunSegment(segment, 0, length, kOpenLoop, &output);
+
+ vector<ArrayX> nap_segment;
+ nap_segment.reserve(output.nap().size());
+ for (const vector<ArrayX>& frame : output.nap()) {
+ nap_segment.push_back(frame[0]);
+ }
+
+ SAIParams sai_params;
+ sai_params.window_width = length;
+ sai_params.n_ch = carfac.num_channels();
+ sai_params.width = 20;
+ // Half of the SAI should come from the future.
+ sai_params.future_lags = sai_params.width / 2;
+ sai_params.n_window_pos = 2;
+ SAI sai(sai_params);
+ ArrayXX sai_frame;
+ sai.RunSegment(nap_segment, &sai_frame);
+
+ // TODO(ronw): Test something about the output.
+}
Reply all
Reply to author
Forward
0 new messages