windows loading fix 64bit and mic in cleanup

This commit is contained in:
dave griffiths 2016-09-24 10:33:16 +01:00
parent 3deaf9ac1e
commit cd6b842026
12 changed files with 306 additions and 166 deletions

View File

@ -48,7 +48,8 @@ audio_thread::~audio_thread() {
void audio_thread::start_audio() { void audio_thread::start_audio() {
if (m_audio_device!=NULL) delete m_audio_device; if (m_audio_device!=NULL) delete m_audio_device;
m_audio_device = new audio_device("samplebrain",44100,2048); m_audio_device = new audio_device("samplebrain",48000,2048);
//m_audio_device = new audio_device("samplebrain",48000,2048*4);
m_audio_device->m_client.set_callback(run_audio, this); m_audio_device->m_client.set_callback(run_audio, this);
} }

View File

@ -114,7 +114,7 @@ void block::process(const sample &pcm, sample &fft, sample &mfcc, float &freq) {
std::vector<std::complex<double> > mfspec; std::vector<std::complex<double> > mfspec;
for (u32 i=0; i<m_block_size; ++i) { for (u32 i=0; i<m_block_size; ++i) {
mfspec.push_back(std::complex<double>(m_fftw->m_spectrum[i][0], mfspec.push_back(std::complex<double>(m_fftw->m_spectrum[i][0],
m_fftw->m_spectrum[i][1])); m_fftw->m_spectrum[i][1]));
} }
freq = m_fftw->calculate_dominant_freq(); freq = m_fftw->calculate_dominant_freq();

View File

@ -14,6 +14,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <unistd.h>
#include <iostream> #include <iostream>
#include "block_stream.h" #include "block_stream.h"
@ -22,6 +23,7 @@ using namespace std;
#define BUFFER_SIZE 4096*10 #define BUFFER_SIZE 4096*10
#define MAX_BLOCKS 200 #define MAX_BLOCKS 200
#define NUM_WORKERS 4
block_stream::block_stream() : block_stream::block_stream() :
m_ready(false), m_ready(false),
@ -29,8 +31,13 @@ block_stream::block_stream() :
m_block_position(0), m_block_position(0),
m_buffer_position(0), m_buffer_position(0),
m_buffer(BUFFER_SIZE), m_buffer(BUFFER_SIZE),
m_block_index_offset(0) m_block_index_offset(0),
m_sent_block_index(0)
{ {
for (u32 i=0; i<NUM_WORKERS; ++i) {
m_workers.push_back(new worker(i,&m_window));
usleep(1);
}
} }
block_stream::~block_stream() {} block_stream::~block_stream() {}
@ -38,16 +45,21 @@ block_stream::~block_stream() {}
void block_stream::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) { void block_stream::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) {
m_block_size=block_size; m_block_size=block_size;
m_overlap=overlap; m_overlap=overlap;
m_block_index=0; m_block_index=20;
m_block_position=0; m_block_position=0;
m_buffer_position=0; m_buffer_position=0;
if (m_overlap>=m_block_size) m_overlap=0; if (m_overlap>=m_block_size) m_overlap=0;
cerr<<m_block_size<<endl;
m_window.init(m_block_size); m_window.init(m_block_size);
m_window.set_current_type(t); m_window.set_current_type(t);
m_blocks.clear(); m_blocks.clear();
sample dummy(block_size);
for (u32 i=0; i<MAX_BLOCKS; i++) {
m_blocks.push_back(block(0,"dummy",dummy,44100,m_window));
}
m_ready=true; m_ready=true;
} }
@ -69,8 +81,16 @@ void block_stream::process(const sample &left, const sample &right) {
//cerr<<(s32)(m_buffer_position-m_block_size)<<" to "<<m_buffer_position<<endl; //cerr<<(s32)(m_buffer_position-m_block_size)<<" to "<<m_buffer_position<<endl;
m_buffer.get_region(region,(s32)(m_buffer_position-m_block_size), m_buffer.get_region(region,(s32)(m_buffer_position-m_block_size),
m_buffer_position); m_buffer_position);
m_blocks.push_back(block(0,"input",region,44100,m_window));
//cerr<<"starting block "<<m_block_index<<endl;
scatter_gather(m_block_index,region);
m_block_index=(m_block_index+1)%MAX_BLOCKS;
//block b(0,"input",region,44100,m_window);
//m_blocks.push_back(b);
m_block_position=0; m_block_position=0;
if (m_blocks.size()>MAX_BLOCKS) { if (m_blocks.size()>MAX_BLOCKS) {
m_blocks.erase(m_blocks.begin()); m_blocks.erase(m_blocks.begin());
@ -80,9 +100,70 @@ void block_stream::process(const sample &left, const sample &right) {
m_block_position++; m_block_position++;
} }
cerr<<"num blocks: "<<m_blocks.size()<<endl;
} }
const block &block_stream::get_block(u32 index) const { const block &block_stream::get_block(u32 index) const {
return m_blocks[(index-m_block_index_offset)%m_blocks.size()]; //cerr<<"returning "<<(index-m_block_index_offset)%m_blocks.size()<<" ("<<m_blocks.size()<<")"<<endl;
u32 i = (index-m_block_index_offset)%MAX_BLOCKS;
//if (m_block_index<i) {
// cerr<<i<<" ("<<(s32)(m_block_index-(s32)(i))<<")"<<endl;
//}
return m_blocks[i];
} }
//-----------------------------------------------------------
void _run_worker(void *p) {
((block_stream::worker *)p)->run();
}
block_stream::worker::worker(u32 id, window *w) :
m_id(id),
m_status(READY),
m_window(w)
{
m_worker_mutex = new pthread_mutex_t;
pthread_mutex_init(m_worker_mutex,NULL);
m_thread = new pthread_t;
pthread_create(m_thread,NULL,(void*(*)(void*))_run_worker,this);
}
void block_stream::worker::run() {
//cerr<<"worker "<<m_id<<" started..."<<endl;
while (true) {
pthread_mutex_lock(m_worker_mutex);
if (m_status==ACTIVATE) {
cerr<<"starting "<<m_id<<endl;
m_status=WORKING;
m_output = new block(0,"input",m_region,44100,*m_window);
m_status=FINISHED;
cerr<<"ending "<<m_id<<endl;
}
pthread_mutex_unlock(m_worker_mutex);
usleep(5);
}
}
void block_stream::scatter_gather(u32 block_index, const sample &region) {
while(true) {
for (auto &w : m_workers) {
if (pthread_mutex_trylock(w->m_worker_mutex)) {
if (w->m_status == worker::FINISHED) {
//cerr<<"adding finished block "<<w->m_block_index<<endl;
m_blocks[w->m_block_index]=*w->m_output;
w->m_status = worker::READY;
}
if (w->m_status == worker::READY) {
w->m_region = region;
w->m_status = worker::ACTIVATE;
w->m_block_index = block_index;
return;
}
pthread_mutex_unlock(w->m_worker_mutex);
}
}
}
}

