diff --git a/samplebrain/src/brain.h b/samplebrain/src/brain.h index 4b6c9db..ea5f7eb 100644 --- a/samplebrain/src/brain.h +++ b/samplebrain/src/brain.h @@ -76,7 +76,7 @@ public: void build_synapses_thresh(search_params ¶ms, double threshold); void build_synapses_fixed(search_params ¶ms); u32 search_synapses(const block &target, search_params ¶ms); - double get_current_error() { return m_current_error/m_average_error; } + double get_current_error() { return m_current_error; } static bool unit_test(); diff --git a/samplebrain/src/main.cpp b/samplebrain/src/main.cpp index 2b6480f..10b9684 100644 --- a/samplebrain/src/main.cpp +++ b/samplebrain/src/main.cpp @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) */ brain source; - ifstream ifs("8bit.brain",ios::binary); + ifstream ifs("shosta.brain",ios::binary); ifs||source; ifs.close(); @@ -119,11 +119,12 @@ int main(int argc, char *argv[]) renderer rr(source,target); rr.set_playing(true); rr.get_params()->m_ratio=0; - rr.get_params()->m_usage_importance=0.5; - rr.get_params()->m_num_synapses=150; - rr.set_slide_error(5.5); - rr.set_search_algo(renderer::SYNAPTIC); - + rr.get_params()->m_usage_importance=0.6; + source.set_usage_falloff(0.9); + rr.get_params()->m_num_synapses=40; + rr.set_slide_error(3400.5); + rr.set_search_algo(renderer::SYNAPTIC_SLIDE); + rr.set_target_mix(0.2); a->start_recording("debug"); a->m_client.set_callback(run_audio, &rr); diff --git a/samplebrain/src/renderer.cpp b/samplebrain/src/renderer.cpp index 0d19c29..b04f2dc 100644 --- a/samplebrain/src/renderer.cpp +++ b/samplebrain/src/renderer.cpp @@ -33,6 +33,7 @@ void renderer::init(brain &source, brain &target) { m_search_algo=BASIC; m_slide_error=1; m_target_index=0; + m_target_counter=0; m_last_tgt_shift=0; } @@ -42,12 +43,164 @@ void renderer::reset() { m_target_time=0; m_render_time=0; m_target_index=0; + m_target_counter=0; m_render_blocks.clear(); m_source.jiggle(); } + void renderer::process(u32 nframes, float *buf) { if (!m_playing) return; + if (!find_render_blocks(nframes)) return; + + render(nframes,buf); + + clean_up(); + + m_render_time+=nframes; + m_target_time+=nframes; +} + +bool renderer::find_render_blocks(u32 nframes) { + // get new blocks from source for the current buffer + + // where are we phase? + u32 tgt_shift = m_target.get_block_size()-m_target.get_overlap(); + u32 tgt_end = (m_target_time+nframes)/(float)tgt_shift; + + // stuff has changed - recompute and abort + if (tgt_shift!=m_last_tgt_shift || + tgt_end>=m_target.get_num_blocks() || m_source.get_num_blocks()==0) { + reset(); + m_last_tgt_shift = tgt_shift; + // next time... + return false; + } + + +// cerr<<"-----------------"<::iterator i=m_render_blocks.begin(); i!=m_render_blocks.end(); ++i) { + const sample &pcm=m_source.get_block(i->m_index).get_pcm(); + const sample &n_pcm=m_source.get_block(i->m_index).get_n_pcm(); + const sample &target_pcm=m_target.get_block(i->m_tgt_index).get_pcm(); + // get the sample offset into the buffer + s32 offset = i->m_time-m_render_time; + + // assume midway through block + u32 block_start = offset; + u32 buffer_start = 0; + if (offset<0) { + block_start=-offset; + if (block_start>=pcm.get_length()) i->m_finished=true; + } else { // block is midway through buffer + block_start=0; + buffer_start=offset; + } + +// cerr<<"-----------------"<m_finished) { + // mix in + u32 buffer_pos = buffer_start; + u32 block_pos = block_start; + u32 block_end = pcm.get_length(); + + + while (block_pos::iterator i=m_render_blocks.begin(); + std::list::iterator ni=m_render_blocks.begin(); + while(i!=m_render_blocks.end()) { + ni++; + if (i->m_finished) m_render_blocks.erase(i); + i=ni; + } +} + + + + + + + + + + + + + +void renderer::old_process(u32 nframes, float *buf) { + if (!m_playing) return; // get new blocks from source for the current buffer u32 tgt_shift = m_target.get_block_size()-m_target.get_overlap(); @@ -160,6 +313,7 @@ void renderer::process(u32 nframes, float *buf) { m_target_time+=nframes; } + bool renderer::unit_test() { brain source; source.load_sound("test_data/up.wav"); diff --git a/samplebrain/src/renderer.h b/samplebrain/src/renderer.h index b4c1338..2d8674b 100644 --- a/samplebrain/src/renderer.h +++ b/samplebrain/src/renderer.h @@ -43,6 +43,7 @@ renderer(brain &source, brain &target) : void reset(); void process(u32 nframes, float *buf); + void old_process(u32 nframes, float *buf); void set_search_algo(search_algo s) { m_search_algo=s; } void set_playing(bool s) { m_playing=s; } @@ -58,6 +59,11 @@ renderer(brain &source, brain &target) : private: + bool find_render_blocks(u32 nframes); + void render(u32 nframes, float *buf); + void clean_up(); + + // realtime stuff class render_block { public: @@ -76,8 +82,10 @@ private: float m_volume; bool m_playing; u32 m_target_index; + u32 m_target_counter; u32 m_target_time; u32 m_render_time; + u32 m_stretch; float m_n_mix; float m_target_mix;