diff --git a/samplebrain/qt/MainWindow.cpp b/samplebrain/qt/MainWindow.cpp index 4a8e9fe..ac60257 100644 --- a/samplebrain/qt/MainWindow.cpp +++ b/samplebrain/qt/MainWindow.cpp @@ -37,6 +37,6 @@ void MainWindow::init_brain() { //target.resynth_listen("shosta-dream-0.5.wav",source,0.5,a); - m_renderer = new renderer(m_source,m_target,1); + m_renderer = new renderer(m_source,m_target); } diff --git a/samplebrain/qt/MainWindow.h b/samplebrain/qt/MainWindow.h index edb0ac2..537c442 100644 --- a/samplebrain/qt/MainWindow.h +++ b/samplebrain/qt/MainWindow.h @@ -20,15 +20,15 @@ protected: private slots: - void play_slot() {} - void stop_slot() {} - void ratio_slot(int s) { m_renderer->set_ratio(s/100.0f); } - void ratio_slot(double) {} - void fft1_start_slot(int) {} - void fft1_end_slot(int) {} - void fft2_start_slot(int) {} - void fft2_end_slot(int) {} - void volume_slot(int) {} + void play_slot() { m_renderer->set_playing(true); } + void stop_slot() { m_renderer->set_playing(false); } + void ratio_slot(int s) { m_renderer->get_params()->m_ratio=s/100.0f; } + void ratio_slot(double s) { m_renderer->get_params()->m_ratio=s/100.0f; } + void fft1_start_slot(int s) { m_renderer->get_params()->m_fft1_start=s; } + void fft1_end_slot(int s) { m_renderer->get_params()->m_fft1_end=s; } + 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) { m_renderer->set_volume(s/50.0f); } void run_slot() {} void load_target() {} void target_block_size(int) {} diff --git a/samplebrain/qt/generated/.#ui_samplebrain.h b/samplebrain/qt/generated/.#ui_samplebrain.h deleted file mode 120000 index aaa8380..0000000 --- a/samplebrain/qt/generated/.#ui_samplebrain.h +++ /dev/null @@ -1 +0,0 @@ -dave@fulmar.5193:1436562455 \ No newline at end of file diff --git a/samplebrain/qt/generated/ui_samplebrain.h b/samplebrain/qt/generated/ui_samplebrain.h index 52aa0d8..aec1ed1 100644 --- a/samplebrain/qt/generated/ui_samplebrain.h +++ b/samplebrain/qt/generated/ui_samplebrain.h @@ -1,14 +1,14 @@ /******************************************************************************** -** Form generated from reading UI file 'samplebrainYv5241.ui' +** Form generated from reading UI file 'samplebrainxS5241.ui' ** -** Created: Sat Jul 11 10:34:17 2015 +** Created: Sat Jul 11 12:25:49 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 SAMPLEBRAINYV5241_H -#define SAMPLEBRAINYV5241_H +#ifndef SAMPLEBRAINXS5241_H +#define SAMPLEBRAINXS5241_H #include #include @@ -22,12 +22,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include @@ -47,6 +45,7 @@ public: QPushButton *pushButtonPlay; QPushButton *pushButtonStop; QVBoxLayout *verticalLayout_3; + QHBoxLayout *horizontalLayout_16; QLabel *label_6; QDial *dialRatio; QDoubleSpinBox *doubleSpinBoxRatio; @@ -66,10 +65,10 @@ public: QHBoxLayout *horizontalLayout_11; QLabel *label_12; QSpinBox *spinBoxFFT2End; + QSpacerItem *verticalSpacer_3; QVBoxLayout *verticalLayout_6; QLabel *label_13; - QSlider *verticalSliderVolume; - QSpacerItem *verticalSpacer_3; + QDial *dialVolume; QVBoxLayout *verticalLayout_9; QLabel *label_16; QLabel *label_15; @@ -82,10 +81,6 @@ public: QSpinBox *spinBoxBlockOverlapTarget; QPushButton *pushButtonGenerateTarget; QSpacerItem *verticalSpacer; - QVBoxLayout *verticalLayout_8; - QLabel *label_14; - QTextEdit *textEdit; - QPushButton *pushButtonRun; QWidget *sampleTab; QHBoxLayout *horizontalLayout_8; QVBoxLayout *verticalLayout_2; @@ -115,7 +110,7 @@ public: { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QString::fromUtf8("MainWindow")); - MainWindow->resize(800, 603); + MainWindow->resize(724, 603); centralwidget = new QWidget(MainWindow); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); horizontalLayout = new QHBoxLayout(centralwidget); @@ -163,17 +158,33 @@ public: verticalLayout_3 = new QVBoxLayout(); verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); + horizontalLayout_16 = new QHBoxLayout(); + horizontalLayout_16->setObjectName(QString::fromUtf8("horizontalLayout_16")); label_6 = new QLabel(controlTab); label_6->setObjectName(QString::fromUtf8("label_6")); - label_6->setFont(font1); + QFont font2; + font2.setFamily(QString::fromUtf8("Comic Sans MS")); + font2.setPointSize(14); + font2.setBold(true); + font2.setWeight(75); + label_6->setFont(font2); - verticalLayout_3->addWidget(label_6); + horizontalLayout_16->addWidget(label_6); dialRatio = new QDial(controlTab); dialRatio->setObjectName(QString::fromUtf8("dialRatio")); dialRatio->setEnabled(true); + QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(dialRatio->sizePolicy().hasHeightForWidth()); + dialRatio->setSizePolicy(sizePolicy); + dialRatio->setMinimumSize(QSize(60, 60)); - verticalLayout_3->addWidget(dialRatio); + horizontalLayout_16->addWidget(dialRatio); + + + verticalLayout_3->addLayout(horizontalLayout_16); doubleSpinBoxRatio = new QDoubleSpinBox(controlTab); doubleSpinBoxRatio->setObjectName(QString::fromUtf8("doubleSpinBoxRatio")); @@ -184,7 +195,7 @@ public: verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); label_7 = new QLabel(controlTab); label_7->setObjectName(QString::fromUtf8("label_7")); - label_7->setFont(font1); + label_7->setFont(font2); verticalLayout_4->addWidget(label_7); @@ -227,7 +238,7 @@ public: verticalLayout_5->setObjectName(QString::fromUtf8("verticalLayout_5")); label_8 = new QLabel(controlTab); label_8->setObjectName(QString::fromUtf8("label_8")); - label_8->setFont(font1); + label_8->setFont(font2); verticalLayout_5->addWidget(label_8); @@ -269,6 +280,10 @@ public: verticalLayout_7->addLayout(verticalLayout_3); + verticalSpacer_3 = new QSpacerItem(323, 511, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout_7->addItem(verticalSpacer_3); + verticalLayout_6 = new QVBoxLayout(); verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); label_13 = new QLabel(controlTab); @@ -277,19 +292,15 @@ public: verticalLayout_6->addWidget(label_13); - verticalSliderVolume = new QSlider(controlTab); - verticalSliderVolume->setObjectName(QString::fromUtf8("verticalSliderVolume")); - verticalSliderVolume->setOrientation(Qt::Vertical); + dialVolume = new QDial(controlTab); + dialVolume->setObjectName(QString::fromUtf8("dialVolume")); + dialVolume->setValue(99); - verticalLayout_6->addWidget(verticalSliderVolume); + verticalLayout_6->addWidget(dialVolume); verticalLayout_7->addLayout(verticalLayout_6); - verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - - verticalLayout_7->addItem(verticalSpacer_3); - horizontalLayout_15->addLayout(verticalLayout_7); @@ -358,28 +369,6 @@ public: horizontalLayout_15->addLayout(verticalLayout_9); - verticalLayout_8 = new QVBoxLayout(); - verticalLayout_8->setObjectName(QString::fromUtf8("verticalLayout_8")); - label_14 = new QLabel(controlTab); - label_14->setObjectName(QString::fromUtf8("label_14")); - label_14->setFont(font); - - verticalLayout_8->addWidget(label_14); - - textEdit = new QTextEdit(controlTab); - textEdit->setObjectName(QString::fromUtf8("textEdit")); - - verticalLayout_8->addWidget(textEdit); - - pushButtonRun = new QPushButton(controlTab); - pushButtonRun->setObjectName(QString::fromUtf8("pushButtonRun")); - pushButtonRun->setFont(font1); - - verticalLayout_8->addWidget(pushButtonRun); - - - horizontalLayout_15->addLayout(verticalLayout_8); - tabWidget->addTab(controlTab, QString()); sampleTab = new QWidget(); sampleTab->setObjectName(QString::fromUtf8("sampleTab")); @@ -516,8 +505,6 @@ public: QObject::connect(spinBoxFFT1End, SIGNAL(valueChanged(int)), MainWindow, SLOT(fft1_end_slot(int))); QObject::connect(spinBoxFFT2Start, SIGNAL(valueChanged(int)), MainWindow, SLOT(fft2_start_slot(int))); QObject::connect(spinBoxFFT2End, SIGNAL(valueChanged(int)), MainWindow, SLOT(fft2_end_slot(int))); - QObject::connect(verticalSliderVolume, SIGNAL(sliderMoved(int)), MainWindow, SLOT(volume_slot(int))); - QObject::connect(pushButtonRun, SIGNAL(released()), MainWindow, SLOT(run_slot())); QObject::connect(pushButtonLoadTarget, SIGNAL(released()), MainWindow, SLOT(load_target())); QObject::connect(spinBoxBlockSizeTarget, SIGNAL(valueChanged(int)), MainWindow, SLOT(target_block_size(int))); QObject::connect(spinBoxBlockOverlapTarget, SIGNAL(valueChanged(int)), MainWindow, SLOT(target_block_overlap(int))); @@ -527,8 +514,9 @@ public: QObject::connect(spinBoxSpectSize, SIGNAL(valueChanged(int)), MainWindow, SLOT(fft_spectrum_size(int))); QObject::connect(pushButtonGenerate, SIGNAL(released()), MainWindow, SLOT(generate())); QObject::connect(pushButtonLoadSound, SIGNAL(released()), MainWindow, SLOT(load_sound())); + QObject::connect(dialVolume, SIGNAL(sliderMoved(int)), MainWindow, SLOT(volume_slot(int))); - tabWidget->setCurrentIndex(1); + tabWidget->setCurrentIndex(0); QMetaObject::connectSlotsByName(MainWindow); @@ -549,13 +537,11 @@ public: label_12->setText(QApplication::translate("MainWindow", "End", 0, QApplication::UnicodeUTF8)); label_13->setText(QApplication::translate("MainWindow", "Volume", 0, QApplication::UnicodeUTF8)); label_16->setText(QApplication::translate("MainWindow", "target sound", 0, QApplication::UnicodeUTF8)); - label_15->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8)); + label_15->setText(QApplication::translate("MainWindow", "no sound yet...", 0, QApplication::UnicodeUTF8)); pushButtonLoadTarget->setText(QApplication::translate("MainWindow", "load target", 0, QApplication::UnicodeUTF8)); label_17->setText(QApplication::translate("MainWindow", "block size", 0, QApplication::UnicodeUTF8)); label_18->setText(QApplication::translate("MainWindow", "block overlap", 0, QApplication::UnicodeUTF8)); pushButtonGenerateTarget->setText(QApplication::translate("MainWindow", "generate blocks", 0, QApplication::UnicodeUTF8)); - label_14->setText(QApplication::translate("MainWindow", "livecode brain", 0, QApplication::UnicodeUTF8)); - pushButtonRun->setText(QApplication::translate("MainWindow", "run", 0, QApplication::UnicodeUTF8)); tabWidget->setTabText(tabWidget->indexOf(controlTab), QApplication::translate("MainWindow", "search", 0, QApplication::UnicodeUTF8)); label_3->setText(QApplication::translate("MainWindow", "brain parameters", 0, QApplication::UnicodeUTF8)); label->setText(QApplication::translate("MainWindow", "block size", 0, QApplication::UnicodeUTF8)); @@ -577,4 +563,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // SAMPLEBRAINYV5241_H +#endif // SAMPLEBRAINXS5241_H diff --git a/samplebrain/src/block.cpp b/samplebrain/src/block.cpp index b983065..75721b5 100644 --- a/samplebrain/src/block.cpp +++ b/samplebrain/src/block.cpp @@ -68,7 +68,7 @@ void block::init_fft(u32 block_size) #define FFT_BIAS 200 -double block::compare(const block &other, float ratio, int fftwack) const { +double block::compare(const block &other, const search_params ¶ms) const { double mfcc_acc=0; double fft_acc=0; @@ -77,17 +77,17 @@ double block::compare(const block &other, float ratio, int fftwack) const { if (fft_start<0) fft_start=0; if (fft_end>m_fft.get_length()) fft_end=m_fft.get_length(); */ - s32 fft_start = 0; - s32 fft_end = m_fft.get_length(); + s32 fft_start = params.m_fft1_start; + s32 fft_end = fmin(params.m_fft1_end,m_fft.get_length()); - if (ratio==0) { + if (params.m_ratio==0) { for (u32 i=fft_start; i::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) { - double diff = target.compare(*i,ratio,fftwack); + double diff = target.compare(*i,params); if (diff::iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) { cerr<<'\r'; cerr<<"searching: "<m_client.set_callback(run_audio, &rr); diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp index c63a2a8..bac5b5a 100644 --- a/samplebrain/src/renderer.cpp +++ b/samplebrain/src/renderer.cpp @@ -4,27 +4,23 @@ using namespace spiralcore; using namespace std; -void renderer::init(brain &source, brain &target, float ratio) { +void renderer::init(brain &source, brain &target) { m_source=source; m_target=target; m_render_time=0; m_render_blocks.clear(); - m_ratio = ratio; } static int ratio_time = 0; void renderer::process(u32 nframes, float *buf) { + if (!m_playing) return; + // get blocks from source for the current buffer u32 tgt_shift = m_target.get_block_size()-m_target.get_overlap(); u32 tgt_start = m_render_time/(float)tgt_shift; u32 tgt_end = (m_render_time+nframes)/(float)tgt_shift; - cerr<<'\r'; - cerr<=m_target.get_num_blocks()) { m_render_time=0; @@ -40,7 +36,7 @@ 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_ratio, fftwack); + u32 src_index = m_source.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)); } @@ -72,7 +68,7 @@ void renderer::process(u32 nframes, float *buf) { u32 block_pos = block_start; u32 block_end = pcm.get_length(); while (block_pos m_render_blocks; u32 m_render_time;