View File

@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include "window.h" #include "window.h"
#include "block.h" #include "block.h"
#include "jellyfish/sample.h"
#include "block_source.h" #include "block_source.h"
#ifndef BLOCK_STREAM #ifndef BLOCK_STREAM
@ -39,10 +40,33 @@ class block_stream : public block_source {
virtual const block &get_block(u32 index) const; virtual const block &get_block(u32 index) const;
virtual u32 get_num_blocks() const { return UINT_MAX; } virtual u32 get_num_blocks() const { return UINT_MAX; }
u32 last_block_index() const { return m_block_index_offset+m_blocks.size(); } u32 last_block_index() const { return m_block_index_offset+m_blocks.size()-1; }
class worker {
public:
worker(u32 id, window *w);
enum worker_status { READY=0, ACTIVATE, WORKING, FINISHED };
void run();
u32 m_id;
worker_status m_status;
pthread_mutex_t* m_worker_mutex;
sample m_region;
block *m_output;
window *m_window;
u32 m_block_index;
pthread_t *m_thread;
};
private: private:
void scatter_gather(u32 block_index, const sample &region);
vector<worker*> m_workers;
bool m_ready; bool m_ready;
u32 m_block_index; u32 m_block_index;
@ -55,6 +79,10 @@ class block_stream : public block_source {
u32 m_block_index_offset; u32 m_block_index_offset;
vector<block> m_blocks; vector<block> m_blocks;
mutable s32 m_sent_block_index;
block *m_dummy_block;
}; };
} }

