summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sndobj/SinAnal.cpp14
-rw-r--r--tests/test_partial_tracking.cpp129
-rw-r--r--tests/test_partial_tracking.h26
-rw-r--r--tests/tests.cpp1
4 files changed, 165 insertions, 5 deletions
diff --git a/src/sndobj/SinAnal.cpp b/src/sndobj/SinAnal.cpp
index d8e53cf..d6a07a2 100644
--- a/src/sndobj/SinAnal.cpp
+++ b/src/sndobj/SinAnal.cpp
@@ -112,8 +112,10 @@ SinAnal::SinAnal(SndObj* input, double threshold, int maxtracks,
AddMsg("max tracks", 21);
AddMsg("threshold", 22);
- for(i = 0; i < m_maxtracks; i++)
- m_pkmags[m_prev][i] = m_bndx[m_prev][i] = m_adthresh[m_prev][i] = 0.f;
+ for(i = 0; i < m_maxtracks; i++) {
+ m_pkmags[0][i] = m_bndx[0][i] = m_adthresh[0][i] = 0.f;
+ m_pkmags[1][i] = m_bndx[1][i] = m_adthresh[1][i] = 0.f;
+ }
}
SinAnal::SinAnal(SndObj* input, int numbins, double threshold, int maxtracks,
@@ -184,8 +186,10 @@ SinAnal::SinAnal(SndObj* input, int numbins, double threshold, int maxtracks,
AddMsg("max tracks", 21);
AddMsg("threshold", 22);
- for(i = 0; i < m_maxtracks; i++)
- m_pkmags[m_prev][i] = m_bndx[m_prev][i] = m_adthresh[m_prev][i] = 0.f;
+ for(i = 0; i < m_maxtracks; i++) {
+ m_pkmags[0][i] = m_bndx[0][i] = m_adthresh[0][i] = 0.f;
+ m_pkmags[1][i] = m_bndx[1][i] = m_adthresh[1][i] = 0.f;
+ }
}
SinAnal::~SinAnal(){
@@ -483,7 +487,7 @@ SinAnal::PartialTracking(){
// loop to the end of tracks (indicate by the 0'd bins)
// find continuation tracks
- for(j=0; m_bndx[m_prev][j] != 0.f && j < m_maxtracks; j++){
+ for(j=0; j < m_maxtracks && m_bndx[m_prev][j] != 0.f; j++){
int foundcont = 0;
if(m_numpeaks > 0){ // check for peaks; m_numpeaks will be > 0
diff --git a/tests/test_partial_tracking.cpp b/tests/test_partial_tracking.cpp
index 31e0473..0c835fd 100644
--- a/tests/test_partial_tracking.cpp
+++ b/tests/test_partial_tracking.cpp
@@ -204,6 +204,135 @@ void TestSMSPartialTracking::test_streaming() {
// ---------------------------------------------------------------------------
+// TestSndObjPartialTracking
+// ---------------------------------------------------------------------------
+void TestSndObjPartialTracking::setUp() {
+ _sf = SndfileHandle(TEST_AUDIO_FILE);
+
+ if(_sf.error() > 0) {
+ throw Exception(std::string("Could not open audio file: ") +
+ std::string(TEST_AUDIO_FILE));
+ }
+
+ _pt.max_partials(5);
+}
+
+void TestSndObjPartialTracking::test_basic() {
+ int hop_size = 256;
+ int frame_size = 2048;
+ int num_samples = 4096;
+
+ _pd.clear();
+ _pt.reset();
+
+ _pd.hop_size(hop_size);
+ _pd.frame_size(frame_size);
+
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
+
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ frames = _pt.find_partials(frames);
+
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+ }
+}
+
+void TestSndObjPartialTracking::test_change_num_partials() {
+ int hop_size = 256;
+ int frame_size = 2048;
+ int num_samples = 4096;
+ int max_partials = 10;
+
+ _pd.clear();
+ _pt.reset();
+
+ _pd.hop_size(hop_size);
+ _pd.frame_size(frame_size);
+
+ _pd.max_peaks(max_partials);
+ _pt.max_partials(max_partials);
+
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
+
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ frames = _pt.find_partials(frames);
+
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() == max_partials);
+ CPPUNIT_ASSERT(frames[i]->num_partials() == max_partials);
+ }
+}
+
+void TestSndObjPartialTracking::test_peaks() {
+ int num_frames = 8;
+ Frames frames;
+
+ _pd.clear();
+ _pt.reset();
+
+ for(int i = 0; i < num_frames; i++) {
+ Frame* f = new Frame();
+ f->add_peak(0.4, 220, 0, 0);
+ f->add_peak(0.2, 440, 0, 0);
+ frames.push_back(f);
+ }
+
+ _pt.find_partials(frames);
+ for(int i = 1; i < num_frames; i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4, frames[i]->partial(0)->amplitude,
+ PRECISION);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(220, frames[i]->partial(0)->frequency,
+ PRECISION);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, frames[i]->partial(1)->amplitude,
+ PRECISION);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(440, frames[i]->partial(1)->frequency,
+ PRECISION);
+ }
+
+ for(int i = 0; i < num_frames; i++) {
+ delete frames[i];
+ }
+}
+
+void TestSndObjPartialTracking::test_streaming() {
+ int hop_size = 256;
+ int frame_size = 2048;
+ int num_frames = 10;
+ int max_partials = 10;
+
+ _pd.clear();
+ _pt.reset();
+
+ _pd.hop_size(hop_size);
+ _pd.frame_size(frame_size);
+
+ _pd.max_peaks(max_partials);
+ _pt.max_partials(max_partials);
+
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
+
+ for(int i = 0, n = (int)_sf.frames() / 2; i < num_frames; i++, n += hop_size) {
+ Frame f(frame_size, true);
+ f.audio(&(audio[n]), frame_size);
+
+ _pd.find_peaks_in_frame(&f);
+ _pt.update_partials(&f);
+
+ CPPUNIT_ASSERT(f.num_partials() > 0);
+ }
+}
+
+
+// ---------------------------------------------------------------------------
// TestLorisPartialTracking
// ---------------------------------------------------------------------------
void TestLorisPartialTracking::setUp() {
diff --git a/tests/test_partial_tracking.h b/tests/test_partial_tracking.h
index c548984..e5715de 100644
--- a/tests/test_partial_tracking.h
+++ b/tests/test_partial_tracking.h
@@ -58,6 +58,32 @@ protected:
void test_streaming();
};
+
+// ---------------------------------------------------------------------------
+// TestSndObjPartialTracking
+// ---------------------------------------------------------------------------
+class TestSndObjPartialTracking : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestSndObjPartialTracking);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST(test_change_num_partials);
+ CPPUNIT_TEST(test_peaks);
+ CPPUNIT_TEST(test_streaming);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ SndObjPeakDetection _pd;
+ SndObjPartialTracking _pt;
+ SndfileHandle _sf;
+
+ void test_basic();
+ void test_change_num_partials();
+ void test_peaks();
+ void test_streaming();
+};
+
// ---------------------------------------------------------------------------
// TestLorisPartialTracking
// ---------------------------------------------------------------------------
diff --git a/tests/tests.cpp b/tests/tests.cpp
index e52653d..11fbebf 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -15,6 +15,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestTWM);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPartialTracking);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSPartialTracking);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSndObjPartialTracking);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis);
CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis);