stuff generally working..

This commit is contained in:
Dave Griffiths 2015-07-11 21:30:16 +01:00
parent 60689fd64c
commit 3f0936d7d5
10 changed files with 606 additions and 311 deletions

View File

@ -17,6 +17,13 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="currentIndex">
<number>0</number>
</property>
@ -26,7 +33,7 @@
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_19">
<property name="font">
@ -78,189 +85,211 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft &lt;-&gt; mfcc ratio</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="dialRatio">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxRatio">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.500000000000000</double>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft subsection 1</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft &lt;-&gt; mfcc ratio</string>
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="dialRatio">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
</widget>
<widget class="QSpinBox" name="spinBoxFFT1Start"/>
</item>
</layout>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxRatio"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="label_10">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft subsection 1</string>
<string>End</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT1Start"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_10">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>End</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT1End"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft subsection 2</string>
<widget class="QSpinBox" name="spinBoxFFT1End">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT2Start"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_12">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>End</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT2End"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>323</width>
<height>511</height>
</size>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft subsection 2</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT2Start"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_12">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>End</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFFT2End">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<widget class="QLabel" name="label_13">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLabel" name="label_13">
<widget class="QDial" name="dialVolume">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRestartAudio">
<property name="font">
<font>
<family>Comic Sans MS</family>
@ -269,14 +298,7 @@
</font>
</property>
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="dialVolume">
<property name="value">
<number>99</number>
<string>restart audio</string>
</property>
</widget>
</item>
@ -346,7 +368,14 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockSizeTarget"/>
<widget class="QSpinBox" name="spinBoxBlockSizeTarget">
<property name="maximum">
<number>99999</number>
</property>
<property name="value">
<number>3000</number>
</property>
</widget>
</item>
</layout>
</item>
@ -367,7 +396,17 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockOverlapTarget"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxBlockOverlapTarget">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.750000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
@ -381,7 +420,7 @@
</font>
</property>
<property name="text">
<string>generate blocks</string>
<string>(re)generate blocks</string>
</property>
</widget>
</item>
@ -441,7 +480,14 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockSize"/>
<widget class="QSpinBox" name="spinBoxBlockSize">
<property name="maximum">
<number>99999</number>
</property>
<property name="value">
<number>3000</number>
</property>
</widget>
</item>
</layout>
</item>
@ -462,7 +508,17 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockOverlap"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxBlockOverlap">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.750000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
@ -497,7 +553,7 @@
</font>
</property>
<property name="text">
<string>generate</string>
<string>(re)generate</string>
</property>
</widget>
</item>
@ -583,6 +639,34 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDeleteSound">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>delete selected</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonClearBrain">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>clear brain</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -757,22 +841,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxBlockOverlapTarget</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>target_block_overlap(int)</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>169</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonGenerateTarget</sender>
<signal>released()</signal>
@ -805,22 +873,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxBlockOverlap</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>block_overlap(int)</slot>
<hints>
<hint type="sourcelabel">
<x>188</x>
<y>138</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxSpectSize</sender>
<signal>valueChanged(int)</signal>
@ -885,6 +937,86 @@
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBoxBlockOverlap</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>block_overlap(double)</slot>
<hints>
<hint type="sourcelabel">
<x>188</x>
<y>138</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBoxBlockOverlapTarget</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>target_block_overlap(double)</slot>
<hints>
<hint type="sourcelabel">
<x>619</x>
<y>196</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonClearBrain</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>clear_brain()</slot>
<hints>
<hint type="sourcelabel">
<x>590</x>
<y>544</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonDeleteSound</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>delete_sound()</slot>
<hints>
<hint type="sourcelabel">
<x>476</x>
<y>544</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonRestartAudio</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>restart_audio()</slot>
<hints>
<hint type="sourcelabel">
<x>274</x>
<y>533</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>play_slot()</slot>
@ -898,7 +1030,7 @@
<slot>volume_slot(int)</slot>
<slot>run_slot()</slot>
<slot>block_size(int)</slot>
<slot>block_overlap(int)</slot>
<slot>block_overlap(double)</slot>
<slot>fft_spectrum_size(int)</slot>
<slot>generate()</slot>
<slot>load_sound()</slot>
@ -906,7 +1038,9 @@
<slot>slot2()</slot>
<slot>load_target()</slot>
<slot>target_block_size(int)</slot>
<slot>target_block_overlap(int)</slot>
<slot>target_block_overlap(double)</slot>
<slot>generate_target_blocks()</slot>
<slot>clear_brain()</slot>
<slot>restart_audio()</slot>
</slots>
</ui>

