loadsa threads and osc

This commit is contained in:
Dave Griffiths 2015-07-11 19:03:05 +01:00
parent f6f6fcdc2d
commit 60689fd64c
14 changed files with 1211 additions and 63 deletions

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormSample</class>
<widget class="QWidget" name="FormSample">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>46</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>active</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSampleName">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSampleInfo">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>delete</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,912 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>724</width>
<height>603</height>
</rect>
</property>
<property name="windowTitle">
<string>samplebrain 0.0.3</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="controlTab">
<attribute name="title">
<string>search</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label_19">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>tweakage</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QPushButton" name="pushButtonPlay">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonStop">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<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"/>
</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_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>
</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>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<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>
<widget class="QDial" name="dialVolume">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label_16">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>target sound</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>no sound yet...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonLoadTarget">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>load target</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_17">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>block size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockSizeTarget"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QLabel" name="label_18">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>block overlap</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockOverlapTarget"/>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonGenerateTarget">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>generate blocks</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="sampleTab">
<attribute name="title">
<string>brain</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<family>Comic Sans MS</family>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>brain parameters</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>block size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockSize"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>block overlap</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxBlockOverlap"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fft spectrum size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxSpectSize"/>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonGenerate">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>generate</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QPushButton" name="pushButtonLosdBrain">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>load</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSaveBrain">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>brain contents</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetSounds"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButtonLoadSound">
<property name="font">
<font>
<family>Comic Sans MS</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>load sound</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButtonPlay</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>play_slot()</slot>
<hints>
<hint type="sourcelabel">
<x>64</x>
<y>62</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonStop</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>stop_slot()</slot>
<hints>
<hint type="sourcelabel">
<x>155</x>
<y>62</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>dialRatio</sender>
<signal>sliderMoved(int)</signal>
<receiver>MainWindow</receiver>
<slot>ratio_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>109</x>
<y>154</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>doubleSpinBoxRatio</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>ratio_slot(double)</slot>
<hints>
<hint type="sourcelabel">
<x>109</x>
<y>223</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxFFT1Start</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>fft1_start_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>154</x>
<y>277</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxFFT1End</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>fft1_end_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>154</x>
<y>310</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxFFT2Start</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>fft2_start_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>154</x>
<y>366</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxFFT2End</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>fft2_end_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>154</x>
<y>399</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonLoadTarget</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>load_target()</slot>
<hints>
<hint type="sourcelabel">
<x>277</x>
<y>103</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxBlockSizeTarget</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>target_block_size(int)</slot>
<hints>
<hint type="sourcelabel">
<x>313</x>
<y>136</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</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>
<receiver>MainWindow</receiver>
<slot>generate_target_blocks()</slot>
<hints>
<hint type="sourcelabel">
<x>277</x>
<y>202</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>spinBoxBlockSize</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>block_size(int)</slot>
<hints>
<hint type="sourcelabel">
<x>188</x>
<y>105</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</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>
<receiver>MainWindow</receiver>
<slot>fft_spectrum_size(int)</slot>
<hints>
<hint type="sourcelabel">
<x>188</x>
<y>171</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonGenerate</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>generate()</slot>
<hints>
<hint type="sourcelabel">
<x>131</x>
<y>204</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonLoadSound</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>load_sound()</slot>
<hints>
<hint type="sourcelabel">
<x>381</x>
<y>544</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>dialVolume</sender>
<signal>sliderMoved(int)</signal>
<receiver>MainWindow</receiver>
<slot>volume_slot(int)</slot>
<hints>
<hint type="sourcelabel">
<x>189</x>
<y>480</y>
</hint>
<hint type="destinationlabel">
<x>361</x>
<y>301</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>play_slot()</slot>
<slot>stop_slot()</slot>
<slot>ratio_slot(double)</slot>
<slot>ratio_slot(int)</slot>
<slot>fft1_start_slot(int)</slot>
<slot>fft2_start_slot(int)</slot>
<slot>fft1_end_slot(int)</slot>
<slot>fft2_end_slot(int)</slot>
<slot>volume_slot(int)</slot>
<slot>run_slot()</slot>
<slot>block_size(int)</slot>
<slot>block_overlap(int)</slot>
<slot>fft_spectrum_size(int)</slot>
<slot>generate()</slot>
<slot>load_sound()</slot>
<slot>delete_sound()</slot>
<slot>slot2()</slot>
<slot>load_target()</slot>
<slot>target_block_size(int)</slot>
<slot>target_block_overlap(int)</slot>
<slot>generate_target_blocks()</slot>
</slots>
</ui>

View File

