diff --git a/samplebrain/interface/samplebrain.ui b/samplebrain/interface/samplebrain.ui
index 23734f0..6177bbb 100644
--- a/samplebrain/interface/samplebrain.ui
+++ b/samplebrain/interface/samplebrain.ui
@@ -214,6 +214,25 @@
+ -
+
+
+
+ 0
+ 0
+
+
+
+ invert
+
+
+
+ 16
+ 16
+
+
+
+
-
@@ -1441,6 +1460,22 @@
+
+ checkBoxInvert
+ toggled(bool)
+ MainWindow
+ invert_slot(bool)
+
+
+ 189
+ 313
+
+
+ 361
+ 306
+
+
+
play_slot()
@@ -1486,5 +1521,6 @@
stop_record()
n_ratio_slot(int)
n_ratio_slot(double)
+ invert_slot(bool)
diff --git a/samplebrain/qt/MainWindow.h b/samplebrain/qt/MainWindow.h
index a5c48d3..80a9279 100644
--- a/samplebrain/qt/MainWindow.h
+++ b/samplebrain/qt/MainWindow.h
@@ -49,6 +49,11 @@ private slots:
void fft2_start_slot(int s){} // { m_renderer->get_params()->m_fft2_start=s; }
void fft2_end_slot(int s){} // { m_renderer->get_params()->m_fft2_end=s; }
void volume_slot(int s) { lo_send(m_audio_address,"/volume","f",s/100.0f); }
+ void invert_slot(bool s) { if (s) {
+ lo_send(m_audio_address,"/invert","i",1);
+ } else {
+ lo_send(m_audio_address,"/invert","i",0);
+ }}
void run_slot() {}
void load_target() {
m_last_file=QFileDialog::getOpenFileName(
diff --git a/samplebrain/qt/audio_thread.cpp b/samplebrain/qt/audio_thread.cpp
index b3ade9e..6bfdc06 100644
--- a/samplebrain/qt/audio_thread.cpp
+++ b/samplebrain/qt/audio_thread.cpp
@@ -88,6 +88,9 @@ void audio_thread::process(sample &s, sample &s2) {
if (name=="/volume") {
m_renderer->set_volume(cmd.get_float(0)*10);
}
+ if (name=="/invert") {
+ m_renderer->set_invert(cmd.get_int(0));
+ }
if (name=="/record") {
m_renderer->set_playing(true);
m_audio_device->start_recording(cmd.get_string(0));
diff --git a/samplebrain/qt/generated/ui_samplebrain.h b/samplebrain/qt/generated/ui_samplebrain.h
index a31be08..97480fb 100644
--- a/samplebrain/qt/generated/ui_samplebrain.h
+++ b/samplebrain/qt/generated/ui_samplebrain.h
@@ -1,19 +1,20 @@
/********************************************************************************
-** Form generated from reading UI file 'samplebrainB32443.ui'
+** Form generated from reading UI file 'samplebrainm32443.ui'
**
-** Created: Tue Jul 21 15:50:16 2015
+** Created: Tue Jul 21 22:01:28 2015
** by: Qt User Interface Compiler version 4.8.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
-#ifndef SAMPLEBRAINB32443_H
-#define SAMPLEBRAINB32443_H
+#ifndef SAMPLEBRAINM32443_H
+#define SAMPLEBRAINM32443_H
#include
#include
#include
#include
+#include
#include
#include
#include
@@ -59,6 +60,7 @@ public:
QSpinBox *spinBoxFFT1Start;
QLabel *label_10;
QSpinBox *spinBoxFFT1End;
+ QCheckBox *checkBoxInvert;
QSpacerItem *verticalSpacer_3;
QVBoxLayout *verticalLayout_6;
QLabel *label_16;
@@ -264,6 +266,13 @@ public:
verticalLayout_3->addLayout(horizontalLayout_3);
+ checkBoxInvert = new QCheckBox(controlTab);
+ checkBoxInvert->setObjectName(QString::fromUtf8("checkBoxInvert"));
+ checkBoxInvert->setSizeIncrement(QSize(0, 0));
+ checkBoxInvert->setIconSize(QSize(16, 16));
+
+ verticalLayout_3->addWidget(checkBoxInvert);
+
verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_3->addItem(verticalSpacer_3);
@@ -676,6 +685,7 @@ public:
QObject::connect(sliderRatio, SIGNAL(valueChanged(int)), MainWindow, SLOT(ratio_slot(int)));
QObject::connect(sliderNRatio, SIGNAL(valueChanged(int)), MainWindow, SLOT(n_ratio_slot(int)));
QObject::connect(doubleSpinBoxNRatio, SIGNAL(valueChanged(double)), MainWindow, SLOT(n_ratio_slot(double)));
+ QObject::connect(checkBoxInvert, SIGNAL(toggled(bool)), MainWindow, SLOT(invert_slot(bool)));
tabWidget->setCurrentIndex(0);
@@ -692,6 +702,7 @@ public:
label_7->setText(QApplication::translate("MainWindow", "fft subsection", 0, QApplication::UnicodeUTF8));
label_9->setText(QApplication::translate("MainWindow", "Start", 0, QApplication::UnicodeUTF8));
label_10->setText(QApplication::translate("MainWindow", "End", 0, QApplication::UnicodeUTF8));
+ checkBoxInvert->setText(QApplication::translate("MainWindow", "invert", 0, QApplication::UnicodeUTF8));
label_16->setText(QApplication::translate("MainWindow", "target sound", 0, QApplication::UnicodeUTF8));
pushButtonLoadTarget->setText(QApplication::translate("MainWindow", "load target", 0, QApplication::UnicodeUTF8));
label_17->setText(QApplication::translate("MainWindow", "block size", 0, QApplication::UnicodeUTF8));
@@ -743,4 +754,4 @@ namespace Ui {
QT_END_NAMESPACE
-#endif // SAMPLEBRAINB32443_H
+#endif // SAMPLEBRAINM32443_H
diff --git a/samplebrain/src/brain.cpp b/samplebrain/src/brain.cpp
index f667f1b..0decb19 100644
--- a/samplebrain/src/brain.cpp
+++ b/samplebrain/src/brain.cpp
@@ -16,6 +16,7 @@
#include
#include
+#include
#include
#include "brain.h"
@@ -83,7 +84,7 @@ const block &brain::get_block(u32 index) const {
// returns index to block
u32 brain::search(const block &target, const search_params ¶ms) const {
- double closest = 999999999;
+ double closest = FLT_MAX;
u32 closest_index = 0;
u32 index = 0;
for (vector::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
@@ -97,6 +98,22 @@ u32 brain::search(const block &target, const search_params ¶ms) const {
return closest_index;
}
+// returns index to block
+u32 brain::rev_search(const block &target, const search_params ¶ms) const {
+ double furthest = 0;
+ u32 furthest_index = 0;
+ u32 index = 0;
+ for (vector::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
+ double diff = target.compare(*i,params);
+ if (diff>furthest) {
+ furthest=diff;
+ furthest_index = index;
+ }
+ ++index;
+ }
+ return furthest_index;
+}
+
// take another brain and rebuild this brain from bits of that one
// (presumably this one is made from a single sample)
void brain::resynth(const string &filename, const brain &other, const search_params ¶ms){
diff --git a/samplebrain/src/brain.h b/samplebrain/src/brain.h
index c183f12..9933eb7 100644
--- a/samplebrain/src/brain.h
+++ b/samplebrain/src/brain.h
@@ -60,6 +60,7 @@ public:
u32 get_overlap() const { return m_overlap; }
u32 search(const block &target, const search_params ¶ms) const;
+ u32 rev_search(const block &target, const search_params ¶ms) const;
static bool unit_test();
diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp
index 2ee5e10..8d5d8e1 100644
--- a/samplebrain/src/renderer.cpp
+++ b/samplebrain/src/renderer.cpp
@@ -54,7 +54,12 @@ void renderer::process(u32 nframes, float *buf) {
// get indices for current buffer
for (u32 tgt_index = tgt_start; tgt_index<=tgt_end; tgt_index++) {
u32 time=tgt_index*tgt_shift;
- u32 src_index = m_source.search(m_target.get_block(tgt_index), m_search_params);
+ u32 src_index;
+ if (!m_invert) {
+ src_index = m_source.search(m_target.get_block(tgt_index), m_search_params);
+ } else {
+ src_index = m_source.rev_search(m_target.get_block(tgt_index), m_search_params);
+ }
// put them in the index list
m_render_blocks.push_back(render_block(src_index,time));
}
diff --git a/samplebrain/src/renderer.h b/samplebrain/src/renderer.h
index d340969..b28295c 100644
--- a/samplebrain/src/renderer.h
+++ b/samplebrain/src/renderer.h
@@ -36,6 +36,7 @@ renderer(brain &source, brain &target) :
void set_playing(bool s) { m_playing=s; }
void set_volume(float s) { m_volume=s; }
+ void set_invert(bool s) { m_invert=s; }
search_params *get_params() { return &m_search_params; }
static bool unit_test();
@@ -58,7 +59,7 @@ private:
search_params m_search_params;
float m_volume;
bool m_playing;
-
+ bool m_invert;
std::list m_render_blocks;
u32 m_render_time;
};