View File

@ -4,6 +4,8 @@
#include <iostream>
#include <lo/lo.h>
using namespace std;
class MainWindow : public QMainWindow
{
Q_OBJECT
@ -17,8 +19,8 @@ protected:
private slots:
void play_slot() { lo_send(m_process_address,"/init",""); }
void stop_slot() {} //{ m_renderer->set_playing(false); }
void play_slot() { lo_send(m_audio_address,"/start",""); }
void stop_slot() { lo_send(m_audio_address,"/stop",""); }
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); }
@ -27,15 +29,47 @@ private slots:
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) {}
void target_block_overlap(int) {}
void generate_target_blocks() {}
void block_size(int) {}
void block_overlap(int) {}
void load_target() {
QString s=QFileDialog::getOpenFileName(
this,
QString("Select an wav file"),
".",
QString("Sounds (*.wav)"));
lo_send(m_process_address,"/load_target","s",s.toStdString().c_str());
}
void target_block_size(int s) { lo_send(m_process_address,"/target_block_size","i",s); }
void target_block_overlap(double s) { lo_send(m_process_address,"/target_overlap","f",s); }
void generate_target_blocks() { lo_send(m_process_address,"/generate_target",""); }
void block_size(int s) { lo_send(m_process_address,"/source_block_size","i",s); }
void block_overlap(double s) { lo_send(m_process_address,"/source_overlap","f",s); }
void fft_spectrum_size(int) {}
void generate() {}
void load_sound() {}
void generate() { lo_send(m_process_address,"/generate_brain",""); }
void load_sound() {
QString s=QFileDialog::getOpenFileName(
this,
QString("Select an wav file"),
".",
QString("Sounds (*.wav)"));
lo_send(m_process_address,"/load_sample","s",s.toStdString().c_str());
m_Ui.listWidgetSounds->addItem(s);
}
void delete_sound() {
QList<QListWidgetItem *> itemList = m_Ui.listWidgetSounds->selectedItems();
for (int i=0; i<itemList.size(); i++) {
lo_send(m_process_address,"/delete_sample","s",itemList[i]->text().toStdString().c_str());
}
qDeleteAll(m_Ui.listWidgetSounds->selectedItems());
}
void clear_brain() {
for (int i=0; i<m_Ui.listWidgetSounds->count(); i++) {
lo_send(m_process_address,"/delete_sample","s",m_Ui.listWidgetSounds->item(i)->text().toStdString().c_str());
}
m_Ui.listWidgetSounds->clear();
}
void restart_audio() { lo_send(m_audio_address,"/restart_audio",""); }
private:
Ui_MainWindow m_Ui;

View File