@ -3,40 +3,13 @@
#include "MainWindow.h" #include "MainWindow.h"
using namespace spiralcore;
using namespace std; using namespace std;
MainWindow::MainWindow() MainWindow::MainWindow()
{ {
m_Ui.setupUi(this); m_Ui.setupUi(this);
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
}
m_audio_address = lo_address_new_from_url("osc.udp://localhost:8888");
void MainWindow::init_brain() { m_process_address = lo_address_new_from_url("osc.udp://localhost:8889");
cerr<<"starting"<<endl;
// m_source.load_sound("../sound/source/shostakovich6.wav");
m_source.load_sound("../../sound/source/808.wav");
m_source.load_sound("../../sound/source/joey.wav");
m_source.load_sound("../../sound/source/pw2.wav");
m_source.load_sound("../../sound/source/pw3.wav");
m_source.load_sound("../../sound/source/claps.wav");
m_source.load_sound("../../sound/source/eagle.wav");
// m_source.load_sound("../sound/source/sailingbybit.wav");
//target.load_sound("../sound/source/sb-left.wav");
m_target.load_sound("../../sound/source/apache.wav");
cerr<<"loaded sounds"<<endl;
cerr<<endl;
u32 len=3000;
m_source.init(len,len-len,50);
m_target.init(len,len-len/8,50);
cerr<<"ready..."<<endl;
cerr<<"we have "<<m_source.get_num_blocks()<<" brain blocks ("<<m_source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl;
//target.resynth_listen("shosta-dream-0.5.wav",source,0.5,a);
m_renderer = new renderer(m_source,m_target);
} }

View File

@ -1,8 +1,8 @@
#include <QtGui> #include <QtGui>
#include "generated/ui_samplebrain.h" #include "generated/ui_samplebrain.h"
#include "brain.h" #include <iostream>
#include "renderer.h" #include <lo/lo.h>
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
@ -11,24 +11,21 @@ class MainWindow : public QMainWindow
public: public:
MainWindow(); MainWindow();
void init_brain();
spiralcore::brain m_source, m_target;
spiralcore::renderer *m_renderer;
protected: protected:
private slots: private slots:
void play_slot() { m_renderer->set_playing(true); } void play_slot() { lo_send(m_process_address,"/init",""); }
void stop_slot() { m_renderer->set_playing(false); } 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(int s) { lo_send(m_audio_address,"/ratio","f",s/100.0f); }
void ratio_slot(double s) { m_renderer->get_params()->m_ratio=s/100.0f; } void ratio_slot(double s) { lo_send(m_audio_address,"/ratio","f",s); }
void fft1_start_slot(int s) { m_renderer->get_params()->m_fft1_start=s; } void fft1_start_slot(int s) { lo_send(m_audio_address,"/fft1_start","i",s); }
void fft1_end_slot(int s) { m_renderer->get_params()->m_fft1_end=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_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 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 volume_slot(int s){} // { m_renderer->set_volume(s/50.0f); }
void run_slot() {} void run_slot() {}
void load_target() {} void load_target() {}
void target_block_size(int) {} void target_block_size(int) {}
@ -42,5 +39,6 @@ private slots:
private: private:
Ui_MainWindow m_Ui; Ui_MainWindow m_Ui;
lo_address m_audio_address;
lo_address m_process_address;
}; };

View File

