2015-07-21 10:58:13 -03:00
|
|
|
// Copyright (C) 2015 Dave Griffiths
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
2015-07-11 15:03:05 -03:00
|
|
|
#include "process_thread.h"
|
|
|
|
|
#include <iostream>
|
2015-07-14 08:17:55 -03:00
|
|
|
#include <unistd.h>
|
2015-07-11 15:03:05 -03:00
|
|
|
|
|
|
|
|
using namespace spiralcore;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2015-07-11 17:30:16 -03:00
|
|
|
static void _process(void *c) {
|
|
|
|
|
process_thread *p=(process_thread*)c;
|
|
|
|
|
p->process();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-11 15:03:05 -03:00
|
|
|
process_thread::process_thread() :
|
2015-07-11 17:30:16 -03:00
|
|
|
m_osc("8889"),
|
|
|
|
|
m_source_block_size(3000),
|
|
|
|
|
m_source_overlap(0.75),
|
|
|
|
|
m_target_block_size(3000),
|
|
|
|
|
m_target_overlap(0.75),
|
2015-07-18 20:34:56 -03:00
|
|
|
m_window_type(window::DODGY),
|
|
|
|
|
m_target_window_type(window::DODGY)
|
2015-07-11 15:03:05 -03:00
|
|
|
{
|
|
|
|
|
m_brain_mutex = new pthread_mutex_t;
|
|
|
|
|
pthread_mutex_init(m_brain_mutex,NULL);
|
|
|
|
|
m_osc.run();
|
|
|
|
|
|
|
|
|
|
// start the processing thread
|
2015-07-19 08:06:22 -03:00
|
|
|
m_thread = new pthread_t;
|
|
|
|
|
pthread_create(m_thread,NULL,(void*(*)(void*))_process,this);
|
|
|
|
|
}
|
2015-07-11 15:03:05 -03:00
|
|
|
|
2015-07-19 08:06:22 -03:00
|
|
|
process_thread::~process_thread() {
|
|
|
|
|
pthread_cancel(*m_thread);
|
|
|
|
|
delete m_brain_mutex;
|
2015-07-11 15:03:05 -03:00
|
|
|
}
|
|
|
|
|
|
2015-07-11 17:30:16 -03:00
|
|
|
void process_thread::process() {
|
2015-07-11 15:03:05 -03:00
|
|
|
command_ring_buffer::command cmd;
|
|
|
|
|
|
|
|
|
|
while(true) {
|
2015-07-11 17:30:16 -03:00
|
|
|
while (m_osc.get(cmd)) {
|
2015-07-11 15:03:05 -03:00
|
|
|
string name = cmd.m_name;
|
|
|
|
|
cerr<<name<<endl;
|
2015-07-11 17:30:16 -03:00
|
|
|
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") {
|
2015-07-12 20:26:30 -03:00
|
|
|
m_source_overlap = m_source_block_size*cmd.get_float(0);
|
2015-07-11 17:30:16 -03:00
|
|
|
}
|
|
|
|
|
if (name=="/generate_brain") {
|
|
|
|
|
pthread_mutex_lock(m_brain_mutex);
|
2015-07-18 20:34:56 -03:00
|
|
|
cerr<<m_window_type<<endl;
|
|
|
|
|
m_source.init(m_source_block_size, m_source_overlap, m_window_type);
|
2015-07-11 17:30:16 -03:00
|
|
|
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") {
|
2015-07-12 20:26:30 -03:00
|
|
|
m_target_overlap = m_target_block_size*cmd.get_float(0);
|
|
|
|
|
cerr<<m_target_overlap<<endl;
|
2015-07-11 17:30:16 -03:00
|
|
|
}
|
|
|
|
|
if (name=="/generate_target") {
|
|
|
|
|
pthread_mutex_lock(m_brain_mutex);
|
2015-07-18 20:34:56 -03:00
|
|
|
cerr<<m_target_window_type<<endl;
|
|
|
|
|
m_target.init(m_target_block_size, m_target_overlap, m_target_window_type);
|
2015-07-11 17:30:16 -03:00
|
|
|
pthread_mutex_unlock(m_brain_mutex);
|
2015-07-11 15:03:05 -03:00
|
|
|
}
|
2015-07-18 20:34:56 -03:00
|
|
|
if (name=="/window_type") {
|
|
|
|
|
m_window_type=(window::type)cmd.get_int(0);
|
|
|
|
|
}
|
|
|
|
|
if (name=="/target_window_type") {
|
|
|
|
|
m_target_window_type=(window::type)cmd.get_int(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-11 15:03:05 -03:00
|
|
|
}
|
|
|
|
|
usleep(500);
|
|
|
|
|
}
|
|
|
|
|
}
|