From 92f8997c1fc8ca245b110db123103b8079f51569 Mon Sep 17 00:00:00 2001 From: Dave Griffiths Date: Mon, 27 Jul 2015 15:36:34 +0100 Subject: [PATCH] lots of gui work, boredom/novelty sliders, started synaptic stuff --- samplebrain/Makefile.in | 1 + samplebrain/configure | 39 ++ samplebrain/configure.ac | 1 + samplebrain/interface/samplebrain.ui | 428 +++++++++++++++++----- samplebrain/qt/MainWindow.cpp | 10 +- samplebrain/qt/MainWindow.h | 75 +++- samplebrain/qt/Makefile | 13 +- samplebrain/qt/audio_thread.cpp | 38 +- samplebrain/qt/generated/ui_samplebrain.h | 206 ++++++++--- samplebrain/qt/process_thread.cpp | 2 +- samplebrain/qt/samplebrain.pro | 1 + samplebrain/src/block.cpp | 33 +- samplebrain/src/block.h | 8 + samplebrain/src/brain.cpp | 103 +++++- samplebrain/src/brain.h | 20 +- samplebrain/src/config.h.in | 3 + samplebrain/src/main.cpp | 38 +- samplebrain/src/renderer.cpp | 61 ++- samplebrain/src/renderer.h | 26 +- samplebrain/src/search_params.h | 9 +- 20 files changed, 890 insertions(+), 225 deletions(-) diff --git a/samplebrain/Makefile.in b/samplebrain/Makefile.in index cb4cdc6..c13d21b 100644 --- a/samplebrain/Makefile.in +++ b/samplebrain/Makefile.in @@ -8,6 +8,7 @@ SRCS := src/fft.cpp \ src/mfcc.cpp \ src/renderer.cpp \ src/window.cpp \ + src/status.cpp \ src/aquila/filter/MelFilterBank.cpp \ src/aquila/filter/MelFilter.cpp \ src/aquila/transform/Dct.cpp \ diff --git a/samplebrain/configure b/samplebrain/configure index 44a323a..05528ce 100755 --- a/samplebrain/configure +++ b/samplebrain/configure @@ -3030,6 +3030,45 @@ _ACEOF fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -llo" >&5 +$as_echo_n "checking for main in -llo... " >&6; } +if ${ac_cv_lib_lo_main+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llo $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ +return main (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_lo_main=yes +else + ac_cv_lib_lo_main=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lo_main" >&5 +$as_echo "$ac_cv_lib_lo_main" >&6; } +if test "x$ac_cv_lib_lo_main" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBLO 1 +_ACEOF + + LIBS="-llo $LIBS" + +fi + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' diff --git a/samplebrain/configure.ac b/samplebrain/configure.ac index 93dfa1a..7e7a448 100644 --- a/samplebrain/configure.ac +++ b/samplebrain/configure.ac @@ -7,6 +7,7 @@ AC_CHECK_LIB(fftw3, main) AC_CHECK_LIB(portaudio, main) AC_CHECK_LIB(jellyfish, main) AC_CHECK_LIB(sndfile, main) +AC_CHECK_LIB(lo, main) AC_PROG_CXX AC_LANG(C++) diff --git a/samplebrain/interface/samplebrain.ui b/samplebrain/interface/samplebrain.ui index 4de2b20..00de903 100644 --- a/samplebrain/interface/samplebrain.ui +++ b/samplebrain/interface/samplebrain.ui @@ -6,12 +6,12 @@ 0 0 - 724 - 613 + 643 + 619 - samplebrain 0.0.4 + samplebrain 0.0.5 @@ -31,7 +31,7 @@ search - + @@ -45,27 +45,27 @@ - search - - - - - - - - Comic Sans MS - 9 - 75 - true - - - - fft <-> mfcc + brain tweaks + + + + + Comic Sans MS + 9 + 75 + true + + + + fft / mfcc + + + @@ -74,6 +74,9 @@ 0 + + plain fft match vs mfcc values + 50 @@ -103,23 +106,23 @@ - - - - - Comic Sans MS - 9 - 75 - true - - - - freq & dynamics <-> freq only - - - + + + + + Comic Sans MS + 9 + 75 + true + + + + freq & dynamics / freq only + + + @@ -128,6 +131,9 @@ 0 + + match original or normalised blocks + 0 @@ -157,25 +163,34 @@ - - - - - Comic Sans MS - 9 - 75 - true - - - - fft subsection - - - + + + + + Comic Sans MS + 9 + 75 + true + + + + + + + fft subsection + + + + + + 0 + 0 + + Comic Sans MS @@ -189,10 +204,20 @@ - + + + start frequency to use for fft match + + + + + 0 + 0 + + Comic Sans MS @@ -207,6 +232,9 @@ + + end frequency to use for fft match + 99 @@ -214,6 +242,126 @@ + + + + + + + Comic Sans MS + 9 + 75 + true + + + + + + + novelty + + + + + + + + 0 + 0 + + + + use new blocks rather than similar ones + + + 0 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.000000000000000 + + + + + + + + + + + + Comic Sans MS + 9 + 75 + true + + + + + + + boredom + + + + + + + + 0 + 0 + + + + how long it takes for the novelty to ware off + + + 0 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.000000000000000 + + + + + @@ -222,6 +370,9 @@ 0 + + + search for least similar @@ -233,6 +384,32 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -248,23 +425,23 @@ - - - - - Comic Sans MS - 9 - 75 - true - - - - dynamic <-> normalised mix - - - + + + + + Comic Sans MS + 9 + 75 + true + + + + dynamic / normalised + + + @@ -273,6 +450,9 @@ 0 + + mix in the normalised blocks + 0 @@ -302,23 +482,23 @@ - - - - - Comic Sans MS - 9 - 75 - true - - - - brain <-> target mix - - - + + + + + Comic Sans MS + 9 + 75 + true + + + + brain / target + + + @@ -327,6 +507,9 @@ 0 + + mix in the original blocks + 0 @@ -359,19 +542,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -992,7 +1162,7 @@ - + @@ -1667,6 +1837,70 @@ + + doubleSpinBoxBoredom + valueChanged(double) + MainWindow + boredom_slot(double) + + + 411 + 253 + + + 321 + 309 + + + + + sliderBoredom + valueChanged(int) + MainWindow + boredom_slot(int) + + + 291 + 253 + + + 321 + 309 + + + + + doubleSpinBoxNovelty + valueChanged(double) + MainWindow + novelty_slot(double) + + + 411 + 217 + + + 321 + 309 + + + + + sliderNovelty + valueChanged(int) + MainWindow + novelty_slot(int) + + + 291 + 217 + + + 321 + 309 + + + play_slot() @@ -1717,5 +1951,9 @@ n_mix_slot(double) target_mix_slot(int) target_mix_slot(double) + novelty_slot(int) + novelty_slot(double) + boredom_slot(int) + boredom_slot(double) diff --git a/samplebrain/qt/MainWindow.cpp b/samplebrain/qt/MainWindow.cpp index de745d9..07736aa 100644 --- a/samplebrain/qt/MainWindow.cpp +++ b/samplebrain/qt/MainWindow.cpp @@ -18,17 +18,25 @@ #include #include "MainWindow.h" +#include "feedback.h" using namespace std; MainWindow::MainWindow() : - m_last_file(".") + m_last_file("."), + m_feedback("8890") { m_Ui.setupUi(this); setUnifiedTitleAndToolBarOnMac(true); m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888"); m_process_address = lo_address_new_from_url("osc.udp://localhost:8889"); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update_status())); + timer->start(1000); + timer->setInterval(500); + m_save_wav=""; m_record_id=0; } diff --git a/samplebrain/qt/MainWindow.h b/samplebrain/qt/MainWindow.h index 0d58cd3..a56bea3 100644 --- a/samplebrain/qt/MainWindow.h +++ b/samplebrain/qt/MainWindow.h @@ -21,6 +21,7 @@ #include #include #include "window.h" +#include "feedback.h" using namespace std; using namespace spiralcore; @@ -40,23 +41,72 @@ private slots: void play_slot() { lo_send(m_audio_address,"/start",""); } void stop_slot() { lo_send(m_audio_address,"/pause",""); } - void ratio_slot(int s) { lo_send(m_audio_address,"/ratio","f",s/100.0f); } - void ratio_slot(double s) { lo_send(m_audio_address,"/ratio","f",s); } - void n_ratio_slot(int s) { lo_send(m_audio_address,"/n_ratio","f",s/100.0f); } - void n_ratio_slot(double s) { lo_send(m_audio_address,"/n_ratio","f",s); } + + void ratio_slot(int s) { + lo_send(m_audio_address,"/ratio","f",s/100.0f); + m_Ui.doubleSpinBoxRatio->setValue(s/100.0f); + } + void ratio_slot(double s) { + lo_send(m_audio_address,"/ratio","f",s); + m_Ui.sliderRatio->setValue(s*100); + } + + void n_ratio_slot(int s) { + lo_send(m_audio_address,"/n_ratio","f",s/100.0f); + m_Ui.doubleSpinBoxNRatio->setValue(s/100.0f); + } + void n_ratio_slot(double s) { + lo_send(m_audio_address,"/n_ratio","f",s); + m_Ui.sliderNRatio->setValue(s*100); + } + void fft1_start_slot(int s) { lo_send(m_audio_address,"/fft1_start","i",s); } void fft1_end_slot(int s) { lo_send(m_audio_address,"/fft1_end","i",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 n_mix_slot(int s) { lo_send(m_audio_address,"/n_mix","f",s/100.0f); } - void n_mix_slot(double s) { lo_send(m_audio_address,"/n_mix","f",s); } - void target_mix_slot(int s) { lo_send(m_audio_address,"/target_mix","f",s/100.0f); } - void target_mix_slot(double s) { lo_send(m_audio_address,"/target_mix","f",s); } + + void n_mix_slot(int s) { + lo_send(m_audio_address,"/n_mix","f",s/100.0f); + m_Ui.doubleSpinBoxNMix->setValue(s/100.0f); + } + void n_mix_slot(double s) { + lo_send(m_audio_address,"/n_mix","f",s); + m_Ui.sliderNMix->setValue(s*100); + } + + void novelty_slot(int s) { + lo_send(m_audio_address,"/novelty","f",s/100.0f); + m_Ui.doubleSpinBoxNovelty->setValue(s/100.0f); + } + void novelty_slot(double s) { + lo_send(m_audio_address,"/novelty","f",s); + m_Ui.sliderNovelty->setValue(s*100); + } + + void boredom_slot(int s) { + float v=s/100.0f; + lo_send(m_audio_address,"/boredom","f",v); + m_Ui.doubleSpinBoxBoredom->setValue(v); + } + void boredom_slot(double s) { + lo_send(m_audio_address,"/boredom","f",s); + m_Ui.sliderBoredom->setValue(s*100); + } + + void target_mix_slot(int s) { + lo_send(m_audio_address,"/target_mix","f",s/100.0f); + m_Ui.doubleSpinBoxTargetMix->setValue(s/100.0f); + } + void target_mix_slot(double s) { + lo_send(m_audio_address,"/target_mix","f",s); + m_Ui.sliderTargetMix->setValue(s*100); + } + 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); + lo_send(m_audio_address,"/search_algo","i",1); } else { - lo_send(m_audio_address,"/invert","i",0); + lo_send(m_audio_address,"/search_algo","i",0); }} void run_slot() {} void load_target() { @@ -146,6 +196,10 @@ private slots: lo_send(m_audio_address,"/stop",""); } + void update_status() { + m_feedback.poll(m_Ui.statusbar); + } + private: string m_save_wav; QString m_last_file; @@ -153,4 +207,5 @@ private: Ui_MainWindow m_Ui; lo_address m_audio_address; lo_address m_process_address; + feedback m_feedback; }; diff --git a/samplebrain/qt/Makefile b/samplebrain/qt/Makefile index 6128d8e..a56d76e 100644 --- a/samplebrain/qt/Makefile +++ b/samplebrain/qt/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: samplebrain -# Generated by qmake (2.01a) (Qt 4.8.1) on: Sun Jul 19 11:22:53 2015 +# Generated by qmake (2.01a) (Qt 4.8.1) on: Mon Jul 27 09:28:27 2015 # Project: samplebrain.pro # Template: app # Command: /usr/bin/qmake -o Makefile samplebrain.pro @@ -46,11 +46,13 @@ OBJECTS_DIR = ./ SOURCES = MainWindow.cpp \ audio_thread.cpp \ process_thread.cpp \ + feedback.cpp \ qtmain.cpp moc_MainWindow.cpp \ qrc_samplebrain.cpp OBJECTS = MainWindow.o \ audio_thread.o \ process_thread.o \ + feedback.o \ qtmain.o \ moc_MainWindow.o \ qrc_samplebrain.o @@ -168,7 +170,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) .tmp/samplebrain1.0.0 || $(MKDIR) .tmp/samplebrain1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents MainWindow.h generated/ui_samplebrain.h .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents samplebrain.qrc .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents MainWindow.cpp audio_thread.cpp process_thread.cpp qtmain.cpp .tmp/samplebrain1.0.0/ && (cd `dirname .tmp/samplebrain1.0.0` && $(TAR) samplebrain1.0.0.tar samplebrain1.0.0 && $(COMPRESS) samplebrain1.0.0.tar) && $(MOVE) `dirname .tmp/samplebrain1.0.0`/samplebrain1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/samplebrain1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents MainWindow.h generated/ui_samplebrain.h .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents samplebrain.qrc .tmp/samplebrain1.0.0/ && $(COPY_FILE) --parents MainWindow.cpp audio_thread.cpp process_thread.cpp feedback.cpp qtmain.cpp .tmp/samplebrain1.0.0/ && (cd `dirname .tmp/samplebrain1.0.0` && $(TAR) samplebrain1.0.0.tar samplebrain1.0.0 && $(COMPRESS) samplebrain1.0.0.tar) && $(MOVE) `dirname .tmp/samplebrain1.0.0`/samplebrain1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/samplebrain1.0.0 clean:compiler_clean @@ -203,6 +205,7 @@ qrc_samplebrain.cpp: samplebrain.qrc \ images/stop.png \ images/play.png \ images/record.png \ + images/at.png \ images/pause.png /usr/bin/rcc -name samplebrain samplebrain.qrc -o qrc_samplebrain.cpp @@ -224,7 +227,8 @@ compiler_clean: compiler_moc_header_clean compiler_rcc_clean ####### Compile MainWindow.o: MainWindow.cpp MainWindow.h \ - generated/ui_samplebrain.h + generated/ui_samplebrain.h \ + feedback.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainWindow.o MainWindow.cpp audio_thread.o: audio_thread.cpp audio_thread.h \ @@ -234,6 +238,9 @@ audio_thread.o: audio_thread.cpp audio_thread.h \ process_thread.o: process_thread.cpp process_thread.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o process_thread.o process_thread.cpp +feedback.o: feedback.cpp feedback.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o feedback.o feedback.cpp + qtmain.o: qtmain.cpp MainWindow.h \ generated/ui_samplebrain.h \ process_thread.h \ diff --git a/samplebrain/qt/audio_thread.cpp b/samplebrain/qt/audio_thread.cpp index c6cd825..a26448e 100644 --- a/samplebrain/qt/audio_thread.cpp +++ b/samplebrain/qt/audio_thread.cpp @@ -33,9 +33,14 @@ audio_thread::audio_thread(process_thread &p) : m_osc.run(); } +static bool state = 1; + audio_thread::~audio_thread() { - delete m_renderer; + state=0; + cerr<<"deleting audio device"<m_audio_device->left_out.zero(); - at->process(at->m_audio_device->left_out, - at->m_audio_device->right_out); - at->m_audio_device->maybe_record(); + if (state) { + audio_thread *at = (audio_thread*)c; + at->m_audio_device->left_out.zero(); + at->process(at->m_audio_device->left_out, + at->m_audio_device->right_out); + at->m_audio_device->maybe_record(); + } } void audio_thread::process(sample &s, sample &s2) { @@ -76,11 +83,8 @@ void audio_thread::process(sample &s, sample &s2) { if (name=="/fft1_end") { m_renderer->get_params()->m_fft1_end = cmd.get_int(0); } - if (name=="/fft2_start") { - m_renderer->get_params()->m_fft2_start = cmd.get_int(0); - } - if (name=="/fft2_end") { - m_renderer->get_params()->m_fft2_end = cmd.get_int(0); + if (name=="/novelty") { + m_renderer->get_params()->m_usage_importance = cmd.get_float(0); } if (name=="/restart_audio") { start_audio(); @@ -88,8 +92,13 @@ 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=="/search_algo") { + switch(cmd.get_int(0)) { + case 0: m_renderer->set_search_algo(renderer::BASIC); break; + case 1: m_renderer->set_search_algo(renderer::REV_BASIC); break; + case 2: m_renderer->set_search_algo(renderer::SYNAPTIC); break; + case 3: m_renderer->set_search_algo(renderer::SYNAPTIC_SLIDE); break; + } } if (name=="/n_mix") { m_renderer->set_n_mix(cmd.get_float(0)); @@ -105,6 +114,9 @@ void audio_thread::process(sample &s, sample &s2) { m_audio_device->stop_recording(); m_renderer->set_playing(false); } + if (name=="/boredom") { + m_renderer->get_source().set_usage_falloff(cmd.get_float(0)); + } } s.zero(); diff --git a/samplebrain/qt/generated/ui_samplebrain.h b/samplebrain/qt/generated/ui_samplebrain.h index 85f5535..d2262ea 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 'samplebrainC26316.ui' +** Form generated from reading UI file 'samplebraing19815.ui' ** -** Created: Wed Jul 22 15:20:00 2015 +** Created: Mon Jul 27 14:41: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 SAMPLEBRAINC26316_H -#define SAMPLEBRAINC26316_H +#ifndef SAMPLEBRAING19815_H +#define SAMPLEBRAING19815_H #include #include @@ -43,34 +43,43 @@ public: QVBoxLayout *verticalLayout_4; QTabWidget *tabWidget; QWidget *controlTab; - QHBoxLayout *horizontalLayout_10; + QHBoxLayout *horizontalLayout_17; QVBoxLayout *verticalLayout_3; QLabel *label_19; - QLabel *label_6; QHBoxLayout *horizontalLayout_16; + QLabel *label_6; QSlider *sliderRatio; QDoubleSpinBox *doubleSpinBoxRatio; - QLabel *label_20; QHBoxLayout *horizontalLayout; + QLabel *label_20; QSlider *sliderNRatio; QDoubleSpinBox *doubleSpinBoxNRatio; - QLabel *label_7; QHBoxLayout *horizontalLayout_3; + QLabel *label_7; QLabel *label_9; QSpinBox *spinBoxFFT1Start; QLabel *label_10; QSpinBox *spinBoxFFT1End; + QHBoxLayout *horizontalLayout_10; + QLabel *label_24; + QSlider *sliderNovelty; + QDoubleSpinBox *doubleSpinBoxNovelty; + QHBoxLayout *horizontalLayout_11; + QLabel *label_25; + QSlider *sliderBoredom; + QDoubleSpinBox *doubleSpinBoxBoredom; QCheckBox *checkBoxInvert; + QSpacerItem *horizontalSpacer_2; + QSpacerItem *verticalSpacer_3; QLabel *label_23; - QLabel *label_21; QHBoxLayout *horizontalLayout_8; + QLabel *label_21; QSlider *sliderNMix; QDoubleSpinBox *doubleSpinBoxNMix; - QLabel *label_22; QHBoxLayout *horizontalLayout_9; + QLabel *label_22; QSlider *sliderTargetMix; QDoubleSpinBox *doubleSpinBoxTargetMix; - QSpacerItem *verticalSpacer_3; QVBoxLayout *verticalLayout_6; QLabel *label_16; QPushButton *pushButtonLoadTarget; @@ -141,7 +150,7 @@ public: { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QString::fromUtf8("MainWindow")); - MainWindow->resize(724, 613); + MainWindow->resize(643, 619); centralwidget = new QWidget(MainWindow); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); verticalLayout_4 = new QVBoxLayout(centralwidget); @@ -155,8 +164,8 @@ public: tabWidget->setFont(font); controlTab = new QWidget(); controlTab->setObjectName(QString::fromUtf8("controlTab")); - horizontalLayout_10 = new QHBoxLayout(controlTab); - horizontalLayout_10->setObjectName(QString::fromUtf8("horizontalLayout_10")); + horizontalLayout_17 = new QHBoxLayout(controlTab); + horizontalLayout_17->setObjectName(QString::fromUtf8("horizontalLayout_17")); verticalLayout_3 = new QVBoxLayout(); verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); label_19 = new QLabel(controlTab); @@ -170,6 +179,8 @@ public: verticalLayout_3->addWidget(label_19); + horizontalLayout_16 = new QHBoxLayout(); + horizontalLayout_16->setObjectName(QString::fromUtf8("horizontalLayout_16")); label_6 = new QLabel(controlTab); label_6->setObjectName(QString::fromUtf8("label_6")); QFont font2; @@ -179,10 +190,8 @@ public: font2.setWeight(75); label_6->setFont(font2); - verticalLayout_3->addWidget(label_6); + horizontalLayout_16->addWidget(label_6); - horizontalLayout_16 = new QHBoxLayout(); - horizontalLayout_16->setObjectName(QString::fromUtf8("horizontalLayout_16")); sliderRatio = new QSlider(controlTab); sliderRatio->setObjectName(QString::fromUtf8("sliderRatio")); QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); @@ -211,14 +220,14 @@ public: verticalLayout_3->addLayout(horizontalLayout_16); + horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); label_20 = new QLabel(controlTab); label_20->setObjectName(QString::fromUtf8("label_20")); label_20->setFont(font2); - verticalLayout_3->addWidget(label_20); + horizontalLayout->addWidget(label_20); - horizontalLayout = new QHBoxLayout(); - horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); sliderNRatio = new QSlider(controlTab); sliderNRatio->setObjectName(QString::fromUtf8("sliderNRatio")); sizePolicy.setHeightForWidth(sliderNRatio->sizePolicy().hasHeightForWidth()); @@ -241,16 +250,21 @@ public: verticalLayout_3->addLayout(horizontalLayout); + horizontalLayout_3 = new QHBoxLayout(); + horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); label_7 = new QLabel(controlTab); label_7->setObjectName(QString::fromUtf8("label_7")); label_7->setFont(font2); - verticalLayout_3->addWidget(label_7); + horizontalLayout_3->addWidget(label_7); - horizontalLayout_3 = new QHBoxLayout(); - horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); label_9 = new QLabel(controlTab); label_9->setObjectName(QString::fromUtf8("label_9")); + QSizePolicy sizePolicy2(QSizePolicy::Fixed, QSizePolicy::Preferred); + sizePolicy2.setHorizontalStretch(0); + sizePolicy2.setVerticalStretch(0); + sizePolicy2.setHeightForWidth(label_9->sizePolicy().hasHeightForWidth()); + label_9->setSizePolicy(sizePolicy2); label_9->setFont(font); horizontalLayout_3->addWidget(label_9); @@ -262,6 +276,8 @@ public: label_10 = new QLabel(controlTab); label_10->setObjectName(QString::fromUtf8("label_10")); + sizePolicy2.setHeightForWidth(label_10->sizePolicy().hasHeightForWidth()); + label_10->setSizePolicy(sizePolicy2); label_10->setFont(font); horizontalLayout_3->addWidget(label_10); @@ -275,6 +291,66 @@ public: verticalLayout_3->addLayout(horizontalLayout_3); + horizontalLayout_10 = new QHBoxLayout(); + horizontalLayout_10->setObjectName(QString::fromUtf8("horizontalLayout_10")); + label_24 = new QLabel(controlTab); + label_24->setObjectName(QString::fromUtf8("label_24")); + label_24->setFont(font2); + + horizontalLayout_10->addWidget(label_24); + + sliderNovelty = new QSlider(controlTab); + sliderNovelty->setObjectName(QString::fromUtf8("sliderNovelty")); + sizePolicy.setHeightForWidth(sliderNovelty->sizePolicy().hasHeightForWidth()); + sliderNovelty->setSizePolicy(sizePolicy); + sliderNovelty->setValue(0); + sliderNovelty->setOrientation(Qt::Horizontal); + + horizontalLayout_10->addWidget(sliderNovelty); + + doubleSpinBoxNovelty = new QDoubleSpinBox(controlTab); + doubleSpinBoxNovelty->setObjectName(QString::fromUtf8("doubleSpinBoxNovelty")); + sizePolicy1.setHeightForWidth(doubleSpinBoxNovelty->sizePolicy().hasHeightForWidth()); + doubleSpinBoxNovelty->setSizePolicy(sizePolicy1); + doubleSpinBoxNovelty->setMaximum(1); + doubleSpinBoxNovelty->setSingleStep(0.01); + doubleSpinBoxNovelty->setValue(0); + + horizontalLayout_10->addWidget(doubleSpinBoxNovelty); + + + verticalLayout_3->addLayout(horizontalLayout_10); + + horizontalLayout_11 = new QHBoxLayout(); + horizontalLayout_11->setObjectName(QString::fromUtf8("horizontalLayout_11")); + label_25 = new QLabel(controlTab); + label_25->setObjectName(QString::fromUtf8("label_25")); + label_25->setFont(font2); + + horizontalLayout_11->addWidget(label_25); + + sliderBoredom = new QSlider(controlTab); + sliderBoredom->setObjectName(QString::fromUtf8("sliderBoredom")); + sizePolicy.setHeightForWidth(sliderBoredom->sizePolicy().hasHeightForWidth()); + sliderBoredom->setSizePolicy(sizePolicy); + sliderBoredom->setValue(0); + sliderBoredom->setOrientation(Qt::Horizontal); + + horizontalLayout_11->addWidget(sliderBoredom); + + doubleSpinBoxBoredom = new QDoubleSpinBox(controlTab); + doubleSpinBoxBoredom->setObjectName(QString::fromUtf8("doubleSpinBoxBoredom")); + sizePolicy1.setHeightForWidth(doubleSpinBoxBoredom->sizePolicy().hasHeightForWidth()); + doubleSpinBoxBoredom->setSizePolicy(sizePolicy1); + doubleSpinBoxBoredom->setMaximum(1); + doubleSpinBoxBoredom->setSingleStep(0.01); + doubleSpinBoxBoredom->setValue(0); + + horizontalLayout_11->addWidget(doubleSpinBoxBoredom); + + + verticalLayout_3->addLayout(horizontalLayout_11); + checkBoxInvert = new QCheckBox(controlTab); checkBoxInvert->setObjectName(QString::fromUtf8("checkBoxInvert")); checkBoxInvert->setSizeIncrement(QSize(0, 0)); @@ -282,20 +358,28 @@ public: verticalLayout_3->addWidget(checkBoxInvert); + horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + verticalLayout_3->addItem(horizontalSpacer_2); + + verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout_3->addItem(verticalSpacer_3); + label_23 = new QLabel(controlTab); label_23->setObjectName(QString::fromUtf8("label_23")); label_23->setFont(font1); verticalLayout_3->addWidget(label_23); + horizontalLayout_8 = new QHBoxLayout(); + horizontalLayout_8->setObjectName(QString::fromUtf8("horizontalLayout_8")); label_21 = new QLabel(controlTab); label_21->setObjectName(QString::fromUtf8("label_21")); label_21->setFont(font2); - verticalLayout_3->addWidget(label_21); + horizontalLayout_8->addWidget(label_21); - horizontalLayout_8 = new QHBoxLayout(); - horizontalLayout_8->setObjectName(QString::fromUtf8("horizontalLayout_8")); sliderNMix = new QSlider(controlTab); sliderNMix->setObjectName(QString::fromUtf8("sliderNMix")); sizePolicy.setHeightForWidth(sliderNMix->sizePolicy().hasHeightForWidth()); @@ -318,14 +402,14 @@ public: verticalLayout_3->addLayout(horizontalLayout_8); + horizontalLayout_9 = new QHBoxLayout(); + horizontalLayout_9->setObjectName(QString::fromUtf8("horizontalLayout_9")); label_22 = new QLabel(controlTab); label_22->setObjectName(QString::fromUtf8("label_22")); label_22->setFont(font2); - verticalLayout_3->addWidget(label_22); + horizontalLayout_9->addWidget(label_22); - horizontalLayout_9 = new QHBoxLayout(); - horizontalLayout_9->setObjectName(QString::fromUtf8("horizontalLayout_9")); sliderTargetMix = new QSlider(controlTab); sliderTargetMix->setObjectName(QString::fromUtf8("sliderTargetMix")); sizePolicy.setHeightForWidth(sliderTargetMix->sizePolicy().hasHeightForWidth()); @@ -349,12 +433,8 @@ public: verticalLayout_3->addLayout(horizontalLayout_9); - verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - verticalLayout_3->addItem(verticalSpacer_3); - - - horizontalLayout_10->addLayout(verticalLayout_3); + horizontalLayout_17->addLayout(verticalLayout_3); verticalLayout_6 = new QVBoxLayout(); verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); @@ -469,7 +549,7 @@ public: verticalLayout_6->addItem(verticalSpacer); - horizontalLayout_10->addLayout(verticalLayout_6); + horizontalLayout_17->addLayout(verticalLayout_6); tabWidget->addTab(controlTab, QString()); sampleTab = new QWidget(); @@ -766,6 +846,10 @@ public: QObject::connect(sliderTargetMix, SIGNAL(valueChanged(int)), MainWindow, SLOT(target_mix_slot(int))); QObject::connect(doubleSpinBoxNMix, SIGNAL(valueChanged(double)), MainWindow, SLOT(n_mix_slot(double))); QObject::connect(doubleSpinBoxTargetMix, SIGNAL(valueChanged(double)), MainWindow, SLOT(target_mix_slot(double))); + QObject::connect(doubleSpinBoxBoredom, SIGNAL(valueChanged(double)), MainWindow, SLOT(boredom_slot(double))); + QObject::connect(sliderBoredom, SIGNAL(valueChanged(int)), MainWindow, SLOT(boredom_slot(int))); + QObject::connect(doubleSpinBoxNovelty, SIGNAL(valueChanged(double)), MainWindow, SLOT(novelty_slot(double))); + QObject::connect(sliderNovelty, SIGNAL(valueChanged(int)), MainWindow, SLOT(novelty_slot(int))); tabWidget->setCurrentIndex(0); @@ -775,17 +859,55 @@ public: void retranslateUi(QMainWindow *MainWindow) { - MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.0.4", 0, QApplication::UnicodeUTF8)); - label_19->setText(QApplication::translate("MainWindow", "search", 0, QApplication::UnicodeUTF8)); - label_6->setText(QApplication::translate("MainWindow", "fft <-> mfcc", 0, QApplication::UnicodeUTF8)); - label_20->setText(QApplication::translate("MainWindow", "freq & dynamics <-> freq only", 0, QApplication::UnicodeUTF8)); + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.0.5", 0, QApplication::UnicodeUTF8)); + label_19->setText(QApplication::translate("MainWindow", "brain tweaks", 0, QApplication::UnicodeUTF8)); + label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderRatio->setToolTip(QApplication::translate("MainWindow", "plain fft match vs mfcc values ", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP + label_20->setText(QApplication::translate("MainWindow", "freq & dynamics / freq only", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderNRatio->setToolTip(QApplication::translate("MainWindow", "match original or normalised blocks", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP + label_7->setToolTip(QString()); +#endif // QT_NO_TOOLTIP label_7->setText(QApplication::translate("MainWindow", "fft subsection", 0, QApplication::UnicodeUTF8)); label_9->setText(QApplication::translate("MainWindow", "Start", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + spinBoxFFT1Start->setToolTip(QApplication::translate("MainWindow", "start frequency to use for fft match", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP label_10->setText(QApplication::translate("MainWindow", "End", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + spinBoxFFT1End->setToolTip(QApplication::translate("MainWindow", "end frequency to use for fft match", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP + label_24->setToolTip(QString()); +#endif // QT_NO_TOOLTIP + label_24->setText(QApplication::translate("MainWindow", "novelty", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderNovelty->setToolTip(QApplication::translate("MainWindow", "use new blocks rather than similar ones", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP + label_25->setToolTip(QString()); +#endif // QT_NO_TOOLTIP + label_25->setText(QApplication::translate("MainWindow", "boredom", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderBoredom->setToolTip(QApplication::translate("MainWindow", "how long it takes for the novelty to ware off", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP + checkBoxInvert->setToolTip(QString()); +#endif // QT_NO_TOOLTIP checkBoxInvert->setText(QApplication::translate("MainWindow", "search for least similar", 0, QApplication::UnicodeUTF8)); label_23->setText(QApplication::translate("MainWindow", "mix", 0, QApplication::UnicodeUTF8)); - label_21->setText(QApplication::translate("MainWindow", "dynamic <-> normalised mix", 0, QApplication::UnicodeUTF8)); - label_22->setText(QApplication::translate("MainWindow", "brain <-> target mix", 0, QApplication::UnicodeUTF8)); + label_21->setText(QApplication::translate("MainWindow", "dynamic / normalised ", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderNMix->setToolTip(QApplication::translate("MainWindow", "mix in the normalised blocks", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP + label_22->setText(QApplication::translate("MainWindow", "brain / target", 0, QApplication::UnicodeUTF8)); +#ifndef QT_NO_TOOLTIP + sliderTargetMix->setToolTip(QApplication::translate("MainWindow", "mix in the original blocks", 0, QApplication::UnicodeUTF8)); +#endif // QT_NO_TOOLTIP 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)); @@ -837,4 +959,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // SAMPLEBRAINC26316_H +#endif // SAMPLEBRAING19815_H diff --git a/samplebrain/qt/process_thread.cpp b/samplebrain/qt/process_thread.cpp index 15db114..ebff323 100644 --- a/samplebrain/qt/process_thread.cpp +++ b/samplebrain/qt/process_thread.cpp @@ -17,6 +17,7 @@ #include "process_thread.h" #include #include +#include "status.h" using namespace spiralcore; using namespace std; @@ -103,7 +104,6 @@ void process_thread::process() { if (name=="/target_window_type") { m_target_window_type=(window::type)cmd.get_int(0); } - } usleep(500); } diff --git a/samplebrain/qt/samplebrain.pro b/samplebrain/qt/samplebrain.pro index ce611ca..5f39da0 100644 --- a/samplebrain/qt/samplebrain.pro +++ b/samplebrain/qt/samplebrain.pro @@ -16,6 +16,7 @@ HEADERS += MainWindow.h \ SOURCES += MainWindow.cpp \ audio_thread.cpp \ process_thread.cpp \ + feedback.cpp \ qtmain.cpp INCLUDEPATH += ../src diff --git a/samplebrain/src/block.cpp b/samplebrain/src/block.cpp index 7a1318d..73d369d 100644 --- a/samplebrain/src/block.cpp +++ b/samplebrain/src/block.cpp @@ -27,6 +27,14 @@ Aquila::Mfcc *block::m_mfcc_proc; static const int MFCC_FILTERS=12; +double blend(double a, double b, double t) { + return a*(1-t)+b*t; +} + +double square(double a) { + return a*a; +} + void normalise(sample &in) { // find min/max float max = 0; @@ -64,7 +72,8 @@ block::block(const string &filename, const sample &pcm, u32 rate, const window & m_n_mfcc(MFCC_FILTERS), m_block_size(pcm.get_length()), m_rate(rate), - m_orig_filename(filename) + m_orig_filename(filename), + m_usage(0) { init_fft(m_pcm.get_length()); assert(m_mfcc_proc!=NULL); @@ -138,33 +147,37 @@ double block::_compare(const sample &fft_a, const sample &mfcc_a, if (params.m_ratio==0) { for (u32 i=fft_start; i +#include #include "jellyfish/fluxa/sample.h" #include "jellyfish/core/types.h" #include "fft.h" @@ -41,6 +42,10 @@ public: const sample &get_pcm() const { return m_pcm; } const sample &get_n_pcm() const { return m_n_pcm; } + std::vector &get_synapse() { return m_synapse; } + const std::vector &get_synapse_const() const { return m_synapse; } + float &get_usage() { return m_usage; } + private: void process(const sample &pcm, sample &fft, sample &mfcc); @@ -63,6 +68,9 @@ private: static FFT *m_fftw; static Aquila::Mfcc *m_mfcc_proc; + std::vector m_synapse; + float m_usage; + }; } diff --git a/samplebrain/src/brain.cpp b/samplebrain/src/brain.cpp index d74d41b..f18378e 100644 --- a/samplebrain/src/brain.cpp +++ b/samplebrain/src/brain.cpp @@ -15,16 +15,23 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include #include #include #include #include "brain.h" +#include "status.h" using namespace std; using namespace spiralcore; -brain::brain() +brain::brain() : + m_current_block_index(0), + m_average_error(0), + m_current_error(0), + m_usage_falloff(0.9) { + status::update("brain ready..."); } // load, chop up and add to brain @@ -37,6 +44,7 @@ void brain::load_sound(std::string filename) { sample s(sfinfo.frames); sf_readf_float(f, s.get_non_const_buffer(), s.get_length()); m_samples.push_back(sound(filename,s)); + status::update("loaded %s",filename.c_str()); } } @@ -44,6 +52,7 @@ void brain::delete_sound(std::string filename) { for (std::list::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) { if (i->m_filename==filename) { m_samples.erase(i); + status::update("deleted %s",filename.c_str()); return; } } @@ -56,17 +65,19 @@ void brain::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) { m_overlap = overlap; m_window.init(block_size); m_window.set_current_type(t); + u32 count=0; for (std::list::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) { - chop_and_add(i->m_sample, ditchpcm); + count++; + chop_and_add(i->m_sample, count, ditchpcm); } + status::update("all samples processed"); } -void brain::chop_and_add(const sample &s, bool ditchpcm) { +void brain::chop_and_add(const sample &s, u32 count, bool ditchpcm) { u32 pos=0; if (m_overlap>=m_block_size) m_overlap=0; while (pos+m_block_size-1::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) { + for (vector::const_iterator j=m_blocks.begin(); j!=m_blocks.end(); ++j) { + diff += j->compare(*i,params); + } + diff/=(double)m_blocks.size(); + } + return diff; +} + +void brain::build_synapses(search_params ¶ms, double thresh) { + m_average_error = calc_average_diff(params)*thresh; + double err=m_average_error*thresh; + u32 brain_size = m_blocks.size(); + u32 outer_index=0; + for (vector::iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) { + u32 index = 0; + status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100)); + for (vector::const_iterator j=m_blocks.begin(); j!=m_blocks.end(); ++j) { + if (index!=outer_index) { + double diff = i->compare(*j,params); + if (diffget_synapse().push_back(index); + } + } + ++index; + } + ++outer_index; + } +} + +u32 brain::search_synapses(const block &target, search_params ¶ms) { + const block ¤t = get_block(m_current_block_index); + double closest = DBL_MAX; + u32 closest_index = 0; + // find nearest in synaptic connections + +// cerr<<"searching "<::const_iterator i=current.get_synapse_const().begin(); + i!=current.get_synapse_const().end(); ++i) { + const block &other = get_block(*i); + double diff = target.compare(other,params); + if (diff::iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) { + i->get_usage()*=m_usage_falloff; + } +} + + // 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){ @@ -145,7 +231,6 @@ bool brain::unit_test() { b.load_sound("test_data/100f32.wav"); b.load_sound("test_data/100i16.wav"); assert(b.m_samples.size()==2); - cerr<<"hjelele"< m_blocks; std::list m_samples; @@ -77,6 +87,10 @@ private: window m_window; + u32 m_current_block_index; + double m_current_error; + double m_average_error; + float m_usage_falloff; }; } diff --git a/samplebrain/src/config.h.in b/samplebrain/src/config.h.in index 992fc22..ebd269b 100644 --- a/samplebrain/src/config.h.in +++ b/samplebrain/src/config.h.in @@ -12,6 +12,9 @@ /* Define to 1 if you have the `jellyfish' library (-ljellyfish). */ #undef HAVE_LIBJELLYFISH +/* Define to 1 if you have the `lo' library (-llo). */ +#undef HAVE_LIBLO + /* Define to 1 if you have the `m' library (-lm). */ #undef HAVE_LIBM diff --git a/samplebrain/src/main.cpp b/samplebrain/src/main.cpp index 731642d..8857d67 100644 --- a/samplebrain/src/main.cpp +++ b/samplebrain/src/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "jellyfish/audio.h" @@ -47,7 +48,7 @@ void run_audio(void* c, unsigned int frames) { a->left_out.zero(); renderer *rr = (renderer*)c; rr->process(frames,a->left_out.get_non_const_buffer()); - + a->right_out=a->left_out; a->maybe_record(); // sleep(1); @@ -61,25 +62,39 @@ int main(int argc, char *argv[]) brain source, target; // source.load_sound("../sound/source/shostakovich6.wav"); -/* source.load_sound("../sound/source/808.wav"); +// source.load_sound("../sound/source/808.wav"); source.load_sound("../sound/source/joey.wav"); source.load_sound("../sound/source/pw2.wav"); - source.load_sound("../sound/source/pw3.wav"); +// source.load_sound("../sound/source/pw3.wav"); source.load_sound("../sound/source/claps.wav"); - source.load_sound("../sound/source/eagle.wav"); - target.load_sound("../sound/source/apache.wav"); -*/ - source.load_sound("../sound/source/totalsine.wav"); +// source.load_sound("../sound/source/eagle.wav"); + // source.load_sound("../sound/source/rise.wav"); +// source.load_sound("../sound/source/totalsine.wav"); +// target.load_sound("../sound/source/apache.wav"); - target.load_sound("../sound/source/sailingbybit.wav"); +// source.load_sound("../sound/source/totalsine.wav"); + + //target.load_sound("../sound/source/sailingbybit.wav"); + + target.load_sound("../sound/source/apache.wav"); + //target.load_sound("../sound/source/dreambit.wav"); //target.load_sound("../sound/source/sb-left.wav"); -// target.load_sound("../sound/source/rise.wav"); + //target.load_sound("../sound/source/rise.wav"); cerr<<"loaded sounds"<m_ratio=0.5; + rr.get_params()->m_usage_importance=0.5; + rr.set_slide_error(5.5); + rr.set_search_algo(renderer::SYNAPTIC); a->start_recording("debug"); a->m_client.set_callback(run_audio, &rr); diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp index 181f7ec..c302c39 100644 --- a/samplebrain/src/renderer.cpp +++ b/samplebrain/src/renderer.cpp @@ -22,14 +22,17 @@ using namespace std; void renderer::init(brain &source, brain &target) { m_volume=1; - m_invert=false; m_playing=false; m_source=source; m_target=target; + m_target_time=0; m_render_time=0; m_n_mix=0; m_target_mix=0; m_render_blocks.clear(); + m_search_algo=BASIC; + m_slide_error=1; + m_target_index=0; } static int ratio_time = 0; @@ -39,32 +42,55 @@ void renderer::process(u32 nframes, float *buf) { // get new 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; + u32 tgt_end = (m_target_time+nframes)/(float)tgt_shift; if (tgt_end>=m_target.get_num_blocks() || m_source.get_num_blocks()==0) { + m_target_time=0; m_render_time=0; + m_target_index=0; m_render_blocks.clear(); // next time... return; } - //cerr<<"-----------------"< m_render_blocks; + u32 m_target_index; + u32 m_target_time; u32 m_render_time; float m_n_mix; float m_target_mix; + + search_algo m_search_algo; + double m_slide_error; + + + std::list m_render_blocks; }; } diff --git a/samplebrain/src/search_params.h b/samplebrain/src/search_params.h index 26da064..f7c90b8 100644 --- a/samplebrain/src/search_params.h +++ b/samplebrain/src/search_params.h @@ -21,21 +21,18 @@ namespace spiralcore { class search_params { public: -search_params(float ratio, float n_ratio, int s1, int e1, int s2, int e2) : + search_params(float ratio, float n_ratio, int s1, int e1, float usage_importance) : m_ratio(ratio), m_n_ratio(n_ratio), m_fft1_start(s1), m_fft1_end(e1), - m_fft2_start(s2), - m_fft2_end(e2) {} + m_usage_importance(usage_importance) {} float m_ratio; float m_n_ratio; int m_fft1_start; int m_fft1_end; - int m_fft2_start; - int m_fft2_end; - + float m_usage_importance; }; }