@ -1,6 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: samplebrain # 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 # Project: samplebrain.pro
# Template: app # Template: app
# Command: /usr/bin/qmake -o Makefile samplebrain.pro # 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. 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++ LINK = g++
LFLAGS = -m64 -Wl,-O1 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 AR = ar cqs
RANLIB = RANLIB =
QMAKE = /usr/bin/qmake QMAKE = /usr/bin/qmake
@ -44,8 +44,12 @@ OBJECTS_DIR = ./
####### Files ####### Files
SOURCES = MainWindow.cpp \ SOURCES = MainWindow.cpp \
audio_thread.cpp \
process_thread.cpp \
qtmain.cpp moc_MainWindow.cpp qtmain.cpp moc_MainWindow.cpp
OBJECTS = MainWindow.o \ OBJECTS = MainWindow.o \
audio_thread.o \
process_thread.o \
qtmain.o \ qtmain.o \
moc_MainWindow.o moc_MainWindow.o
DIST = /usr/share/qt4/mkspecs/common/unix.conf \ DIST = /usr/share/qt4/mkspecs/common/unix.conf \
@ -162,7 +166,7 @@ qmake: FORCE
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/samplebrain1.0.0 || $(MKDIR) .tmp/samplebrain1.0.0 @$(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 clean:compiler_clean
@ -213,8 +217,17 @@ MainWindow.o: MainWindow.cpp MainWindow.h \
generated/ui_samplebrain.h generated/ui_samplebrain.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o MainWindow.o MainWindow.cpp $(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 \ 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 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtmain.o qtmain.cpp
moc_MainWindow.o: moc_MainWindow.cpp moc_MainWindow.o: moc_MainWindow.cpp

View File

@ -0,0 +1,37 @@
#include "audio_thread.h"
#include <iostream>
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<<name<<endl;
if (name=="/ratio") {
m_renderer->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..."<<endl;
}
}

View File

@ -0,0 +1,23 @@
#include "jellyfish/fluxa/OSC_server.h"
#include "process_thread.h"
#include "renderer.h"
#pragma once
namespace spiralcore {
class audio_thread {
public:
audio_thread(process_thread &p);
void process(sample &s);
private:
renderer *m_renderer;
OSC_server m_osc;
process_thread &m_process_thread;
pthread_mutex_t* m_brain_mutex;
};
}

View File

@ -0,0 +1,66 @@
#include "process_thread.h"
#include <iostream>
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<<name<<endl;
if (name=="/init") {
p->init_brain();
}
}
usleep(500);
}
}
void process_thread::init_brain() {
pthread_mutex_lock(m_brain_mutex);
cerr<<"starting"<<endl;
// m_source.load_sound("../sound/source/shostakovich6.wav");
m_source.load_sound("../../sound/source/808.wav");
m_source.load_sound("../../sound/source/joey.wav");
m_source.load_sound("../../sound/source/pw2.wav");
m_source.load_sound("../../sound/source/pw3.wav");
m_source.load_sound("../../sound/source/claps.wav");
m_source.load_sound("../../sound/source/eagle.wav");
// m_source.load_sound("../sound/source/sailingbybit.wav");
//target.load_sound("../sound/source/sb-left.wav");
m_target.load_sound("../../sound/source/apache.wav");
cerr<<"loaded sounds"<<endl;
cerr<<endl;
u32 len=3000;
m_source.init(len,len-len,50);
m_target.init(len,len-len/8,50);
cerr<<"ready..."<<endl;
cerr<<"we have "<<m_source.get_num_blocks()<<" brain blocks ("<<m_source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl;
pthread_mutex_unlock(m_brain_mutex);
//target.resynth_listen("shosta-dream-0.5.wav",source,0.5,a);
}

View File

@ -0,0 +1,22 @@
#include "jellyfish/fluxa/OSC_server.h"
#include "brain.h"
#include <pthread.h>
#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;
};
}

View File

@ -7,20 +7,17 @@
#include "jellyfish/audio.h" #include "jellyfish/audio.h"
#include "block.h" #include "process_thread.h"
#include "brain.h" #include "audio_thread.h"
#include "renderer.h"
using namespace std; using namespace std;
audio_device *a = NULL; audio_device *a = NULL;
renderer *rr = NULL;
void run_audio(void* c, unsigned int frames) { void run_audio(void* c, unsigned int frames) {
audio_thread *at = (audio_thread*)c;
a->left_out.zero(); a->left_out.zero();
rr->process(frames,a->left_out.get_non_const_buffer()); at->process(a->left_out);
// sleep(1);
} }
int main( int argc , char *argv[] ){ int main( int argc , char *argv[] ){
@ -28,10 +25,11 @@ int main( int argc , char *argv[] ){
MainWindow mainWin; MainWindow mainWin;
mainWin.show(); mainWin.show();
mainWin.init_brain(); process_thread pt;
rr = mainWin.m_renderer; audio_thread at(pt);
a = new audio_device("samplebrain",44100,2048); 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(); return app.exec();
} }

View File

@ -14,10 +14,12 @@ HEADERS += MainWindow.h \
generated/ui_samplebrain.h \ generated/ui_samplebrain.h \
SOURCES += MainWindow.cpp \ SOURCES += MainWindow.cpp \
audio_thread.cpp \
process_thread.cpp \
qtmain.cpp qtmain.cpp
INCLUDEPATH += ../src INCLUDEPATH += ../src
LIBS += -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -ldl -lpthread -lm LIBS += -L.. -lsamplebrain -ljellyfish -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm
# assets # assets
#RESOURCES = application.qrc #RESOURCES = application.qrc

View File

@ -26,9 +26,9 @@ public:
const sample &get_block_pcm(u32 index) const; const sample &get_block_pcm(u32 index) const;
const block &get_block(u32 index) const; const block &get_block(u32 index) const;
const u32 get_num_blocks() const { return m_blocks.size(); } u32 get_num_blocks() const { return m_blocks.size(); }
const u32 get_block_size() const { return m_block_size; } u32 get_block_size() const { return m_block_size; }
const u32 get_overlap() const { return m_overlap; } u32 get_overlap() const { return m_overlap; }
u32 search(const block &target, const search_params &params) const; u32 search(const block &target, const search_params &params) const;

View File

@ -5,6 +5,7 @@ using namespace spiralcore;
using namespace std; using namespace std;
void renderer::init(brain &source, brain &target) { void renderer::init(brain &source, brain &target) {
m_volume=1;
m_source=source; m_source=source;
m_target=target; m_target=target;
m_render_time=0; m_render_time=0;

View File

@ -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