From fabd9cbe4fa995b66ab8133215741c0735d8644b Mon Sep 17 00:00:00 2001 From: Dave Griffiths Date: Wed, 22 Jul 2015 15:32:36 +0100 Subject: [PATCH] mix options, render glitch fix, fft bins, interface rework --- samplebrain/interface/samplebrain.ui | 221 ++++++++++++++++++++-- samplebrain/qt/MainWindow.h | 4 + samplebrain/qt/audio_thread.cpp | 6 + samplebrain/qt/generated/ui_samplebrain.h | 131 ++++++++++--- samplebrain/src/block.cpp | 15 +- samplebrain/src/block.h | 1 + samplebrain/src/brain.cpp | 8 +- samplebrain/src/brain.h | 3 +- samplebrain/src/fft.cpp | 38 +++- samplebrain/src/fft.h | 8 +- samplebrain/src/main.cpp | 14 +- samplebrain/src/renderer.cpp | 41 ++-- samplebrain/src/renderer.h | 9 +- 13 files changed, 427 insertions(+), 72 deletions(-) diff --git a/samplebrain/interface/samplebrain.ui b/samplebrain/interface/samplebrain.ui index 6177bbb..4de2b20 100644 --- a/samplebrain/interface/samplebrain.ui +++ b/samplebrain/interface/samplebrain.ui @@ -14,7 +14,7 @@ samplebrain 0.0.4 - + @@ -31,7 +31,7 @@ search - + @@ -45,7 +45,7 @@ - tweakage + search @@ -54,13 +54,13 @@ Comic Sans MS - 14 + 9 75 true - fft <-> mfcc ratio + fft <-> mfcc @@ -108,13 +108,13 @@ Comic Sans MS - 14 + 9 75 true - freq & dynamics <-> freq ratio + freq & dynamics <-> freq only @@ -129,7 +129,7 @@ - 50 + 0 Qt::Horizontal @@ -151,7 +151,7 @@ 0.010000000000000 - 0.500000000000000 + 0.000000000000000 @@ -162,7 +162,7 @@ Comic Sans MS - 14 + 9 75 true @@ -223,7 +223,7 @@ - invert + search for least similar @@ -233,6 +233,132 @@ + + + + + Comic Sans MS + 20 + 75 + true + + + + mix + + + + + + + + Comic Sans MS + 9 + 75 + true + + + + dynamic <-> normalised mix + + + + + + + + + + 0 + 0 + + + + 0 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.000000000000000 + + + + + + + + + + Comic Sans MS + 9 + 75 + true + + + + brain <-> target mix + + + + + + + + + + 0 + 0 + + + + 0 + + + 0 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.000000000000000 + + + + + @@ -332,7 +458,7 @@ 0.010000000000000 - 0.750000000000000 + 0.000000000000000 @@ -514,7 +640,7 @@ 0.010000000000000 - 0.750000000000000 + 0.000000000000000 @@ -866,6 +992,7 @@ + @@ -1476,6 +1603,70 @@ + + sliderNMix + valueChanged(int) + MainWindow + n_mix_slot(int) + + + 159 + 386 + + + 361 + 306 + + + + + sliderTargetMix + valueChanged(int) + MainWindow + target_mix_slot(int) + + + 159 + 446 + + + 361 + 306 + + + + + doubleSpinBoxNMix + valueChanged(double) + MainWindow + n_mix_slot(double) + + + 330 + 386 + + + 361 + 306 + + + + + doubleSpinBoxTargetMix + valueChanged(double) + MainWindow + target_mix_slot(double) + + + 330 + 446 + + + 361 + 306 + + + play_slot() @@ -1522,5 +1713,9 @@ n_ratio_slot(int) n_ratio_slot(double) invert_slot(bool) + n_mix_slot(int) + n_mix_slot(double) + target_mix_slot(int) + target_mix_slot(double) diff --git a/samplebrain/qt/MainWindow.h b/samplebrain/qt/MainWindow.h index 80a9279..0d58cd3 100644 --- a/samplebrain/qt/MainWindow.h +++ b/samplebrain/qt/MainWindow.h @@ -48,6 +48,10 @@ private slots: 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 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); diff --git a/samplebrain/qt/audio_thread.cpp b/samplebrain/qt/audio_thread.cpp index 6bfdc06..c6cd825 100644 --- a/samplebrain/qt/audio_thread.cpp +++ b/samplebrain/qt/audio_thread.cpp @@ -91,6 +91,12 @@ void audio_thread::process(sample &s, sample &s2) { if (name=="/invert") { m_renderer->set_invert(cmd.get_int(0)); } + if (name=="/n_mix") { + m_renderer->set_n_mix(cmd.get_float(0)); + } + if (name=="/target_mix") { + m_renderer->set_target_mix(cmd.get_float(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 97480fb..85f5535 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 'samplebrainm32443.ui' +** Form generated from reading UI file 'samplebrainC26316.ui' ** -** Created: Tue Jul 21 22:01:28 2015 +** Created: Wed Jul 22 15:20:00 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 SAMPLEBRAINM32443_H -#define SAMPLEBRAINM32443_H +#ifndef SAMPLEBRAINC26316_H +#define SAMPLEBRAINC26316_H #include #include @@ -40,10 +40,10 @@ class Ui_MainWindow { public: QWidget *centralwidget; - QVBoxLayout *verticalLayout_7; + QVBoxLayout *verticalLayout_4; QTabWidget *tabWidget; QWidget *controlTab; - QHBoxLayout *horizontalLayout_8; + QHBoxLayout *horizontalLayout_10; QVBoxLayout *verticalLayout_3; QLabel *label_19; QLabel *label_6; @@ -61,6 +61,15 @@ public: QLabel *label_10; QSpinBox *spinBoxFFT1End; QCheckBox *checkBoxInvert; + QLabel *label_23; + QLabel *label_21; + QHBoxLayout *horizontalLayout_8; + QSlider *sliderNMix; + QDoubleSpinBox *doubleSpinBoxNMix; + QLabel *label_22; + QHBoxLayout *horizontalLayout_9; + QSlider *sliderTargetMix; + QDoubleSpinBox *doubleSpinBoxTargetMix; QSpacerItem *verticalSpacer_3; QVBoxLayout *verticalLayout_6; QLabel *label_16; @@ -135,8 +144,8 @@ public: MainWindow->resize(724, 613); centralwidget = new QWidget(MainWindow); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); - verticalLayout_7 = new QVBoxLayout(centralwidget); - verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7")); + verticalLayout_4 = new QVBoxLayout(centralwidget); + verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4")); tabWidget = new QTabWidget(centralwidget); tabWidget->setObjectName(QString::fromUtf8("tabWidget")); QFont font; @@ -146,8 +155,8 @@ public: tabWidget->setFont(font); controlTab = new QWidget(); controlTab->setObjectName(QString::fromUtf8("controlTab")); - horizontalLayout_8 = new QHBoxLayout(controlTab); - horizontalLayout_8->setObjectName(QString::fromUtf8("horizontalLayout_8")); + horizontalLayout_10 = new QHBoxLayout(controlTab); + horizontalLayout_10->setObjectName(QString::fromUtf8("horizontalLayout_10")); verticalLayout_3 = new QVBoxLayout(); verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); label_19 = new QLabel(controlTab); @@ -165,7 +174,7 @@ public: label_6->setObjectName(QString::fromUtf8("label_6")); QFont font2; font2.setFamily(QString::fromUtf8("Comic Sans MS")); - font2.setPointSize(14); + font2.setPointSize(9); font2.setBold(true); font2.setWeight(75); label_6->setFont(font2); @@ -214,7 +223,7 @@ public: sliderNRatio->setObjectName(QString::fromUtf8("sliderNRatio")); sizePolicy.setHeightForWidth(sliderNRatio->sizePolicy().hasHeightForWidth()); sliderNRatio->setSizePolicy(sizePolicy); - sliderNRatio->setValue(50); + sliderNRatio->setValue(0); sliderNRatio->setOrientation(Qt::Horizontal); horizontalLayout->addWidget(sliderNRatio); @@ -225,7 +234,7 @@ public: doubleSpinBoxNRatio->setSizePolicy(sizePolicy1); doubleSpinBoxNRatio->setMaximum(1); doubleSpinBoxNRatio->setSingleStep(0.01); - doubleSpinBoxNRatio->setValue(0.5); + doubleSpinBoxNRatio->setValue(0); horizontalLayout->addWidget(doubleSpinBoxNRatio); @@ -273,12 +282,79 @@ public: verticalLayout_3->addWidget(checkBoxInvert); + label_23 = new QLabel(controlTab); + label_23->setObjectName(QString::fromUtf8("label_23")); + label_23->setFont(font1); + + verticalLayout_3->addWidget(label_23); + + label_21 = new QLabel(controlTab); + label_21->setObjectName(QString::fromUtf8("label_21")); + label_21->setFont(font2); + + verticalLayout_3->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()); + sliderNMix->setSizePolicy(sizePolicy); + sliderNMix->setValue(0); + sliderNMix->setOrientation(Qt::Horizontal); + + horizontalLayout_8->addWidget(sliderNMix); + + doubleSpinBoxNMix = new QDoubleSpinBox(controlTab); + doubleSpinBoxNMix->setObjectName(QString::fromUtf8("doubleSpinBoxNMix")); + sizePolicy1.setHeightForWidth(doubleSpinBoxNMix->sizePolicy().hasHeightForWidth()); + doubleSpinBoxNMix->setSizePolicy(sizePolicy1); + doubleSpinBoxNMix->setMaximum(1); + doubleSpinBoxNMix->setSingleStep(0.01); + doubleSpinBoxNMix->setValue(0); + + horizontalLayout_8->addWidget(doubleSpinBoxNMix); + + + verticalLayout_3->addLayout(horizontalLayout_8); + + label_22 = new QLabel(controlTab); + label_22->setObjectName(QString::fromUtf8("label_22")); + label_22->setFont(font2); + + verticalLayout_3->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()); + sliderTargetMix->setSizePolicy(sizePolicy); + sliderTargetMix->setValue(0); + sliderTargetMix->setSliderPosition(0); + sliderTargetMix->setOrientation(Qt::Horizontal); + + horizontalLayout_9->addWidget(sliderTargetMix); + + doubleSpinBoxTargetMix = new QDoubleSpinBox(controlTab); + doubleSpinBoxTargetMix->setObjectName(QString::fromUtf8("doubleSpinBoxTargetMix")); + sizePolicy1.setHeightForWidth(doubleSpinBoxTargetMix->sizePolicy().hasHeightForWidth()); + doubleSpinBoxTargetMix->setSizePolicy(sizePolicy1); + doubleSpinBoxTargetMix->setMaximum(1); + doubleSpinBoxTargetMix->setSingleStep(0.01); + doubleSpinBoxTargetMix->setValue(0); + + horizontalLayout_9->addWidget(doubleSpinBoxTargetMix); + + + verticalLayout_3->addLayout(horizontalLayout_9); + verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); verticalLayout_3->addItem(verticalSpacer_3); - horizontalLayout_8->addLayout(verticalLayout_3); + horizontalLayout_10->addLayout(verticalLayout_3); verticalLayout_6 = new QVBoxLayout(); verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6")); @@ -324,7 +400,7 @@ public: doubleSpinBoxBlockOverlapTarget->setObjectName(QString::fromUtf8("doubleSpinBoxBlockOverlapTarget")); doubleSpinBoxBlockOverlapTarget->setMaximum(1); doubleSpinBoxBlockOverlapTarget->setSingleStep(0.01); - doubleSpinBoxBlockOverlapTarget->setValue(0.75); + doubleSpinBoxBlockOverlapTarget->setValue(0); horizontalLayout_14->addWidget(doubleSpinBoxBlockOverlapTarget); @@ -393,7 +469,7 @@ public: verticalLayout_6->addItem(verticalSpacer); - horizontalLayout_8->addLayout(verticalLayout_6); + horizontalLayout_10->addLayout(verticalLayout_6); tabWidget->addTab(controlTab, QString()); sampleTab = new QWidget(); @@ -438,7 +514,7 @@ public: doubleSpinBoxBlockOverlap->setObjectName(QString::fromUtf8("doubleSpinBoxBlockOverlap")); doubleSpinBoxBlockOverlap->setMaximum(1); doubleSpinBoxBlockOverlap->setSingleStep(0.01); - doubleSpinBoxBlockOverlap->setValue(0.75); + doubleSpinBoxBlockOverlap->setValue(0); horizontalLayout_6->addWidget(doubleSpinBoxBlockOverlap); @@ -577,7 +653,7 @@ public: tabWidget->addTab(logTab, QString()); - verticalLayout_7->addWidget(tabWidget); + verticalLayout_4->addWidget(tabWidget); horizontalLayout_12 = new QHBoxLayout(); horizontalLayout_12->setObjectName(QString::fromUtf8("horizontalLayout_12")); @@ -640,7 +716,7 @@ public: horizontalLayout_12->addWidget(label_13); - verticalLayout_7->addLayout(horizontalLayout_12); + verticalLayout_4->addLayout(horizontalLayout_12); MainWindow->setCentralWidget(centralwidget); statusbar = new QStatusBar(MainWindow); @@ -686,6 +762,10 @@ public: 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))); + QObject::connect(sliderNMix, SIGNAL(valueChanged(int)), MainWindow, SLOT(n_mix_slot(int))); + 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))); tabWidget->setCurrentIndex(0); @@ -696,13 +776,16 @@ public: void retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.0.4", 0, QApplication::UnicodeUTF8)); - label_19->setText(QApplication::translate("MainWindow", "tweakage", 0, QApplication::UnicodeUTF8)); - label_6->setText(QApplication::translate("MainWindow", "fft <-> mfcc ratio", 0, QApplication::UnicodeUTF8)); - label_20->setText(QApplication::translate("MainWindow", "freq & dynamics <-> freq ratio", 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)); 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)); + 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_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)); @@ -754,4 +837,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // SAMPLEBRAINM32443_H +#endif // SAMPLEBRAINC26316_H diff --git a/samplebrain/src/block.cpp b/samplebrain/src/block.cpp index 9b6e975..7a1318d 100644 --- a/samplebrain/src/block.cpp +++ b/samplebrain/src/block.cpp @@ -88,7 +88,7 @@ void block::init_fft(u32 block_size) { if (m_fftw == NULL || m_fftw->m_length!=block_size) { if (m_fftw == NULL) delete m_fftw; - m_fftw = new FFT(block_size); + m_fftw = new FFT(block_size,100); if (m_mfcc_proc == NULL) delete m_mfcc_proc; m_mfcc_proc = new Aquila::Mfcc(block_size); } @@ -96,16 +96,25 @@ void block::init_fft(u32 block_size) void block::process(const sample &pcm, sample &fft, sample &mfcc) { m_fftw->impulse2freq(pcm.get_buffer()); + m_fftw->calculate_bins(); // calculate fft std::vector > mfspec; for (u32 i=0; im_spectrum[i][0]; mfspec.push_back(std::complex(m_fftw->m_spectrum[i][0], m_fftw->m_spectrum[i][1])); } - if (m_block_size>100) fft.crop_to(100); + u32 fft_size = m_block_size; + if (fft_size>100) { + fft.crop_to(100); + fft_size=100; + } + + for (u32 i=0; im_bin[i]; + } + // calculate mfcc std::vector m = m_mfcc_proc->calculate(mfspec,MFCC_FILTERS); diff --git a/samplebrain/src/block.h b/samplebrain/src/block.h index a3d6a0d..b9d0ffb 100644 --- a/samplebrain/src/block.h +++ b/samplebrain/src/block.h @@ -39,6 +39,7 @@ public: static bool unit_test(); const sample &get_pcm() const { return m_pcm; } + const sample &get_n_pcm() const { return m_n_pcm; } private: diff --git a/samplebrain/src/brain.cpp b/samplebrain/src/brain.cpp index 0decb19..d74d41b 100644 --- a/samplebrain/src/brain.cpp +++ b/samplebrain/src/brain.cpp @@ -74,10 +74,6 @@ void brain::chop_and_add(const sample &s, bool ditchpcm) { } } -const sample &brain::get_block_pcm(u32 index) const { - return m_blocks[index].get_pcm(); -} - const block &brain::get_block(u32 index) const { return m_blocks[index]; } @@ -116,7 +112,7 @@ u32 brain::rev_search(const block &target, const search_params ¶ms) const { // 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){ +/*void brain::resynth(const string &filename, const brain &other, const search_params ¶ms){ sample out((m_block_size-m_overlap)*m_blocks.size()); out.zero(); u32 pos = 0; @@ -139,7 +135,7 @@ void brain::resynth(const string &filename, const brain &other, const search_par } audio_device::save_sample(filename,out); } - +*/ bool brain::unit_test() { brain b; diff --git a/samplebrain/src/brain.h b/samplebrain/src/brain.h index 9933eb7..e719c85 100644 --- a/samplebrain/src/brain.h +++ b/samplebrain/src/brain.h @@ -51,9 +51,10 @@ public: void clear_sounds() { m_samples.clear(); } // take another brain and rebuild this brain from bits of that one // (presumably this one is made from a single sample) - void resynth(const std::string &filename, const brain &other, const search_params ¶ms); + //void resynth(const std::string &filename, const brain &other, const search_params ¶ms); const sample &get_block_pcm(u32 index) const; + const sample &get_block_n_pcm(u32 index) const; const block &get_block(u32 index) const; u32 get_num_blocks() const { return m_blocks.size(); } u32 get_block_size() const { return m_block_size; } diff --git a/samplebrain/src/fft.cpp b/samplebrain/src/fft.cpp index 4c4864c..39e539e 100644 --- a/samplebrain/src/fft.cpp +++ b/samplebrain/src/fft.cpp @@ -15,16 +15,20 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -#include + +#include using namespace spiralcore; +using namespace std; static const int MAX_FFT_LENGTH = 4096; -FFT::FFT(int length) : +FFT::FFT(u32 length, u32 bins) : m_length(length), + m_num_bins(bins), m_in(new double[length]), - m_spectrum(new fftw_complex[length]) + m_spectrum(new fftw_complex[length]), + m_bin(new float[bins]) { m_plan = fftw_plan_dft_r2c_1d(m_length, m_in, m_spectrum, FFTW_ESTIMATE); } @@ -46,3 +50,31 @@ void FFT::impulse2freq(const float *imp) fftw_execute(m_plan); } + +void FFT::calculate_bins() { + float useful_area = m_length/2; + + for (unsigned int n=0; n +#include #ifndef SPIRALCORE_FFT #define SPIRALCORE_FFT @@ -26,14 +27,17 @@ namespace spiralcore { class FFT { public: - FFT(int length); + FFT(u32 length, u32 num_bins); ~FFT(); void impulse2freq(const float *imp); + void calculate_bins(); fftw_plan m_plan; - unsigned int m_length; + u32 m_length; + u32 m_num_bins; double *m_in; fftw_complex *m_spectrum; + float *m_bin; }; } diff --git a/samplebrain/src/main.cpp b/samplebrain/src/main.cpp index 6211444..731642d 100644 --- a/samplebrain/src/main.cpp +++ b/samplebrain/src/main.cpp @@ -48,6 +48,8 @@ void run_audio(void* c, unsigned int frames) { renderer *rr = (renderer*)c; rr->process(frames,a->left_out.get_non_const_buffer()); + a->maybe_record(); + // sleep(1); } @@ -59,24 +61,25 @@ 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/claps.wav"); source.load_sound("../sound/source/eagle.wav"); - target.load_sound("../sound/source/apache.wav"); -// source.load_sound("../sound/source/rise.wav"); +*/ + source.load_sound("../sound/source/totalsine.wav"); + target.load_sound("../sound/source/sailingbybit.wav"); //target.load_sound("../sound/source/sb-left.wav"); // target.load_sound("../sound/source/rise.wav"); cerr<<"loaded sounds"<m_ratio=0.5; + a->start_recording("debug"); a->m_client.set_callback(run_audio, &rr); //target.resynth("shosta-dream-0.5.wav",source,0.5); diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp index 8d5d8e1..181f7ec 100644 --- a/samplebrain/src/renderer.cpp +++ b/samplebrain/src/renderer.cpp @@ -22,10 +22,13 @@ 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_render_time=0; + m_n_mix=0; + m_target_mix=0; m_render_blocks.clear(); } @@ -34,7 +37,7 @@ static int ratio_time = 0; void renderer::process(u32 nframes, float *buf) { if (!m_playing) return; - // get blocks from source for the current buffer + // 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; @@ -47,12 +50,12 @@ void renderer::process(u32 nframes, float *buf) { } -// cerr<<"-----------------"<::iterator i=m_render_blocks.begin(); i!=m_render_blocks.end(); ++i) { - const sample &pcm=m_source.get_block_pcm(i->m_index); + const sample &pcm=m_source.get_block(i->m_index).get_pcm(); + const sample &n_pcm=m_source.get_block(i->m_index).get_n_pcm(); + const sample &target_pcm=m_target.get_block(i->m_tgt_index).get_pcm(); // get the sample offset into the buffer s32 offset = i->m_time-m_render_time; @@ -90,8 +95,18 @@ void renderer::process(u32 nframes, float *buf) { u32 buffer_pos = buffer_start; u32 block_pos = block_start; u32 block_end = pcm.get_length(); + + while (block_pos m_render_blocks; u32 m_render_time; + float m_n_mix; + float m_target_mix; }; }