summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt18
-rw-r--r--setup.py8
-rw-r--r--simpl/peak_detection.pxd6
-rw-r--r--simpl/peak_detection.pyx12
-rw-r--r--src/simpl/peak_detection.cpp62
-rw-r--r--src/simpl/peak_detection.h25
6 files changed, 122 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 97767ba..938cc0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,24 +5,28 @@ FILE(GLOB simpl_src src/simpl/*.cpp)
FILE(GLOB sms_src src/sms/*.c)
FILE(GLOB sndobj_src src/sndobj/*.cpp)
FILE(GLOB loris_src src/loris/*.C)
+FILE(GLOB mq_src src/mq/*.cpp)
LIST(APPEND source_files ${simpl_src}
${sndobj_src}
${sms_src}
- ${loris_src})
+ ${loris_src}
+ ${mq_src})
FILE(GLOB simpl_include src/simpl/*.h)
set(sms_include src/sms/sms.h)
FILE(GLOB sndobj_include src/sndobj/*.h)
FILE(GLOB loris_include src/loris/*.h)
+FILE(GLOB mq_include src/mq/*.h)
LIST(APPEND include_files ${simpl_include}
${sms_include}
${sndobj_include}
- ${loris_include})
+ ${loris_include}
+ ${mq_include})
add_definitions(-DHAVE_FFTW3_H)
set(libs m fftw3 gsl gslcblas)
-include_directories(src/simpl src/sms src/sndobj src/sndobj/rfftw src/loris)
+include_directories(src/simpl src/sms src/sndobj src/loris src/mq)
add_library(simpl SHARED ${source_files})
target_link_libraries(simpl ${libs})
@@ -36,8 +40,10 @@ install(FILES ${include_files} DESTINATION include/simpl)
# ----------------------------------------------------------------------------
if(BUILD_TESTS)
set(test_base_src ${source_files} tests/test_base.cpp)
- set(test_peak_detection_src ${source_files} tests/test_peak_detection.cpp)
- set(test_partial_tracking_src ${source_files} tests/test_partial_tracking.cpp)
+ set(test_peak_detection_src ${source_files}
+ tests/test_peak_detection.cpp)
+ set(test_partial_tracking_src ${source_files}
+ tests/test_partial_tracking.cpp)
set(test_synthesis_src ${source_files} tests/test_synthesis.cpp)
LIST(APPEND libs cppunit sndfile)
@@ -52,5 +58,5 @@ if(BUILD_TESTS)
target_link_libraries(test_partial_tracking ${libs})
target_link_libraries(test_synthesis ${libs})
else()
- message("-- Not building tests. To change run CMake with -D BUILD_TESTS=yes")
+ message("Not building tests. To change run CMake with -D BUILD_TESTS=yes")
endif()
diff --git a/setup.py b/setup.py
index b49f943..a3ea28e 100644
--- a/setup.py
+++ b/setup.py
@@ -35,7 +35,7 @@ except ImportError:
macros = []
link_args = []
include_dirs = ['simpl', 'src/simpl', 'src/sms', 'src/sndobj',
- 'src/loris', numpy_include, '/usr/local/include']
+ 'src/loris', 'src/mq', numpy_include, '/usr/local/include']
libs = ['m', 'fftw3', 'gsl', 'gslcblas']
sources = []
@@ -69,6 +69,12 @@ loris_sources = glob.glob(os.path.join('src', 'loris', '*.C'))
sources.extend(loris_sources)
# -----------------------------------------------------------------------------
+# MQ
+# -----------------------------------------------------------------------------
+mq_sources = glob.glob(os.path.join('src', 'mq', '*.cpp'))
+sources.extend(mq_sources)
+
+# -----------------------------------------------------------------------------
# Base
# -----------------------------------------------------------------------------
base = Extension(
diff --git a/simpl/peak_detection.pxd b/simpl/peak_detection.pxd
index da3a5cf..aeed77d 100644
--- a/simpl/peak_detection.pxd
+++ b/simpl/peak_detection.pxd
@@ -37,6 +37,12 @@ cdef extern from "../src/simpl/peak_detection.h" namespace "simpl":
vector[c_Peak*] find_peaks_in_frame(c_Frame* frame)
vector[c_Frame*] find_peaks(int audio_size, double* audio)
+ cdef cppclass c_MQPeakDetection "simpl::MQPeakDetection"(c_PeakDetection):
+ c_MQPeakDetection()
+ void hop_size(int new_hop_size)
+ void max_peaks(int new_max_peaks)
+ vector[c_Peak*] find_peaks_in_frame(c_Frame* frame)
+
cdef cppclass c_SMSPeakDetection "simpl::SMSPeakDetection"(c_PeakDetection):
c_SMSPeakDetection()
void hop_size(int new_hop_size)
diff --git a/simpl/peak_detection.pyx b/simpl/peak_detection.pyx
index cd143bf..66d5a1a 100644
--- a/simpl/peak_detection.pyx
+++ b/simpl/peak_detection.pyx
@@ -101,6 +101,18 @@ cdef class PeakDetection:
return self.frames
+cdef class MQPeakDetection(PeakDetection):
+ def __cinit__(self):
+ if self.thisptr:
+ del self.thisptr
+ self.thisptr = new c_MQPeakDetection()
+
+ def __dealloc__(self):
+ if self.thisptr:
+ del self.thisptr
+ self.thisptr = <c_PeakDetection*>0
+
+
cdef class SMSPeakDetection(PeakDetection):
def __cinit__(self):
if self.thisptr:
diff --git a/src/simpl/peak_detection.cpp b/src/simpl/peak_detection.cpp
index a8b68f8..b0d4829 100644
--- a/src/simpl/peak_detection.cpp
+++ b/src/simpl/peak_detection.cpp
@@ -166,6 +166,68 @@ Frames PeakDetection::find_peaks(int audio_size, sample* audio) {
// ---------------------------------------------------------------------------
+// MQPeakDetection
+// ---------------------------------------------------------------------------
+MQPeakDetection::MQPeakDetection() {
+ _mq_params.max_peaks = _max_peaks;
+ _mq_params.frame_size = _frame_size;
+ _mq_params.num_bins = (_frame_size / 2) + 1;
+ _mq_params.peak_threshold = 0.0;
+ _mq_params.matching_interval = 100.0;
+ _mq_params.fundamental = 44100.0 / _frame_size;
+ init_mq(&_mq_params);
+}
+
+MQPeakDetection::~MQPeakDetection() {
+ destroy_mq(&_mq_params);
+}
+
+void MQPeakDetection::reset() {
+ reset_mq(&_mq_params);
+ destroy_mq(&_mq_params);
+ _mq_params.max_peaks = _max_peaks;
+ _mq_params.frame_size = _frame_size;
+ _mq_params.num_bins = (_frame_size / 2) + 1;
+ _mq_params.fundamental = 44100.0 / _frame_size;
+ init_mq(&_mq_params);
+}
+
+void MQPeakDetection::frame_size(int new_frame_size) {
+ _frame_size = new_frame_size;
+ reset();
+}
+
+void MQPeakDetection::hop_size(int new_hop_size) {
+ _hop_size = new_hop_size;
+}
+
+void MQPeakDetection::max_peaks(int new_max_peaks) {
+ _max_peaks = new_max_peaks;
+ reset();
+}
+
+Peaks MQPeakDetection::find_peaks_in_frame(Frame* frame) {
+ Peaks peaks;
+
+ MQPeakList* pl = mq_find_peaks(_frame_size, frame->audio(), &_mq_params);
+
+ int num_peaks = 0;
+ while(pl && pl->peak && num_peaks < _max_peaks) {
+ Peak* p = new Peak();
+ p->amplitude = pl->peak->amplitude;
+ p->frequency = pl->peak->frequency;
+ p->phase = pl->peak->phase;
+ peaks.push_back(p);
+ frame->add_peak(p);
+
+ pl = pl->next;
+ num_peaks++;
+ }
+
+ return peaks;
+}
+
+// ---------------------------------------------------------------------------
// SMSPeakDetection
// ---------------------------------------------------------------------------
SMSPeakDetection::SMSPeakDetection() {
diff --git a/src/simpl/peak_detection.h b/src/simpl/peak_detection.h
index 9a35b52..983340a 100644
--- a/src/simpl/peak_detection.h
+++ b/src/simpl/peak_detection.h
@@ -3,6 +3,8 @@
#include "base.h"
+#include "mq.h"
+
extern "C" {
#include "sms.h"
}
@@ -76,13 +78,32 @@ class PeakDetection {
virtual Peaks find_peaks_in_frame(Frame* frame);
// Find and return all spectral peaks in a given audio signal.
- // If the signal contains more than 1 frame worth of audio, it will be broken
- // up into separate frames, with an array of peaks returned for each frame.
+ // If the signal contains more than 1 frame worth of audio, it will be
+ // broken up into separate frames, with an array of peaks returned for
+ // each frame
virtual Frames find_peaks(int audio_size, sample* audio);
};
// ---------------------------------------------------------------------------
+// MQPeakDetection
+// ---------------------------------------------------------------------------
+class MQPeakDetection : public PeakDetection {
+ private:
+ MQParameters _mq_params;
+ void reset();
+
+ public:
+ MQPeakDetection();
+ ~MQPeakDetection();
+ void frame_size(int new_frame_size);
+ void hop_size(int new_hop_size);
+ void max_peaks(int new_max_peaks);
+ Peaks find_peaks_in_frame(Frame* frame);
+};
+
+
+// ---------------------------------------------------------------------------
// SMSPeakDetection
// ---------------------------------------------------------------------------
class SMSPeakDetection : public PeakDetection {