View File

@ -22,57 +22,57 @@ using namespace std;
command_ring_buffer::command::command(const char *name, const char *types, const char *data, unsigned int datasize) command_ring_buffer::command::command(const char *name, const char *types, const char *data, unsigned int datasize)
{ {
strcpy(m_name,name); strcpy(m_name,name);
strcpy(m_types,types); strcpy(m_types,types);
// already checking datasize fits in OSCserver.cpp // already checking datasize fits in OSCserver.cpp
memcpy(m_data,data,datasize); memcpy(m_data,data,datasize);
m_num_args=strlen(types); m_num_args=strlen(types);
// figure out the offsets into the data to use later // figure out the offsets into the data to use later
int pos=0; int pos=0;
for(unsigned int i=0; i<m_num_args; i++) for(unsigned int i=0; i<m_num_args; i++)
{
m_offsets[i]=pos;
switch(types[i])
{ {
m_offsets[i]=pos; case 'i': pos+=4; break;
switch(types[i]) case 'f': pos+=4; break;
{ case 's': pos+=strlen(m_data+pos)+1; break;
case 'i': pos+=4; break; case 'b': pos+=sizeof(char*); break;
case 'f': pos+=4; break;
case 's': pos+=strlen(m_data+pos)+1; break;
case 'b': pos+=sizeof(char*); break;
default: default:
// invalidate the command // invalidate the command
for(unsigned int n=0; n<strlen(types); n++) m_offsets[n]=-1; for(unsigned int n=0; n<strlen(types); n++) m_offsets[n]=-1;
cerr<<"command_ring_buffer::command::command: erk! unknown type: "<<types[i]<<endl; cerr<<"command_ring_buffer::command::command: erk! unknown type: "<<types[i]<<endl;
return; return;
break; break;
}
} }
}
} }
int command_ring_buffer::command::get_int(unsigned int index) int command_ring_buffer::command::get_int(unsigned int index)
{ {
if (m_offsets[index]!=-1 && m_types[index]=='i') return *((int*)(m_data+m_offsets[index])); if (m_offsets[index]!=-1 && m_types[index]=='i') return *((int*)(m_data+m_offsets[index]));
return 0; return 0;
} }
float command_ring_buffer::command::get_float(unsigned int index) float command_ring_buffer::command::get_float(unsigned int index)
{ {
if (m_offsets[index]!=-1 && m_types[index]=='f') return *((float*)(m_data+m_offsets[index])); if (m_offsets[index]!=-1 && m_types[index]=='f') return *((float*)(m_data+m_offsets[index]));
return 0; return 0;
} }
char *command_ring_buffer::command::get_string(unsigned int index) char *command_ring_buffer::command::get_string(unsigned int index)
{ {
if (m_offsets[index]!=-1 && m_types[index]=='s') return ((char*)(m_data+m_offsets[index])); if (m_offsets[index]!=-1 && m_types[index]=='s') return ((char*)(m_data+m_offsets[index]));
return 0; return 0;
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
command_ring_buffer::command_ring_buffer(unsigned int size): command_ring_buffer::command_ring_buffer(unsigned int size):
ring_buffer(size) ring_buffer(size)
{ {
} }
@ -82,10 +82,10 @@ command_ring_buffer::~command_ring_buffer()
bool command_ring_buffer::send(const command& command) bool command_ring_buffer::send(const command& command)
{ {
return write((char*)&command,sizeof(command)); return write((char*)&command,sizeof(command));
} }
bool command_ring_buffer::get(command& command) bool command_ring_buffer::get(command& command)
{ {
return read((char*)&command, sizeof(command)); return read((char*)&command, sizeof(command));
} }

View File

@ -23,39 +23,39 @@ static const unsigned int COMMAND_DATA_SIZE = 128;
class command_ring_buffer : public ring_buffer class command_ring_buffer : public ring_buffer
{ {
public: public:
command_ring_buffer(unsigned int size); command_ring_buffer(unsigned int size);
~command_ring_buffer(); ~command_ring_buffer();
class command class command
{ {
public: public:
command() {} command() {}
command(const char *name, const char *types, const char *data, unsigned int datasize); command(const char *name, const char *types, const char *data, unsigned int datasize);
~command() {} ~command() {}
int get_int(unsigned int index); int get_int(unsigned int index);
float get_float(unsigned int index); float get_float(unsigned int index);
char *get_string(unsigned int index); char *get_string(unsigned int index);
// unlike the string - ownership of the blob is yours // unlike the string - ownership of the blob is yours
// you must delete it when you're done... // you must delete it when you're done...
char *get_blob(unsigned int index); char *get_blob(unsigned int index);
unsigned int size() { return m_num_args; } unsigned int size() { return m_num_args; }
char m_name[256]; char m_name[256];
char m_types[64]; char m_types[64];
private: private:
char m_data[COMMAND_DATA_SIZE]; char m_data[COMMAND_DATA_SIZE];
int m_offsets[64]; int m_offsets[64];
unsigned int m_num_args; unsigned int m_num_args;
}; };
bool send(const command& command); bool send(const command& command);
bool get(command& command); bool get(command& command);
private: private:
command m_current; command m_current;
}; };
#endif #endif

View File

@ -55,8 +55,14 @@ bool portaudio_client::attach(const string &client_name, const device_options &d
fprintf( stderr, "error message: %s\n", Pa_GetErrorText( err ) ); fprintf( stderr, "error message: %s\n", Pa_GetErrorText( err ) );
} }
PaDeviceIndex output_device_num = Pa_GetDefaultOutputDevice();
PaDeviceIndex input_device_num = Pa_GetDefaultInputDevice();
//output_device_num = 4;
//input_device_num = 4;
PaStreamParameters output_parameters; PaStreamParameters output_parameters;
output_parameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ output_parameters.device = output_device_num;
if (output_parameters.device == paNoDevice) { if (output_parameters.device == paNoDevice) {
cerr<<"error: no default output device."<<endl; cerr<<"error: no default output device."<<endl;
} }
@ -65,8 +71,10 @@ bool portaudio_client::attach(const string &client_name, const device_options &d
output_parameters.suggestedLatency = Pa_GetDeviceInfo( output_parameters.device )->defaultLowOutputLatency; output_parameters.suggestedLatency = Pa_GetDeviceInfo( output_parameters.device )->defaultLowOutputLatency;
output_parameters.hostApiSpecificStreamInfo = NULL; output_parameters.hostApiSpecificStreamInfo = NULL;
cerr<<"Connecting to "<<Pa_GetDeviceInfo( output_parameters.device )->name<<" for output"<<endl;
PaStreamParameters input_parameters; PaStreamParameters input_parameters;
input_parameters.device = Pa_GetDefaultInputDevice(); /* default output device */ input_parameters.device = input_device_num;
if (input_parameters.device == paNoDevice) { if (input_parameters.device == paNoDevice) {
cerr<<"error: no default input device."<<endl; cerr<<"error: no default input device."<<endl;
} }
@ -75,6 +83,8 @@ bool portaudio_client::attach(const string &client_name, const device_options &d
input_parameters.suggestedLatency = Pa_GetDeviceInfo( input_parameters.device )->defaultLowInputLatency; input_parameters.suggestedLatency = Pa_GetDeviceInfo( input_parameters.device )->defaultLowInputLatency;
input_parameters.hostApiSpecificStreamInfo = NULL; input_parameters.hostApiSpecificStreamInfo = NULL;
cerr<<"Connecting to "<<Pa_GetDeviceInfo( input_parameters.device )->name<<" for input"<<endl;
PaStream *stream; PaStream *stream;
err = Pa_OpenStream(&stream, err = Pa_OpenStream(&stream,

View File

@ -23,107 +23,107 @@
using namespace std; using namespace std;
ring_buffer::ring_buffer(unsigned int size): ring_buffer::ring_buffer(unsigned int size):
m_read_pos(0), m_read_pos(0),
m_write_pos(0), m_write_pos(0),
m_size(size), m_size(size),
m_size_mask(size-1), m_size_mask(size-1),
m_buffer(NULL) m_buffer(NULL)
{ {
m_buffer = new char[m_size]; m_buffer = new char[m_size];
memset(m_buffer,'Z',m_size); memset(m_buffer,'Z',m_size);
} }
ring_buffer::~ring_buffer() ring_buffer::~ring_buffer()
{ {
delete[] m_buffer; delete[] m_buffer;
} }
bool ring_buffer::write(char *src, unsigned int size) bool ring_buffer::write(char *src, unsigned int size)
{ {
//cerr<<"write pos: "<<m_write_pos<<endl; //cerr<<"write pos: "<<m_write_pos<<endl;
unsigned int space=write_space(); unsigned int space=write_space();
if (space<size) if (space<size)
{ {
cerr<<"ringbuffer ran out of space, needed: "<<size<<" have: "<<space<<endl; cerr<<"ringbuffer ran out of space, needed: "<<size<<" have: "<<space<<endl;
return false; return false;
} }
if (size<m_size-m_write_pos) if (size<m_size-m_write_pos)
{ {
//cerr<<"written to: "<<m_write_pos<<endl; //cerr<<"written to: "<<m_write_pos<<endl;
memcpy(&(m_buffer[m_write_pos]), src, size); memcpy(&(m_buffer[m_write_pos]), src, size);
m_write_pos += size; m_write_pos += size;
m_write_pos &= m_size_mask; m_write_pos &= m_size_mask;
} }
else // have to split data over boundary else // have to split data over boundary
{ {
unsigned int first = m_size-m_write_pos; unsigned int first = m_size-m_write_pos;
unsigned int second = (m_write_pos+size) & m_size_mask; unsigned int second = (m_write_pos+size) & m_size_mask;
memcpy(&(m_buffer[m_write_pos]), src, first); memcpy(&(m_buffer[m_write_pos]), src, first);
m_write_pos += first; m_write_pos += first;
m_write_pos &= m_size_mask; m_write_pos &= m_size_mask;
memcpy(&(m_buffer[m_write_pos]), &src[first], second); memcpy(&(m_buffer[m_write_pos]), &src[first], second);
m_write_pos += second; m_write_pos += second;
m_write_pos &= m_size_mask; m_write_pos &= m_size_mask;
} }
return true; return true;
} }
bool ring_buffer::read(char *dest, unsigned int size) bool ring_buffer::read(char *dest, unsigned int size)
{ {
//cerr<<"read pos: "<<m_read_pos<<endl; //cerr<<"read pos: "<<m_read_pos<<endl;
unsigned int space=read_space(); unsigned int space=read_space();
if (space==0 || size>m_size) return false; if (space==0 || size>m_size) return false;
if (size<m_size-m_read_pos) if (size<m_size-m_read_pos)
{ {
//cerr<<"reading from: "<<m_read_pos<<endl; //cerr<<"reading from: "<<m_read_pos<<endl;
memcpy(dest, &(m_buffer[m_read_pos]), size); memcpy(dest, &(m_buffer[m_read_pos]), size);
m_read_pos += size; m_read_pos += size;
m_read_pos &= m_size_mask; m_read_pos &= m_size_mask;
} }
else // have to split data over boundary else // have to split data over boundary
{ {
unsigned int first = m_size-m_read_pos; unsigned int first = m_size-m_read_pos;
unsigned int second = (m_read_pos+size) & m_size_mask; unsigned int second = (m_read_pos+size) & m_size_mask;
memcpy(dest, &(m_buffer[m_read_pos]), first); memcpy(dest, &(m_buffer[m_read_pos]), first);
m_read_pos += first; m_read_pos += first;
m_read_pos &= m_size_mask; m_read_pos &= m_size_mask;
memcpy(&dest[first], &(m_buffer[m_read_pos]), second); memcpy(&dest[first], &(m_buffer[m_read_pos]), second);
m_read_pos += second; m_read_pos += second;
m_read_pos &= m_size_mask; m_read_pos &= m_size_mask;
} }
return true; return true;
} }
void ring_buffer::dump() void ring_buffer::dump()
{ {
for (unsigned int i=0; i<m_size; i++) cerr<<m_buffer[i]; for (unsigned int i=0; i<m_size; i++) cerr<<m_buffer[i];
cerr<<endl; cerr<<endl;
} }
unsigned int ring_buffer::write_space() unsigned int ring_buffer::write_space()
{ {
unsigned int read = m_read_pos; unsigned int read = m_read_pos;
unsigned int write = m_write_pos; unsigned int write = m_write_pos;
if (write > read) return (read - write + m_size) & (m_size_mask - 1); if (write > read) return (read - write + m_size) & (m_size_mask - 1);
if (write < read) return (read - write) - 1; if (write < read) return (read - write) - 1;
return m_size - 1; return m_size - 1;
} }
unsigned int ring_buffer::read_space() unsigned int ring_buffer::read_space()
{ {
unsigned int read = m_read_pos; unsigned int read = m_read_pos;
unsigned int write = m_write_pos; unsigned int write = m_write_pos;
if (write > read) return write - read; if (write > read) return write - read;
else return (write - read + m_size) & m_size_mask; else return (write - read + m_size) & m_size_mask;
} }

View File

@ -22,25 +22,25 @@
class ring_buffer class ring_buffer
{ {
public: public:
ring_buffer(unsigned int size); ring_buffer(unsigned int size);
~ring_buffer(); ~ring_buffer();
//bool lock(); //bool lock();
//bool unlock(); //bool unlock();
bool write(char *src, unsigned int size); bool write(char *src, unsigned int size);
bool read(char *dest, unsigned int size); bool read(char *dest, unsigned int size);
void dump(); void dump();
private: private:
unsigned int write_space(); unsigned int write_space();
unsigned int read_space(); unsigned int read_space();
unsigned int m_read_pos; unsigned int m_read_pos;
unsigned int m_write_pos; unsigned int m_write_pos;
unsigned int m_size; unsigned int m_size;
unsigned int m_size_mask; unsigned int m_size_mask;
char *m_buffer; char *m_buffer;
}; };
#endif #endif

View File

@ -26,8 +26,8 @@ template<>ios &spiralcore::operator||(ios &s, string &v) {
ofstream *pos=dynamic_cast<ofstream*>(&s); ofstream *pos=dynamic_cast<ofstream*>(&s);
if (pos!=NULL) { if (pos!=NULL) {
ofstream &os = *pos; ofstream &os = *pos;
size_t len = v.length(); u64 len = v.length();
os.write((char *)&len,sizeof(size_t)); os.write((char *)&len,sizeof(u64));
os.write((char*)(v.c_str()),v.length()); os.write((char*)(v.c_str()),v.length());
return os; return os;
} }
@ -36,8 +36,8 @@ template<>ios &spiralcore::operator||(ios &s, string &v) {
ifstream *pis=dynamic_cast<ifstream*>(&s); ifstream *pis=dynamic_cast<ifstream*>(&s);
assert(pis!=NULL); assert(pis!=NULL);
ifstream &is = *pis; ifstream &is = *pis;
size_t len=0; u64 len=0;
is.read((char *)&len,sizeof(size_t)); is.read((char *)&len,sizeof(u64));
if (len>0) { if (len>0) {
char *str = new char[len+1]; char *str = new char[len+1];
is.read(str,len); is.read(str,len);

View File

@ -25,6 +25,7 @@
#include "block.h" #include "block.h"
#include "brain.h" #include "brain.h"
#include "renderer.h" #include "renderer.h"
#include "block_stream.h"
#include <pthread.h> #include <pthread.h>
using namespace std; using namespace std;
@ -46,12 +47,23 @@ void unit_test() {
} }
audio_device *a = NULL; audio_device *a = NULL;
block_stream *m_block_stream = NULL;
bool m_mic_mode = true;
void run_audio(void* c, unsigned int frames) { void run_audio(void* c, unsigned int frames) {
a->left_out.zero(); a->left_out.zero();
renderer *rr = (renderer*)c; renderer *rr = (renderer*)c;
pthread_mutex_lock(m_fuz_mutex); pthread_mutex_lock(m_fuz_mutex);
rr->process(frames,a->left_out.get_non_const_buffer());
block_stream *bs=NULL;
if (m_mic_mode) {
m_block_stream->process(a->left_in,a->right_in);
bs = m_block_stream;
}
rr->process(frames,a->left_out.get_non_const_buffer(),bs);
pthread_mutex_unlock(m_fuz_mutex); pthread_mutex_unlock(m_fuz_mutex);
a->right_out=a->left_out; a->right_out=a->left_out;
a->maybe_record(); a->maybe_record();
@ -127,8 +139,15 @@ void fuz() {
brain target; brain target;
target.load_sound(fuz_samplefile(),brain::MIX); target.load_sound(fuz_samplefile(),brain::MIX);
u32 len=fuz_rr_i(500,5000); // u32 len=fuz_rr_i(500,5000);
target.init(len,len-len/fuz_rr_i(1,16),window::HANN); //u32 overlap = len-len/fuz_rr_i(1,16);
u32 len=5000;
u32 overlap=len/2;
target.init(len,overlap,window::HANN);
m_block_stream = new block_stream();
m_block_stream->init(len,overlap,window::HANN);
cerr<<"ready..."<<endl; cerr<<"ready..."<<endl;
cerr<<"we have "<<source.get_num_blocks()<<" brain blocks ("<<source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl; cerr<<"we have "<<source.get_num_blocks()<<" brain blocks ("<<source.get_num_blocks()*len/44100.0<<" secs)"<<endl<<endl;
@ -140,8 +159,8 @@ void fuz() {
renderer rr(source,target); renderer rr(source,target);
rr.set_playing(true); rr.set_playing(true);
// a->start_recording("debug"); // a->start_recording("debug");
a->m_client.set_callback(run_audio, &rr); a->m_client.set_callback(run_audio, &rr);
//target.resynth("shosta-dream-0.5.wav",source,0.5); //target.resynth("shosta-dream-0.5.wav",source,0.5);
u32 counter=0; u32 counter=0;
@ -199,6 +218,8 @@ int main(int argc, char *argv[])
{ {
m_fuz_mutex = new pthread_mutex_t; m_fuz_mutex = new pthread_mutex_t;
pthread_mutex_init(m_fuz_mutex,NULL); pthread_mutex_init(m_fuz_mutex,NULL);
unit_test(); //unit_test();
fuz(); fuz();
} }

View File

@ -57,15 +57,14 @@ void renderer::process(u32 nframes, float *buf, const block_stream *bs) {
// or the realtime block stream // or the realtime block stream
const block_source *source = (block_source*)bs; const block_source *source = (block_source*)bs;
if (source==NULL) { if (source==NULL) {
cerr<<"not using block stream..."<<endl;
source = &m_target; source = &m_target;
} else { } else {
if (m_target_index<bs->last_block_index()-10) { if ((s32)m_target_index<(s32)(bs->last_block_index()-100)) {
cerr<<"catch up..."<<endl; //cerr<<"catch up... "<<(s32)m_target_index<<" "<<(s32)bs->last_block_index()<<endl;
m_target_index = bs->last_block_index(); m_target_index = bs->last_block_index();
} }
if (m_target_index>bs->last_block_index()) { if (m_target_index>bs->last_block_index()) {
cerr<<"catch down..."<<endl; //cerr<<"catch down..."<<endl;
m_target_index = bs->last_block_index(); m_target_index = bs->last_block_index();
} }
} }
@ -106,7 +105,7 @@ bool renderer::find_render_blocks(const block_source &target, u32 nframes) {
} }
cerr<<"-----------------"<<endl; /* cerr<<"-----------------"<<endl;
cerr<<"tgt start:"<<m_target_index<<endl; cerr<<"tgt start:"<<m_target_index<<endl;
cerr<<"tgt end:"<<tgt_end<<endl; cerr<<"tgt end:"<<tgt_end<<endl;
cerr<<":"<<tgt_end-m_target_index<<endl; cerr<<":"<<tgt_end-m_target_index<<endl;
@ -117,7 +116,7 @@ bool renderer::find_render_blocks(const block_source &target, u32 nframes) {
cerr<<"render time (index) "<<m_render_index*tgt_shift<<endl; cerr<<"render time (index) "<<m_render_index*tgt_shift<<endl;
cerr<<"real vs index = "<<(s32)m_render_time-(s32)(m_render_index*tgt_shift)<<endl; cerr<<"real vs index = "<<(s32)m_render_time-(s32)(m_render_index*tgt_shift)<<endl;
cerr<<m_render_blocks.size()<<endl; cerr<<m_render_blocks.size()<<endl;
*/
// search phase // search phase
// get indices for current buffer // get indices for current buffer