@ -5,6 +5,7 @@ using namespace spiralcore;
using namespace std;
audio_thread::audio_thread(process_thread &p) :
m_audio_device(NULL),
m_process_thread(p),
m_brain_mutex(p.m_brain_mutex),
m_osc("8888")
@ -13,6 +14,19 @@ audio_thread::audio_thread(process_thread &p) :
m_renderer = new renderer(p.m_source,p.m_target);
pthread_mutex_unlock(m_brain_mutex);
m_osc.run();
start_audio();
}
void audio_thread::start_audio() {
if (m_audio_device!=NULL) delete m_audio_device;
m_audio_device = new audio_device("samplebrain",44100,2048);
m_audio_device->m_client.set_callback(run_audio, this);
}
void audio_thread::run_audio(void* c, unsigned int frames) {
audio_thread *at = (audio_thread*)c;
at->m_audio_device->left_out.zero();
at->process(at->m_audio_device->left_out);
}
void audio_thread::process(sample &s) {
@ -21,12 +35,32 @@ void audio_thread::process(sample &s) {
while (m_osc.get(cmd)) {
string name = cmd.m_name;
cerr<<name<<endl;
if (name=="/start") {
m_renderer->set_playing(true);
}
if (name=="/stop") {
m_renderer->set_playing(false);
}
if (name=="/ratio") {
m_renderer->get_params()->m_ratio = cmd.get_float(0);
}
if (name=="/fft1_start") {
m_renderer->get_params()->m_fft1_start = cmd.get_int(0);
}
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=="/restart_audio") {
start_audio();
}
}
s.zero();
if (!pthread_mutex_trylock(m_brain_mutex)) {
m_renderer->process(s.get_length(),s.get_non_const_buffer());

View File

@ -1,6 +1,7 @@
#include "jellyfish/fluxa/OSC_server.h"
#include "process_thread.h"
#include "renderer.h"
#include "jellyfish/audio.h"
#pragma once
@ -11,7 +12,11 @@ public:
audio_thread(process_thread &p);
void process(sample &s);
static void run_audio(void* c, unsigned int frames);
audio_device *m_audio_device;
private:
void start_audio();
renderer *m_renderer;
OSC_server m_osc;

View File

@ -1,14 +1,14 @@
/********************************************************************************
** Form generated from reading UI file 'samplebrainxS5241.ui'
** Form generated from reading UI file 'samplebrainHz5241.ui'
**
** Created: Sat Jul 11 12:25:49 2015
** Created: Sat Jul 11 20:24:05 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 SAMPLEBRAINXS5241_H
#define SAMPLEBRAINXS5241_H
#ifndef SAMPLEBRAINHZ5241_H
#define SAMPLEBRAINHZ5241_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
@ -39,12 +39,11 @@ public:
QTabWidget *tabWidget;
QWidget *controlTab;
QHBoxLayout *horizontalLayout_15;
QVBoxLayout *verticalLayout_7;
QVBoxLayout *verticalLayout_3;
QLabel *label_19;
QHBoxLayout *horizontalLayout_12;
QPushButton *pushButtonPlay;
QPushButton *pushButtonStop;
QVBoxLayout *verticalLayout_3;
QHBoxLayout *horizontalLayout_16;
QLabel *label_6;
QDial *dialRatio;
@ -65,10 +64,10 @@ public:
QHBoxLayout *horizontalLayout_11;
QLabel *label_12;
QSpinBox *spinBoxFFT2End;
QSpacerItem *verticalSpacer_3;
QVBoxLayout *verticalLayout_6;
QLabel *label_13;
QHBoxLayout *horizontalLayout_17;
QDial *dialVolume;
QPushButton *pushButtonRestartAudio;
QVBoxLayout *verticalLayout_9;
QLabel *label_16;
QLabel *label_15;
@ -78,7 +77,7 @@ public:
QSpinBox *spinBoxBlockSizeTarget;
QHBoxLayout *horizontalLayout_14;
QLabel *label_18;
QSpinBox *spinBoxBlockOverlapTarget;
QDoubleSpinBox *doubleSpinBoxBlockOverlapTarget;
QPushButton *pushButtonGenerateTarget;
QSpacerItem *verticalSpacer;
QWidget *sampleTab;
@ -90,7 +89,7 @@ public:
QSpinBox *spinBoxBlockSize;
QHBoxLayout *horizontalLayout_6;
QLabel *label_2;
QSpinBox *spinBoxBlockOverlap;
QDoubleSpinBox *doubleSpinBoxBlockOverlap;
QHBoxLayout *horizontalLayout_5;
QLabel *label_4;
QSpinBox *spinBoxSpectSize;
@ -104,6 +103,8 @@ public:
QListWidget *listWidgetSounds;
QHBoxLayout *horizontalLayout_2;
QPushButton *pushButtonLoadSound;
QPushButton *pushButtonDeleteSound;
QPushButton *pushButtonClearBrain;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
@ -117,47 +118,46 @@ public:
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
tabWidget = new QTabWidget(centralwidget);
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
QFont font;
font.setFamily(QString::fromUtf8("Comic Sans MS"));
font.setBold(true);
font.setWeight(75);
tabWidget->setFont(font);
controlTab = new QWidget();
controlTab->setObjectName(QString::fromUtf8("controlTab"));
horizontalLayout_15 = new QHBoxLayout(controlTab);
horizontalLayout_15->setObjectName(QString::fromUtf8("horizontalLayout_15"));
verticalLayout_7 = new QVBoxLayout();
verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7"));
verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
label_19 = new QLabel(controlTab);
label_19->setObjectName(QString::fromUtf8("label_19"));
QFont font;
font.setFamily(QString::fromUtf8("Comic Sans MS"));
font.setPointSize(20);
font.setBold(true);
font.setWeight(75);
label_19->setFont(font);
QFont font1;
font1.setFamily(QString::fromUtf8("Comic Sans MS"));
font1.setPointSize(20);
font1.setBold(true);
font1.setWeight(75);
label_19->setFont(font1);
verticalLayout_7->addWidget(label_19);
verticalLayout_3->addWidget(label_19);
horizontalLayout_12 = new QHBoxLayout();
horizontalLayout_12->setObjectName(QString::fromUtf8("horizontalLayout_12"));
pushButtonPlay = new QPushButton(controlTab);
pushButtonPlay->setObjectName(QString::fromUtf8("pushButtonPlay"));
QFont font1;
font1.setFamily(QString::fromUtf8("Comic Sans MS"));
font1.setBold(true);
font1.setWeight(75);
pushButtonPlay->setFont(font1);
pushButtonPlay->setFont(font);
pushButtonPlay->setFlat(false);
horizontalLayout_12->addWidget(pushButtonPlay);
pushButtonStop = new QPushButton(controlTab);
pushButtonStop->setObjectName(QString::fromUtf8("pushButtonStop"));
pushButtonStop->setFont(font1);
pushButtonStop->setFont(font);
horizontalLayout_12->addWidget(pushButtonStop);
verticalLayout_7->addLayout(horizontalLayout_12);
verticalLayout_3->addLayout(horizontalLayout_12);
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);
@ -188,6 +188,9 @@ public:
doubleSpinBoxRatio = new QDoubleSpinBox(controlTab);
doubleSpinBoxRatio->setObjectName(QString::fromUtf8("doubleSpinBoxRatio"));
doubleSpinBoxRatio->setMaximum(1);
doubleSpinBoxRatio->setSingleStep(0.01);
doubleSpinBoxRatio->setValue(0.5);
verticalLayout_3->addWidget(doubleSpinBoxRatio);
@ -203,7 +206,7 @@ public:
horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
label_9 = new QLabel(controlTab);
label_9->setObjectName(QString::fromUtf8("label_9"));
label_9->setFont(font1);
label_9->setFont(font);
horizontalLayout_3->addWidget(label_9);
@ -219,12 +222,13 @@ public:
horizontalLayout_9->setObjectName(QString::fromUtf8("horizontalLayout_9"));
label_10 = new QLabel(controlTab);
label_10->setObjectName(QString::fromUtf8("label_10"));
label_10->setFont(font1);
label_10->setFont(font);
horizontalLayout_9->addWidget(label_10);
spinBoxFFT1End = new QSpinBox(controlTab);
spinBoxFFT1End->setObjectName(QString::fromUtf8("spinBoxFFT1End"));
spinBoxFFT1End->setValue(99);
horizontalLayout_9->addWidget(spinBoxFFT1End);
@ -246,7 +250,7 @@ public:
horizontalLayout_10->setObjectName(QString::fromUtf8("horizontalLayout_10"));
label_11 = new QLabel(controlTab);
label_11->setObjectName(QString::fromUtf8("label_11"));
label_11->setFont(font1);
label_11->setFont(font);
horizontalLayout_10->addWidget(label_11);
@ -262,12 +266,13 @@ public:
horizontalLayout_11->setObjectName(QString::fromUtf8("horizontalLayout_11"));
label_12 = new QLabel(controlTab);
label_12->setObjectName(QString::fromUtf8("label_12"));
label_12->setFont(font1);
label_12->setFont(font);
horizontalLayout_11->addWidget(label_12);
spinBoxFFT2End = new QSpinBox(controlTab);
spinBoxFFT2End->setObjectName(QString::fromUtf8("spinBoxFFT2End"));
spinBoxFFT2End->setValue(99);
horizontalLayout_11->addWidget(spinBoxFFT2End);
@ -277,50 +282,49 @@ public:
verticalLayout_3->addLayout(verticalLayout_5);
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);
label_13->setObjectName(QString::fromUtf8("label_13"));
label_13->setFont(font1);
label_13->setFont(font);
verticalLayout_6->addWidget(label_13);
verticalLayout_3->addWidget(label_13);
horizontalLayout_17 = new QHBoxLayout();
horizontalLayout_17->setObjectName(QString::fromUtf8("horizontalLayout_17"));
dialVolume = new QDial(controlTab);
dialVolume->setObjectName(QString::fromUtf8("dialVolume"));
dialVolume->setValue(99);
verticalLayout_6->addWidget(dialVolume);
horizontalLayout_17->addWidget(dialVolume);
pushButtonRestartAudio = new QPushButton(controlTab);
pushButtonRestartAudio->setObjectName(QString::fromUtf8("pushButtonRestartAudio"));
pushButtonRestartAudio->setFont(font);
horizontalLayout_17->addWidget(pushButtonRestartAudio);
verticalLayout_7->addLayout(verticalLayout_6);
verticalLayout_3->addLayout(horizontalLayout_17);
horizontalLayout_15->addLayout(verticalLayout_7);
horizontalLayout_15->addLayout(verticalLayout_3);
verticalLayout_9 = new QVBoxLayout();
verticalLayout_9->setObjectName(QString::fromUtf8("verticalLayout_9"));
label_16 = new QLabel(controlTab);
label_16->setObjectName(QString::fromUtf8("label_16"));
label_16->setFont(font);
label_16->setFont(font1);
verticalLayout_9->addWidget(label_16);
label_15 = new QLabel(controlTab);
label_15->setObjectName(QString::fromUtf8("label_15"));
label_15->setFont(font1);
label_15->setFont(font);
verticalLayout_9->addWidget(label_15);
pushButtonLoadTarget = new QPushButton(controlTab);
pushButtonLoadTarget->setObjectName(QString::fromUtf8("pushButtonLoadTarget"));
pushButtonLoadTarget->setFont(font1);
pushButtonLoadTarget->setFont(font);
verticalLayout_9->addWidget(pushButtonLoadTarget);
@ -328,12 +332,14 @@ public:
horizontalLayout_13->setObjectName(QString::fromUtf8("horizontalLayout_13"));
label_17 = new QLabel(controlTab);
label_17->setObjectName(QString::fromUtf8("label_17"));
label_17->setFont(font1);
label_17->setFont(font);
horizontalLayout_13->addWidget(label_17);
spinBoxBlockSizeTarget = new QSpinBox(controlTab);
spinBoxBlockSizeTarget->setObjectName(QString::fromUtf8("spinBoxBlockSizeTarget"));
spinBoxBlockSizeTarget->setMaximum(99999);
spinBoxBlockSizeTarget->setValue(3000);
horizontalLayout_13->addWidget(spinBoxBlockSizeTarget);
@ -344,21 +350,24 @@ public:
horizontalLayout_14->setObjectName(QString::fromUtf8("horizontalLayout_14"));
label_18 = new QLabel(controlTab);
label_18->setObjectName(QString::fromUtf8("label_18"));
label_18->setFont(font1);
label_18->setFont(font);
horizontalLayout_14->addWidget(label_18);
spinBoxBlockOverlapTarget = new QSpinBox(controlTab);
spinBoxBlockOverlapTarget->setObjectName(QString::fromUtf8("spinBoxBlockOverlapTarget"));
doubleSpinBoxBlockOverlapTarget = new QDoubleSpinBox(controlTab);
doubleSpinBoxBlockOverlapTarget->setObjectName(QString::fromUtf8("doubleSpinBoxBlockOverlapTarget"));
doubleSpinBoxBlockOverlapTarget->setMaximum(1);
doubleSpinBoxBlockOverlapTarget->setSingleStep(0.01);
doubleSpinBoxBlockOverlapTarget->setValue(0.75);
horizontalLayout_14->addWidget(spinBoxBlockOverlapTarget);
horizontalLayout_14->addWidget(doubleSpinBoxBlockOverlapTarget);
verticalLayout_9->addLayout(horizontalLayout_14);
pushButtonGenerateTarget = new QPushButton(controlTab);
pushButtonGenerateTarget->setObjectName(QString::fromUtf8("pushButtonGenerateTarget"));
pushButtonGenerateTarget->setFont(font1);
pushButtonGenerateTarget->setFont(font);
verticalLayout_9->addWidget(pushButtonGenerateTarget);
@ -378,7 +387,7 @@ public:
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
label_3 = new QLabel(sampleTab);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setFont(font);
label_3->setFont(font1);
verticalLayout_2->addWidget(label_3);
@ -386,12 +395,14 @@ public:
horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
label = new QLabel(sampleTab);
label->setObjectName(QString::fromUtf8("label"));
label->setFont(font1);
label->setFont(font);
horizontalLayout_4->addWidget(label);
spinBoxBlockSize = new QSpinBox(sampleTab);
spinBoxBlockSize->setObjectName(QString::fromUtf8("spinBoxBlockSize"));
spinBoxBlockSize->setMaximum(99999);
spinBoxBlockSize->setValue(3000);
horizontalLayout_4->addWidget(spinBoxBlockSize);
@ -402,14 +413,17 @@ public:
horizontalLayout_6->setObjectName(QString::fromUtf8("horizontalLayout_6"));
label_2 = new QLabel(sampleTab);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setFont(font1);
label_2->setFont(font);
horizontalLayout_6->addWidget(label_2);
spinBoxBlockOverlap = new QSpinBox(sampleTab);
spinBoxBlockOverlap->setObjectName(QString::fromUtf8("spinBoxBlockOverlap"));
doubleSpinBoxBlockOverlap = new QDoubleSpinBox(sampleTab);
doubleSpinBoxBlockOverlap->setObjectName(QString::fromUtf8("doubleSpinBoxBlockOverlap"));
doubleSpinBoxBlockOverlap->setMaximum(1);
doubleSpinBoxBlockOverlap->setSingleStep(0.01);
doubleSpinBoxBlockOverlap->setValue(0.75);
horizontalLayout_6->addWidget(spinBoxBlockOverlap);
horizontalLayout_6->addWidget(doubleSpinBoxBlockOverlap);
verticalLayout_2->addLayout(horizontalLayout_6);
@ -418,7 +432,7 @@ public:
horizontalLayout_5->setObjectName(QString::fromUtf8("horizontalLayout_5"));
label_4 = new QLabel(sampleTab);
label_4->setObjectName(QString::fromUtf8("label_4"));
label_4->setFont(font1);
label_4->setFont(font);
horizontalLayout_5->addWidget(label_4);
@ -432,7 +446,7 @@ public:
pushButtonGenerate = new QPushButton(sampleTab);
pushButtonGenerate->setObjectName(QString::fromUtf8("pushButtonGenerate"));
pushButtonGenerate->setFont(font1);
pushButtonGenerate->setFont(font);
verticalLayout_2->addWidget(pushButtonGenerate);
@ -440,13 +454,13 @@ public:
horizontalLayout_7->setObjectName(QString::fromUtf8("horizontalLayout_7"));
pushButtonLosdBrain = new QPushButton(sampleTab);
pushButtonLosdBrain->setObjectName(QString::fromUtf8("pushButtonLosdBrain"));
pushButtonLosdBrain->setFont(font1);
pushButtonLosdBrain->setFont(font);
horizontalLayout_7->addWidget(pushButtonLosdBrain);
pushButtonSaveBrain = new QPushButton(sampleTab);
pushButtonSaveBrain->setObjectName(QString::fromUtf8("pushButtonSaveBrain"));
pushButtonSaveBrain->setFont(font1);
pushButtonSaveBrain->setFont(font);
horizontalLayout_7->addWidget(pushButtonSaveBrain);
@ -464,7 +478,7 @@ public:
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
label_5 = new QLabel(sampleTab);
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setFont(font1);
label_5->setFont(font);
verticalLayout->addWidget(label_5);
@ -477,10 +491,22 @@ public:
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
pushButtonLoadSound = new QPushButton(sampleTab);
pushButtonLoadSound->setObjectName(QString::fromUtf8("pushButtonLoadSound"));
pushButtonLoadSound->setFont(font1);
pushButtonLoadSound->setFont(font);
horizontalLayout_2->addWidget(pushButtonLoadSound);
pushButtonDeleteSound = new QPushButton(sampleTab);
pushButtonDeleteSound->setObjectName(QString::fromUtf8("pushButtonDeleteSound"));
pushButtonDeleteSound->setFont(font);
horizontalLayout_2->addWidget(pushButtonDeleteSound);
pushButtonClearBrain = new QPushButton(sampleTab);
pushButtonClearBrain->setObjectName(QString::fromUtf8("pushButtonClearBrain"));
pushButtonClearBrain->setFont(font);
horizontalLayout_2->addWidget(pushButtonClearBrain);
verticalLayout->addLayout(horizontalLayout_2);
@ -507,14 +533,17 @@ public:
QObject::connect(spinBoxFFT2End, SIGNAL(valueChanged(int)), MainWindow, SLOT(fft2_end_slot(int)));
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)));
QObject::connect(pushButtonGenerateTarget, SIGNAL(released()), MainWindow, SLOT(generate_target_blocks()));
QObject::connect(spinBoxBlockSize, SIGNAL(valueChanged(int)), MainWindow, SLOT(block_size(int)));
QObject::connect(spinBoxBlockOverlap, SIGNAL(valueChanged(int)), MainWindow, SLOT(block_overlap(int)));
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)));
QObject::connect(doubleSpinBoxBlockOverlap, SIGNAL(valueChanged(double)), MainWindow, SLOT(block_overlap(double)));
QObject::connect(doubleSpinBoxBlockOverlapTarget, SIGNAL(valueChanged(double)), MainWindow, SLOT(target_block_overlap(double)));
QObject::connect(pushButtonClearBrain, SIGNAL(released()), MainWindow, SLOT(clear_brain()));
QObject::connect(pushButtonDeleteSound, SIGNAL(released()), MainWindow, SLOT(delete_sound()));
QObject::connect(pushButtonRestartAudio, SIGNAL(released()), MainWindow, SLOT(restart_audio()));
tabWidget->setCurrentIndex(0);
@ -536,22 +565,25 @@ public:
label_11->setText(QApplication::translate("MainWindow", "Start", 0, QApplication::UnicodeUTF8));
label_12->setText(QApplication::translate("MainWindow", "End", 0, QApplication::UnicodeUTF8));
label_13->setText(QApplication::translate("MainWindow", "Volume", 0, QApplication::UnicodeUTF8));
pushButtonRestartAudio->setText(QApplication::translate("MainWindow", "restart audio", 0, QApplication::UnicodeUTF8));
label_16->setText(QApplication::translate("MainWindow", "target sound", 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));
pushButtonGenerateTarget->setText(QApplication::translate("MainWindow", "(re)generate blocks", 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));
label_2->setText(QApplication::translate("MainWindow", "block overlap", 0, QApplication::UnicodeUTF8));
label_4->setText(QApplication::translate("MainWindow", "fft spectrum size", 0, QApplication::UnicodeUTF8));
pushButtonGenerate->setText(QApplication::translate("MainWindow", "generate", 0, QApplication::UnicodeUTF8));
pushButtonGenerate->setText(QApplication::translate("MainWindow", "(re)generate", 0, QApplication::UnicodeUTF8));
pushButtonLosdBrain->setText(QApplication::translate("MainWindow", "load", 0, QApplication::UnicodeUTF8));
pushButtonSaveBrain->setText(QApplication::translate("MainWindow", "save", 0, QApplication::UnicodeUTF8));
label_5->setText(QApplication::translate("MainWindow", "brain contents", 0, QApplication::UnicodeUTF8));
pushButtonLoadSound->setText(QApplication::translate("MainWindow", "load sound", 0, QApplication::UnicodeUTF8));
pushButtonDeleteSound->setText(QApplication::translate("MainWindow", "delete selected", 0, QApplication::UnicodeUTF8));
pushButtonClearBrain->setText(QApplication::translate("MainWindow", "clear brain", 0, QApplication::UnicodeUTF8));
tabWidget->setTabText(tabWidget->indexOf(sampleTab), QApplication::translate("MainWindow", "brain", 0, QApplication::UnicodeUTF8));
} // retranslateUi
@ -563,4 +595,4 @@ namespace Ui {
QT_END_NAMESPACE
#endif // SAMPLEBRAINXS5241_H
#endif // SAMPLEBRAINHZ5241_H

View File

@ -4,8 +4,18 @@
using namespace spiralcore;
using namespace std;
static void _process(void *c) {
process_thread *p=(process_thread*)c;
p->process();
}
process_thread::process_thread() :
m_osc("8889")
m_osc("8889"),
m_source_block_size(3000),
m_source_overlap(0.75),
m_target_block_size(3000),
m_target_overlap(0.75),
m_env(50)
{
m_brain_mutex = new pthread_mutex_t;
pthread_mutex_init(m_brain_mutex,NULL);
@ -13,20 +23,57 @@ process_thread::process_thread() :
// start the processing thread
pthread_t *thread = new pthread_t;
pthread_create(thread,NULL,(void*(*)(void*))process_thread::process,this);
pthread_create(thread,NULL,(void*(*)(void*))_process,this);
}
void process_thread::process(void *c) {
process_thread *p=(process_thread*)c;
void process_thread::process() {
command_ring_buffer::command cmd;
while(true) {
while (p->m_osc.get(cmd)) {
while (m_osc.get(cmd)) {
string name = cmd.m_name;
cerr<<name<<endl;
if (name=="/init") {
p->init_brain();
init_brain();
}
if (name=="/load_sample") {
pthread_mutex_lock(m_brain_mutex);
m_source.load_sound(cmd.get_string(0));
pthread_mutex_unlock(m_brain_mutex);
}
if (name=="/delete_sample") {
pthread_mutex_lock(m_brain_mutex);
m_source.delete_sound(cmd.get_string(0));
pthread_mutex_unlock(m_brain_mutex);
}
if (name=="/source_block_size") {
m_source_block_size = cmd.get_int(0);
}
if (name=="/source_overlap") {
m_source_overlap = m_source_block_size-m_source_block_size/cmd.get_float(0);
}
if (name=="/generate_brain") {
pthread_mutex_lock(m_brain_mutex);
m_source.init(m_source_block_size, m_source_overlap, m_env);
pthread_mutex_unlock(m_brain_mutex);
}
if (name=="/load_target") {
pthread_mutex_lock(m_brain_mutex);
m_target.clear_sounds();
m_target.load_sound(cmd.get_string(0));
pthread_mutex_unlock(m_brain_mutex);
}
if (name=="/target_block_size") {
m_target_block_size = cmd.get_int(0);
}
if (name=="/target_overlap") {
m_target_overlap = m_target_block_size-m_target_block_size/cmd.get_float(0);
}
if (name=="/generate_target") {
pthread_mutex_lock(m_brain_mutex);
m_target.init(m_target_block_size, m_target_overlap, m_env);
pthread_mutex_unlock(m_brain_mutex);
}
}
usleep(500);
@ -34,6 +81,7 @@ void process_thread::process(void *c) {
}
void process_thread::init_brain() {
pthread_mutex_lock(m_brain_mutex);

View File

@ -14,9 +14,15 @@ public:
brain m_source, m_target;
pthread_mutex_t* m_brain_mutex;
void process();
private:
static void process(void *c);
OSC_server m_osc;
u32 m_source_block_size;
float m_source_overlap;
u32 m_target_block_size;
float m_target_overlap;
float m_env;
};
}

View File

@ -5,21 +5,11 @@
#include <QtGui>
#include "MainWindow.h"
#include "jellyfish/audio.h"
#include "process_thread.h"
#include "audio_thread.h"
using namespace std;
audio_device *a = NULL;
void run_audio(void* c, unsigned int frames) {
audio_thread *at = (audio_thread*)c;
a->left_out.zero();
at->process(a->left_out);
}
int main( int argc , char *argv[] ){
QApplication app(argc, argv);
MainWindow mainWin;
@ -28,8 +18,5 @@ int main( int argc , char *argv[] ){
process_thread pt;
audio_thread at(pt);
a = new audio_device("samplebrain",44100,2048);
a->m_client.set_callback(run_audio, &at);
return app.exec();
}

View File

@ -11,15 +11,24 @@ brain::brain()
// load, chop up and add to brain
// todo: add tags
sample brain::load_sound(std::string filename) {
void brain::load_sound(std::string filename) {
SF_INFO sfinfo;
sfinfo.format=0;
SNDFILE* f=sf_open(filename.c_str(), SFM_READ, &sfinfo);
sample s(sfinfo.frames);
sf_readf_float(f, s.get_non_const_buffer(), s.get_length());
sf_close(f);
m_samples.push_back(s);
return s;
if (f!=NULL) {
sample s(sfinfo.frames);
sf_readf_float(f, s.get_non_const_buffer(), s.get_length());
m_samples.push_back(sound(filename,s));
}
}
void brain::delete_sound(std::string filename) {
for (std::list<sound>::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) {
if (i->m_filename==filename) {
m_samples.erase(i);
return;
}
}
}
void save_sample(const string &filename, const sample s) {
@ -42,8 +51,8 @@ void brain::init(u32 block_size, u32 overlap, u32 env, bool ditchpcm) {
m_blocks.clear();
m_block_size = block_size;
m_overlap = overlap;
for (vector<sample>::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) {
chop_and_add(*i, block_size, overlap, env, ditchpcm);
for (std::list<sound>::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) {
chop_and_add(i->m_sample, block_size, overlap, env, ditchpcm);
}
}
@ -115,16 +124,10 @@ bool brain::unit_test() {
assert(b.m_samples.size()==0);
assert(b.m_blocks.size()==0);
sample s=b.load_sound("test_data/100f32.wav");
assert(b.m_samples.size()==1);
assert(s.get_length()==100);
s=b.load_sound("test_data/100i16.wav");
b.load_sound("test_data/100f32.wav");
b.load_sound("test_data/100i16.wav");
assert(b.m_samples.size()==2);
assert(s.get_length()==100);
b.init(10, 0, 0);
assert(b.m_samples.size()==2);
assert(b.m_blocks.size()==20);
b.init(10, 5, 0);
assert(b.m_samples.size()==2);

View File

@ -1,3 +1,4 @@
#include <list>
#include <vector>
#include <string>
#include "jellyfish/core/types.h"
@ -17,9 +18,20 @@ public:
// rewrites whole brain
void init(u32 block_size, u32 overlap, u32 env, bool ditchpcm=false);
class sound {
public:
sound(const std::string &name, const sample &sample) :
m_filename(name), m_sample(sample) {}
std::string m_filename;
sample m_sample;
};
// load, chop up and add to brain
// todo: add tags
sample load_sound(std::string filename);
void load_sound(std::string filename);
void delete_sound(std::string filename);
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 &params);
@ -39,7 +51,7 @@ private:
void chop_and_add(const sample &s, u32 block_size, u32 overlap, u32 env, bool ditchpcm=false);
vector<block> m_blocks;
vector<sample> m_samples;
std::list<sound> m_samples;
u32 m_block_size;
u32 m_overlap;