mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2026-06-28 17:41:37 +00:00
started making samplerate and buffer size configurable for audio device selection
This commit is contained in:
@@ -26,7 +26,9 @@ audio_thread::audio_thread(process_thread &p) :
|
||||
m_process_thread(p),
|
||||
m_brain_mutex(p.m_brain_mutex),
|
||||
m_stereo_mode(false),
|
||||
m_mic_mode(false)
|
||||
m_mic_mode(false),
|
||||
m_bufsize(2048),
|
||||
m_samplerate(44100)
|
||||
{
|
||||
start_audio();
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
@@ -48,8 +50,7 @@ audio_thread::~audio_thread() {
|
||||
|
||||
void audio_thread::start_audio() {
|
||||
if (m_audio_device!=NULL) delete m_audio_device;
|
||||
m_audio_device = new audio_device("samplebrain",48000,2048);
|
||||
//m_audio_device = new audio_device("samplebrain",48000,2048*4);
|
||||
m_audio_device = new audio_device("samplebrain",m_samplerate,m_bufsize);
|
||||
m_audio_device->m_client.set_callback(run_audio, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace spiralcore {
|
||||
|
||||
class audio_thread {
|
||||
public:
|
||||
class audio_thread {
|
||||
public:
|
||||
audio_thread(process_thread &p);
|
||||
~audio_thread();
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
renderer *m_right_renderer;
|
||||
block_stream *m_block_stream;
|
||||
|
||||
private:
|
||||
private:
|
||||
void start_audio();
|
||||
|
||||
OSC_server m_osc;
|
||||
@@ -46,6 +46,8 @@ private:
|
||||
pthread_mutex_t* m_brain_mutex;
|
||||
bool m_stereo_mode;
|
||||
bool m_mic_mode;
|
||||
};
|
||||
u32 m_bufsize;
|
||||
u32 m_samplerate;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -63,82 +63,82 @@ void process_thread::process() {
|
||||
string name = cmd.m_name;
|
||||
//cerr<<name<<endl;
|
||||
if (name=="/load_sample") {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.load_sound(cmd.get_string(0),brain::MIX);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.load_sound(cmd.get_string(0),brain::MIX);
|
||||
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);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.delete_sound(cmd.get_string(0));
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/activate_sound") {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.activate_sound(cmd.get_string(0),1);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.activate_sound(cmd.get_string(0),1);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/deactivate_sound") {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.activate_sound(cmd.get_string(0),0);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.activate_sound(cmd.get_string(0),0);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/source_block_size") {
|
||||
m_source_block_size = cmd.get_int(0);
|
||||
m_source_block_size = cmd.get_int(0);
|
||||
}
|
||||
if (name=="/source_overlap") {
|
||||
m_source_overlap = m_source_block_size*cmd.get_float(0);
|
||||
m_source_overlap = 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_window_type);
|
||||
search_params p(1,0,0,100,0);
|
||||
m_source.build_synapses_fixed(p);
|
||||
m_left_renderer->reset();
|
||||
m_right_renderer->reset();
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_source.init(m_source_block_size, m_source_overlap, m_window_type);
|
||||
search_params p(1,0,0,100,0);
|
||||
m_source.build_synapses_fixed(p);
|
||||
m_left_renderer->reset();
|
||||
m_right_renderer->reset();
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/load_target") {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_left_target.clear_sounds();
|
||||
m_left_target.load_sound(cmd.get_string(0),brain::LEFT);
|
||||
m_right_target.clear_sounds();
|
||||
m_right_target.load_sound(cmd.get_string(0),brain::RIGHT);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_left_target.clear_sounds();
|
||||
m_left_target.load_sound(cmd.get_string(0),brain::LEFT);
|
||||
m_right_target.clear_sounds();
|
||||
m_right_target.load_sound(cmd.get_string(0),brain::RIGHT);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/target_block_size") {
|
||||
m_target_block_size = cmd.get_int(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
m_target_block_size = cmd.get_int(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
}
|
||||
if (name=="/target_overlap") {
|
||||
m_target_overlap = m_target_block_size*cmd.get_float(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
m_target_overlap = m_target_block_size*cmd.get_float(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
}
|
||||
if (name=="/generate_target") {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_left_target.init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
m_right_target.init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
// probably elsewhere
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
m_left_target.init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
m_right_target.init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
// probably elsewhere
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
if (name=="/window_type") {
|
||||
m_window_type=(window::type)cmd.get_int(0);
|
||||
m_window_type=(window::type)cmd.get_int(0);
|
||||
}
|
||||
if (name=="/target_window_type") {
|
||||
m_target_window_type=(window::type)cmd.get_int(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
m_target_window_type=(window::type)cmd.get_int(0);
|
||||
m_block_stream->init(m_target_block_size, m_target_overlap, m_target_window_type);
|
||||
}
|
||||
if (name=="/load_brain") {
|
||||
load_source(cmd.get_string(0));
|
||||
load_source(cmd.get_string(0));
|
||||
}
|
||||
if (name=="/save_brain") {
|
||||
save_source(cmd.get_string(0));
|
||||
save_source(cmd.get_string(0));
|
||||
}
|
||||
if (name=="/load_session") {
|
||||
load_session(cmd.get_string(0));
|
||||
load_session(cmd.get_string(0));
|
||||
}
|
||||
if (name=="/save_session") {
|
||||
save_session(cmd.get_string(0));
|
||||
save_session(cmd.get_string(0));
|
||||
}
|
||||
}
|
||||
#ifdef WIN32
|
||||
@@ -181,9 +181,6 @@ void process_thread::load_session(const std::string &filename) {
|
||||
ifs||m_source_block_size||m_source_overlap;
|
||||
ifs||m_target_block_size||m_target_overlap;
|
||||
ifs||m_window_type||m_target_window_type;
|
||||
|
||||
cerr<<"loading window type session "<<m_target_window_type<<endl;
|
||||
|
||||
ifs||m_source;
|
||||
ifs||m_left_target;
|
||||
ifs||m_right_target;
|
||||
@@ -200,9 +197,6 @@ void process_thread::save_session(const std::string &filename) {
|
||||
ofs||(*m_right_renderer);
|
||||
ofs||m_source_block_size||m_source_overlap;
|
||||
ofs||m_target_block_size||m_target_overlap;
|
||||
|
||||
cerr<<"saving window type session "<<m_target_window_type<<endl;
|
||||
|
||||
ofs||m_window_type||m_target_window_type;
|
||||
ofs||m_source;
|
||||
ofs||m_left_target;
|
||||
|
||||
Reference in New Issue
Block a user