mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-05-12 10:37:20 +00:00
invert mode added
This commit is contained in:
parent
1148166537
commit
3f2b86c171
@ -214,6 +214,25 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxInvert">
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>invert</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
@ -1441,6 +1460,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>checkBoxInvert</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>invert_slot(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>189</x>
|
||||
<y>313</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>361</x>
|
||||
<y>306</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>play_slot()</slot>
|
||||
@ -1486,5 +1521,6 @@
|
||||
<slot>stop_record()</slot>
|
||||
<slot>n_ratio_slot(int)</slot>
|
||||
<slot>n_ratio_slot(double)</slot>
|
||||
<slot>invert_slot(bool)</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
@ -49,6 +49,11 @@ private slots:
|
||||
void fft2_start_slot(int s){} // { m_renderer->get_params()->m_fft2_start=s; }
|
||||
void fft2_end_slot(int s){} // { m_renderer->get_params()->m_fft2_end=s; }
|
||||
void volume_slot(int s) { lo_send(m_audio_address,"/volume","f",s/100.0f); }
|
||||
void invert_slot(bool s) { if (s) {
|
||||
lo_send(m_audio_address,"/invert","i",1);
|
||||
} else {
|
||||
lo_send(m_audio_address,"/invert","i",0);
|
||||
}}
|
||||
void run_slot() {}
|
||||
void load_target() {
|
||||
m_last_file=QFileDialog::getOpenFileName(
|
||||
|
@ -88,6 +88,9 @@ void audio_thread::process(sample &s, sample &s2) {
|
||||
if (name=="/volume") {
|
||||
m_renderer->set_volume(cmd.get_float(0)*10);
|
||||
}
|
||||
if (name=="/invert") {
|
||||
m_renderer->set_invert(cmd.get_int(0));
|
||||
}
|
||||
if (name=="/record") {
|
||||
m_renderer->set_playing(true);
|
||||
m_audio_device->start_recording(cmd.get_string(0));
|
||||
|
@ -1,19 +1,20 @@
|
||||
/********************************************************************************
|
||||
** Form generated from reading UI file 'samplebrainB32443.ui'
|
||||
** Form generated from reading UI file 'samplebrainm32443.ui'
|
||||
**
|
||||
** Created: Tue Jul 21 15:50:16 2015
|
||||
** Created: Tue Jul 21 22:01:28 2015
|
||||
** by: Qt User Interface Compiler version 4.8.1
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef SAMPLEBRAINB32443_H
|
||||
#define SAMPLEBRAINB32443_H
|
||||
#ifndef SAMPLEBRAINM32443_H
|
||||
#define SAMPLEBRAINM32443_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QButtonGroup>
|
||||
#include <QtGui/QCheckBox>
|
||||
#include <QtGui/QDial>
|
||||
#include <QtGui/QDoubleSpinBox>
|
||||
#include <QtGui/QGridLayout>
|
||||
@ -59,6 +60,7 @@ public:
|
||||
QSpinBox *spinBoxFFT1Start;
|
||||
QLabel *label_10;
|
||||
QSpinBox *spinBoxFFT1End;
|
||||
QCheckBox *checkBoxInvert;
|
||||
QSpacerItem *verticalSpacer_3;
|
||||
QVBoxLayout *verticalLayout_6;
|
||||
QLabel *label_16;
|
||||
@ -264,6 +266,13 @@ public:
|
||||
|
||||
verticalLayout_3->addLayout(horizontalLayout_3);
|
||||
|
||||
checkBoxInvert = new QCheckBox(controlTab);
|
||||
checkBoxInvert->setObjectName(QString::fromUtf8("checkBoxInvert"));
|
||||
checkBoxInvert->setSizeIncrement(QSize(0, 0));
|
||||
checkBoxInvert->setIconSize(QSize(16, 16));
|
||||
|
||||
verticalLayout_3->addWidget(checkBoxInvert);
|
||||
|
||||
verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
|
||||
verticalLayout_3->addItem(verticalSpacer_3);
|
||||
@ -676,6 +685,7 @@ public:
|
||||
QObject::connect(sliderRatio, SIGNAL(valueChanged(int)), MainWindow, SLOT(ratio_slot(int)));
|
||||
QObject::connect(sliderNRatio, SIGNAL(valueChanged(int)), MainWindow, SLOT(n_ratio_slot(int)));
|
||||
QObject::connect(doubleSpinBoxNRatio, SIGNAL(valueChanged(double)), MainWindow, SLOT(n_ratio_slot(double)));
|
||||
QObject::connect(checkBoxInvert, SIGNAL(toggled(bool)), MainWindow, SLOT(invert_slot(bool)));
|
||||
|
||||
tabWidget->setCurrentIndex(0);
|
||||
|
||||
@ -692,6 +702,7 @@ public:
|
||||
label_7->setText(QApplication::translate("MainWindow", "fft subsection", 0, QApplication::UnicodeUTF8));
|
||||
label_9->setText(QApplication::translate("MainWindow", "Start", 0, QApplication::UnicodeUTF8));
|
||||
label_10->setText(QApplication::translate("MainWindow", "End", 0, QApplication::UnicodeUTF8));
|
||||
checkBoxInvert->setText(QApplication::translate("MainWindow", "invert", 0, QApplication::UnicodeUTF8));
|
||||
label_16->setText(QApplication::translate("MainWindow", "target sound", 0, QApplication::UnicodeUTF8));
|
||||
pushButtonLoadTarget->setText(QApplication::translate("MainWindow", "load target", 0, QApplication::UnicodeUTF8));
|
||||
label_17->setText(QApplication::translate("MainWindow", "block size", 0, QApplication::UnicodeUTF8));
|
||||
@ -743,4 +754,4 @@ namespace Ui {
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // SAMPLEBRAINB32443_H
|
||||
#endif // SAMPLEBRAINM32443_H
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <sndfile.h>
|
||||
#include <float.h>
|
||||
#include <jellyfish/audio.h>
|
||||
#include "brain.h"
|
||||
|
||||
@ -83,7 +84,7 @@ const block &brain::get_block(u32 index) const {
|
||||
|
||||
// returns index to block
|
||||
u32 brain::search(const block &target, const search_params ¶ms) const {
|
||||
double closest = 999999999;
|
||||
double closest = FLT_MAX;
|
||||
u32 closest_index = 0;
|
||||
u32 index = 0;
|
||||
for (vector<block>::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
||||
@ -97,6 +98,22 @@ u32 brain::search(const block &target, const search_params ¶ms) const {
|
||||
return closest_index;
|
||||
}
|
||||
|
||||
// returns index to block
|
||||
u32 brain::rev_search(const block &target, const search_params ¶ms) const {
|
||||
double furthest = 0;
|
||||
u32 furthest_index = 0;
|
||||
u32 index = 0;
|
||||
for (vector<block>::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
||||
double diff = target.compare(*i,params);
|
||||
if (diff>furthest) {
|
||||
furthest=diff;
|
||||
furthest_index = index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return furthest_index;
|
||||
}
|
||||
|
||||
// take another brain and rebuild this brain from bits of that one
|
||||
// (presumably this one is made from a single sample)
|
||||
void brain::resynth(const string &filename, const brain &other, const search_params ¶ms){
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
u32 get_overlap() const { return m_overlap; }
|
||||
|
||||
u32 search(const block &target, const search_params ¶ms) const;
|
||||
u32 rev_search(const block &target, const search_params ¶ms) const;
|
||||
|
||||
static bool unit_test();
|
||||
|
||||
|
@ -54,7 +54,12 @@ void renderer::process(u32 nframes, float *buf) {
|
||||
// get indices for current buffer
|
||||
for (u32 tgt_index = tgt_start; tgt_index<=tgt_end; tgt_index++) {
|
||||
u32 time=tgt_index*tgt_shift;
|
||||
u32 src_index = m_source.search(m_target.get_block(tgt_index), m_search_params);
|
||||
u32 src_index;
|
||||
if (!m_invert) {
|
||||
src_index = m_source.search(m_target.get_block(tgt_index), m_search_params);
|
||||
} else {
|
||||
src_index = m_source.rev_search(m_target.get_block(tgt_index), m_search_params);
|
||||
}
|
||||
// put them in the index list
|
||||
m_render_blocks.push_back(render_block(src_index,time));
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ renderer(brain &source, brain &target) :
|
||||
|
||||
void set_playing(bool s) { m_playing=s; }
|
||||
void set_volume(float s) { m_volume=s; }
|
||||
void set_invert(bool s) { m_invert=s; }
|
||||
search_params *get_params() { return &m_search_params; }
|
||||
|
||||
static bool unit_test();
|
||||
@ -58,7 +59,7 @@ private:
|
||||
search_params m_search_params;
|
||||
float m_volume;
|
||||
bool m_playing;
|
||||
|
||||
bool m_invert;
|
||||
std::list<render_block> m_render_blocks;
|
||||
u32 m_render_time;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user