summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-10-24 17:32:18 +0200
committerJohn Glover <j@johnglover.net>2012-10-24 17:32:18 +0200
commited811c93657b9cdc20c8203966881de5141fe5c4 (patch)
treeba4fb65586b33f42ddc257354c8868d0470e0379 /src
parent1023eb542bb7b43fb49fdfbff59c88e75b81415f (diff)
downloadsimpl-ed811c93657b9cdc20c8203966881de5141fe5c4.tar.gz
simpl-ed811c93657b9cdc20c8203966881de5141fe5c4.tar.bz2
simpl-ed811c93657b9cdc20c8203966881de5141fe5c4.zip
[mq] Add MQPeakDetection C++ class.
Diffstat (limited to 'src')
-rw-r--r--src/simpl/peak_detection.cpp62
-rw-r--r--src/simpl/peak_detection.h25
2 files changed, 85 insertions, 2 deletions
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 {