diff --git a/samplebrain/interface/sample.ui b/samplebrain/interface/sample.ui new file mode 100644 index 0000000..64636bc --- /dev/null +++ b/samplebrain/interface/sample.ui @@ -0,0 +1,77 @@ + + + FormSample + + + + 0 + 0 + 400 + 46 + + + + Form + + + + + + + Comic Sans MS + 75 + true + + + + active + + + + + + + + Comic Sans MS + 75 + true + + + + TextLabel + + + + + + + + Comic Sans MS + 75 + true + + + + TextLabel + + + + + + + + Comic Sans MS + 75 + true + + + + delete + + + + + + + + diff --git a/samplebrain/interface/samplebrain.ui b/samplebrain/interface/samplebrain.ui new file mode 100644 index 0000000..3438526 --- /dev/null +++ b/samplebrain/interface/samplebrain.ui @@ -0,0 +1,912 @@ + + + MainWindow + + + + 0 + 0 + 724 + 603 + + + + samplebrain 0.0.3 + + + + + + + 0 + + + + search + + + + + + + + + Comic Sans MS + 20 + 75 + true + + + + tweakage + + + + + + + + + + Comic Sans MS + 75 + true + + + + Start + + + false + + + + + + + + Comic Sans MS + 75 + true + + + + Stop + + + + + + + + + + + + + + Comic Sans MS + 14 + 75 + true + + + + fft <-> mfcc ratio + + + + + + + true + + + + 0 + 0 + + + + + 60 + 60 + + + + + + + + + + + + + + + + Comic Sans MS + 14 + 75 + true + + + + fft subsection 1 + + + + + + + + + + Comic Sans MS + 75 + true + + + + Start + + + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + End + + + + + + + + + + + + + + + + + Comic Sans MS + 14 + 75 + true + + + + fft subsection 2 + + + + + + + + + + Comic Sans MS + 75 + true + + + + Start + + + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + End + + + + + + + + + + + + + + + + Qt::Vertical + + + + 323 + 511 + + + + + + + + + + + Comic Sans MS + 75 + true + + + + Volume + + + + + + + 99 + + + + + + + + + + + + + + Comic Sans MS + 20 + 75 + true + + + + target sound + + + + + + + + Comic Sans MS + 75 + true + + + + no sound yet... + + + + + + + + Comic Sans MS + 75 + true + + + + load target + + + + + + + + + + Comic Sans MS + 75 + true + + + + block size + + + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + block overlap + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + generate blocks + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + brain + + + + + + + + + Comic Sans MS + 20 + 75 + true + + + + brain parameters + + + + + + + + + + Comic Sans MS + 75 + true + + + + block size + + + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + block overlap + + + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + fft spectrum size + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + generate + + + + + + + + + + Comic Sans MS + 75 + true + + + + load + + + + + + + + Comic Sans MS + 75 + true + + + + save + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + brain contents + + + + + + + + + + + + + Comic Sans MS + 75 + true + + + + load sound + + + + + + + + + + + + + + + + + + + pushButtonPlay + released() + MainWindow + play_slot() + + + 64 + 62 + + + 399 + 301 + + + + + pushButtonStop + released() + MainWindow + stop_slot() + + + 155 + 62 + + + 399 + 301 + + + + + dialRatio + sliderMoved(int) + MainWindow + ratio_slot(int) + + + 109 + 154 + + + 399 + 301 + + + + + doubleSpinBoxRatio + valueChanged(double) + MainWindow + ratio_slot(double) + + + 109 + 223 + + + 399 + 301 + + + + + spinBoxFFT1Start + valueChanged(int) + MainWindow + fft1_start_slot(int) + + + 154 + 277 + + + 399 + 301 + + + + + spinBoxFFT1End + valueChanged(int) + MainWindow + fft1_end_slot(int) + + + 154 + 310 + + + 399 + 301 + + + + + spinBoxFFT2Start + valueChanged(int) + MainWindow + fft2_start_slot(int) + + + 154 + 366 + + + 399 + 301 + + + + + spinBoxFFT2End + valueChanged(int) + MainWindow + fft2_end_slot(int) + + + 154 + 399 + + + 399 + 301 + + + + + pushButtonLoadTarget + released() + MainWindow + load_target() + + + 277 + 103 + + + 399 + 301 + + + + + spinBoxBlockSizeTarget + valueChanged(int) + MainWindow + target_block_size(int) + + + 313 + 136 + + + 399 + 301 + + + + + spinBoxBlockOverlapTarget + valueChanged(int) + MainWindow + target_block_overlap(int) + + + 320 + 169 + + + 399 + 301 + + + + + pushButtonGenerateTarget + released() + MainWindow + generate_target_blocks() + + + 277 + 202 + + + 399 + 301 + + + + + spinBoxBlockSize + valueChanged(int) + MainWindow + block_size(int) + + + 188 + 105 + + + 399 + 301 + + + + + spinBoxBlockOverlap + valueChanged(int) + MainWindow + block_overlap(int) + + + 188 + 138 + + + 399 + 301 + + + + + spinBoxSpectSize + valueChanged(int) + MainWindow + fft_spectrum_size(int) + + + 188 + 171 + + + 399 + 301 + + + + + pushButtonGenerate + released() + MainWindow + generate() + + + 131 + 204 + + + 399 + 301 + + + + + pushButtonLoadSound + released() + MainWindow + load_sound() + + + 381 + 544 + + + 399 + 301 + + + + + dialVolume + sliderMoved(int) + MainWindow + volume_slot(int) + + + 189 + 480 + + + 361 + 301 + + + + + + play_slot() + stop_slot() + ratio_slot(double) + ratio_slot(int) + fft1_start_slot(int) + fft2_start_slot(int) + fft1_end_slot(int) + fft2_end_slot(int) + volume_slot(int) + run_slot() + block_size(int) + block_overlap(int) + fft_spectrum_size(int) + generate() + load_sound() + delete_sound() + slot2() + load_target() + target_block_size(int) + target_block_overlap(int) + generate_target_blocks() + + diff --git a/samplebrain/qt/MainWindow.cpp b/samplebrain/qt/MainWindow.cpp index ac60257..243b9d5 100644 --- a/samplebrain/qt/MainWindow.cpp +++ b/samplebrain/qt/MainWindow.cpp @@ -3,40 +3,13 @@ #include "MainWindow.h" -using namespace spiralcore; using namespace std; MainWindow::MainWindow() { m_Ui.setupUi(this); setUnifiedTitleAndToolBarOnMac(true); -} - -void MainWindow::init_brain() { - cerr<<"starting"< #include "generated/ui_samplebrain.h" -#include "brain.h" -#include "renderer.h" +#include +#include class MainWindow : public QMainWindow { @@ -11,24 +11,21 @@ class MainWindow : public QMainWindow public: MainWindow(); - void init_brain(); - spiralcore::brain m_source, m_target; - spiralcore::renderer *m_renderer; protected: private slots: - 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 play_slot() { lo_send(m_process_address,"/init",""); } + void stop_slot() {} //{ m_renderer->set_playing(false); } + 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 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 volume_slot(int s){} // { m_renderer->set_volume(s/50.0f); } void run_slot() {} void load_target() {} void target_block_size(int) {} @@ -42,5 +39,6 @@ private slots: private: Ui_MainWindow m_Ui; - + lo_address m_audio_address; + lo_address m_process_address; }; diff --git a/samplebrain/qt/Makefile b/samplebrain/qt/Makefile index a47b454..a0dd1d9 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: Sat Jul 11 11:13:22 2015 +# Generated by qmake (2.01a) (Qt 4.8.1) on: Sat Jul 11 18:25:22 2015 # Project: samplebrain.pro # Template: app # Command: /usr/bin/qmake -o Makefile samplebrain.pro @@ -16,7 +16,7 @@ CXXFLAGS = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I2 -I../src -I. LINK = g++ LFLAGS = -m64 -Wl,-O1 -LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -ldl -lm -lQtGui -lQtCore -lpthread +LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -llo -ldl -lm -lQtGui -lQtCore -lpthread AR = ar cqs RANLIB = QMAKE = /usr/bin/qmake @@ -44,8 +44,12 @@ OBJECTS_DIR = ./ ####### Files SOURCES = MainWindow.cpp \ + audio_thread.cpp \ + process_thread.cpp \ qtmain.cpp moc_MainWindow.cpp OBJECTS = MainWindow.o \ + audio_thread.o \ + process_thread.o \ qtmain.o \ moc_MainWindow.o DIST = /usr/share/qt4/mkspecs/common/unix.conf \ @@ -162,7 +166,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 MainWindow.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 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 clean:compiler_clean @@ -213,8 +217,17 @@ MainWindow.o: MainWindow.cpp MainWindow.h \ generated/ui_samplebrain.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainWindow.o MainWindow.cpp +audio_thread.o: audio_thread.cpp audio_thread.h \ + process_thread.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o audio_thread.o audio_thread.cpp + +process_thread.o: process_thread.cpp process_thread.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o process_thread.o process_thread.cpp + qtmain.o: qtmain.cpp MainWindow.h \ - generated/ui_samplebrain.h + generated/ui_samplebrain.h \ + process_thread.h \ + audio_thread.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtmain.o qtmain.cpp moc_MainWindow.o: moc_MainWindow.cpp diff --git a/samplebrain/qt/audio_thread.cpp b/samplebrain/qt/audio_thread.cpp new file mode 100644 index 0000000..57f8cf7 --- /dev/null +++ b/samplebrain/qt/audio_thread.cpp @@ -0,0 +1,37 @@ +#include "audio_thread.h" +#include + +using namespace spiralcore; +using namespace std; + +audio_thread::audio_thread(process_thread &p) : + m_process_thread(p), + m_brain_mutex(p.m_brain_mutex), + m_osc("8888") +{ + pthread_mutex_lock(m_brain_mutex); + m_renderer = new renderer(p.m_source,p.m_target); + pthread_mutex_unlock(m_brain_mutex); + m_osc.run(); +} + +void audio_thread::process(sample &s) { + + command_ring_buffer::command cmd; + while (m_osc.get(cmd)) { + string name = cmd.m_name; + cerr<get_params()->m_ratio = cmd.get_float(0); + } + } + + + s.zero(); + if (!pthread_mutex_trylock(m_brain_mutex)) { + m_renderer->process(s.get_length(),s.get_non_const_buffer()); + pthread_mutex_unlock(m_brain_mutex); + } else { + cerr<<"audio no lock..."< + +using namespace spiralcore; +using namespace std; + +process_thread::process_thread() : + m_osc("8889") +{ + m_brain_mutex = new pthread_mutex_t; + pthread_mutex_init(m_brain_mutex,NULL); + m_osc.run(); + + // start the processing thread + pthread_t *thread = new pthread_t; + pthread_create(thread,NULL,(void*(*)(void*))process_thread::process,this); + +} + +void process_thread::process(void *c) { + process_thread *p=(process_thread*)c; + command_ring_buffer::command cmd; + + while(true) { + while (p->m_osc.get(cmd)) { + string name = cmd.m_name; + cerr<init_brain(); + } + } + usleep(500); + } +} + + +void process_thread::init_brain() { + pthread_mutex_lock(m_brain_mutex); + + cerr<<"starting"< + +#pragma once + +namespace spiralcore { + +class process_thread { +public: + process_thread(); + void init_brain(); + + brain m_source, m_target; + pthread_mutex_t* m_brain_mutex; + +private: + static void process(void *c); + OSC_server m_osc; +}; + +} diff --git a/samplebrain/qt/qtmain.cpp b/samplebrain/qt/qtmain.cpp index f296d92..8ca302f 100644 --- a/samplebrain/qt/qtmain.cpp +++ b/samplebrain/qt/qtmain.cpp @@ -7,20 +7,17 @@ #include "jellyfish/audio.h" -#include "block.h" -#include "brain.h" -#include "renderer.h" +#include "process_thread.h" +#include "audio_thread.h" using namespace std; audio_device *a = NULL; -renderer *rr = NULL; void run_audio(void* c, unsigned int frames) { + audio_thread *at = (audio_thread*)c; a->left_out.zero(); - rr->process(frames,a->left_out.get_non_const_buffer()); - -// sleep(1); + at->process(a->left_out); } int main( int argc , char *argv[] ){ @@ -28,10 +25,11 @@ int main( int argc , char *argv[] ){ MainWindow mainWin; mainWin.show(); - mainWin.init_brain(); - rr = mainWin.m_renderer; + process_thread pt; + audio_thread at(pt); + a = new audio_device("samplebrain",44100,2048); - a->m_client.set_callback(run_audio, &rr); + a->m_client.set_callback(run_audio, &at); return app.exec(); } diff --git a/samplebrain/qt/samplebrain.pro b/samplebrain/qt/samplebrain.pro index e915955..2bf1083 100644 --- a/samplebrain/qt/samplebrain.pro +++ b/samplebrain/qt/samplebrain.pro @@ -14,10 +14,12 @@ HEADERS += MainWindow.h \ generated/ui_samplebrain.h \ SOURCES += MainWindow.cpp \ + audio_thread.cpp \ + process_thread.cpp \ qtmain.cpp INCLUDEPATH += ../src -LIBS += -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -ldl -lpthread -lm +LIBS += -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm # assets #RESOURCES = application.qrc diff --git a/samplebrain/src/brain.h b/samplebrain/src/brain.h index 35dc19c..5b4f7f4 100644 --- a/samplebrain/src/brain.h +++ b/samplebrain/src/brain.h @@ -26,9 +26,9 @@ public: const sample &get_block_pcm(u32 index) const; const block &get_block(u32 index) const; - const u32 get_num_blocks() const { return m_blocks.size(); } - const u32 get_block_size() const { return m_block_size; } - const u32 get_overlap() const { return m_overlap; } + u32 get_num_blocks() const { return m_blocks.size(); } + u32 get_block_size() const { return m_block_size; } + u32 get_overlap() const { return m_overlap; } u32 search(const block &target, const search_params ¶ms) const; diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp index bac5b5a..8945aa0 100644 --- a/samplebrain/src/renderer.cpp +++ b/samplebrain/src/renderer.cpp @@ -5,6 +5,7 @@ using namespace spiralcore; using namespace std; void renderer::init(brain &source, brain &target) { + m_volume=1; m_source=source; m_target=target; m_render_time=0; diff --git a/samplebrain/src/search_params.h b/samplebrain/src/search_params.h new file mode 100644 index 0000000..8bdb0bd --- /dev/null +++ b/samplebrain/src/search_params.h @@ -0,0 +1,26 @@ +#ifndef SEARCH_PARAMS +#define SEARCH_PARAMS + +namespace spiralcore { + +class search_params { +public: +search_params(float ratio, int s1, int e1, int s2, int e2) : + m_ratio(ratio), + m_fft1_start(s1), + m_fft1_end(e1), + m_fft2_start(s2), + m_fft2_end(e2) {} + + + float m_ratio; + int m_fft1_start; + int m_fft1_end; + int m_fft2_start; + int m_fft2_end; + +}; + +} + +#endif