mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-05-12 18:47:21 +00:00
fixed stereo and c++11 stuff
This commit is contained in:
parent
36a68d9ecf
commit
e966d6b3af
@ -45,14 +45,23 @@ void brain::load_sound(std::string filename) {
|
|||||||
SNDFILE* f=sf_open(filename.c_str(), SFM_READ, &sfinfo);
|
SNDFILE* f=sf_open(filename.c_str(), SFM_READ, &sfinfo);
|
||||||
if (f!=NULL) {
|
if (f!=NULL) {
|
||||||
sample s(sfinfo.frames);
|
sample s(sfinfo.frames);
|
||||||
sf_readf_float(f, s.get_non_const_buffer(), s.get_length());
|
float *temp = new float[sfinfo.channels * sfinfo.frames];
|
||||||
|
sf_readf_float(f, temp, sfinfo.channels * sfinfo.frames);
|
||||||
|
// mix down stereo to mono
|
||||||
|
for(u32 i=0; i<sfinfo.frames; i++) {
|
||||||
|
s[i]=0;
|
||||||
|
for(u32 j = 0; j < sfinfo.channels; j++) {
|
||||||
|
s[i]+=temp[i*sfinfo.channels + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete[] temp;
|
||||||
m_samples.push_back(sound(filename,s));
|
m_samples.push_back(sound(filename,s));
|
||||||
status::update("loaded %s",filename.c_str());
|
status::update("loaded %s",filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void brain::delete_sound(std::string filename) {
|
void brain::delete_sound(std::string filename) {
|
||||||
for (std::list<sound>::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) {
|
for (auto i=m_samples.begin(); i!=m_samples.end(); ++i) {
|
||||||
if (i->m_filename==filename) {
|
if (i->m_filename==filename) {
|
||||||
m_samples.erase(i);
|
m_samples.erase(i);
|
||||||
status::update("deleted %s",filename.c_str());
|
status::update("deleted %s",filename.c_str());
|
||||||
@ -75,9 +84,9 @@ void brain::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) {
|
|||||||
m_window.init(block_size);
|
m_window.init(block_size);
|
||||||
m_window.set_current_type(t);
|
m_window.set_current_type(t);
|
||||||
u32 count=0;
|
u32 count=0;
|
||||||
for (std::list<sound>::iterator i=m_samples.begin(); i!=m_samples.end(); ++i) {
|
for (auto s : m_samples) {
|
||||||
count++;
|
count++;
|
||||||
chop_and_add(*i, count, ditchpcm);
|
chop_and_add(s, count, ditchpcm);
|
||||||
}
|
}
|
||||||
status::update("all samples processed");
|
status::update("all samples processed");
|
||||||
}
|
}
|
||||||
@ -123,8 +132,8 @@ u32 brain::search(const block &target, const search_params ¶ms) {
|
|||||||
double closest = FLT_MAX;
|
double closest = FLT_MAX;
|
||||||
u32 closest_index = 0;
|
u32 closest_index = 0;
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
for (vector<block>::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
for (auto b : m_blocks) {
|
||||||
double diff = target.compare(*i,params);
|
double diff = target.compare(b,params);
|
||||||
if (diff<closest) {
|
if (diff<closest) {
|
||||||
closest=diff;
|
closest=diff;
|
||||||
closest_index = index;
|
closest_index = index;
|
||||||
@ -141,8 +150,8 @@ u32 brain::rev_search(const block &target, const search_params ¶ms) {
|
|||||||
double furthest = 0;
|
double furthest = 0;
|
||||||
u32 furthest_index = 0;
|
u32 furthest_index = 0;
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
for (vector<block>::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
for (auto b:m_blocks) {
|
||||||
double diff = target.compare(*i,params);
|
double diff = target.compare(b,params);
|
||||||
if (diff>furthest) {
|
if (diff>furthest) {
|
||||||
furthest=diff;
|
furthest=diff;
|
||||||
furthest_index = index;
|
furthest_index = index;
|
||||||
@ -160,9 +169,9 @@ u32 brain::rev_search(const block &target, const search_params ¶ms) {
|
|||||||
// really slow - every to every comparison of blocks calculating average distance
|
// really slow - every to every comparison of blocks calculating average distance
|
||||||
double brain::calc_average_diff(search_params ¶ms) {
|
double brain::calc_average_diff(search_params ¶ms) {
|
||||||
double diff=0;
|
double diff=0;
|
||||||
for (vector<block>::const_iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
for (auto i:m_blocks) {
|
||||||
for (vector<block>::const_iterator j=m_blocks.begin(); j!=m_blocks.end(); ++j) {
|
for (auto j:m_blocks) {
|
||||||
diff += j->compare(*i,params);
|
diff += j.compare(i,params);
|
||||||
}
|
}
|
||||||
diff/=(double)m_blocks.size();
|
diff/=(double)m_blocks.size();
|
||||||
}
|
}
|
||||||
@ -174,15 +183,15 @@ void brain::build_synapses_thresh(search_params ¶ms, double thresh) {
|
|||||||
double err = m_average_error*thresh;
|
double err = m_average_error*thresh;
|
||||||
u32 brain_size = m_blocks.size();
|
u32 brain_size = m_blocks.size();
|
||||||
u32 outer_index = 0;
|
u32 outer_index = 0;
|
||||||
for (vector<block>::iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
for (auto i:m_blocks) {
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
|
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
|
||||||
for (vector<block>::const_iterator j=m_blocks.begin(); j!=m_blocks.end(); ++j) {
|
for (auto j:m_blocks) {
|
||||||
if (index!=outer_index) {
|
if (index!=outer_index) {
|
||||||
// collect connections that are under threshold in closeness
|
// collect connections that are under threshold in closeness
|
||||||
double diff = i->compare(*j,params);
|
double diff = i.compare(j,params);
|
||||||
if (diff<err) {
|
if (diff<err) {
|
||||||
i->get_synapse().push_back(index);
|
i.get_synapse().push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
@ -198,16 +207,16 @@ void brain::build_synapses_fixed(search_params ¶ms) {
|
|||||||
u32 num_synapses = NUM_FIXED_SYNAPSES;
|
u32 num_synapses = NUM_FIXED_SYNAPSES;
|
||||||
if (num_synapses>=m_blocks.size()) num_synapses=m_blocks.size()-1;
|
if (num_synapses>=m_blocks.size()) num_synapses=m_blocks.size()-1;
|
||||||
|
|
||||||
for (vector<block>::iterator i=m_blocks.begin(); i!=m_blocks.end(); ++i) {
|
for (auto i:m_blocks) {
|
||||||
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
|
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
vector<pair<u32,double>> collect;
|
vector<pair<u32,double>> collect;
|
||||||
|
|
||||||
// collect comparisons to all other blocks
|
// collect comparisons to all other blocks
|
||||||
for (vector<block>::const_iterator j=m_blocks.begin(); j!=m_blocks.end(); ++j) {
|
for (auto j:m_blocks) {
|
||||||
assert(index<m_blocks.size());
|
assert(index<m_blocks.size());
|
||||||
if (index!=outer_index) {
|
if (index!=outer_index) {
|
||||||
double diff = i->compare(*j,params);
|
double diff = i.compare(j,params);
|
||||||
collect.push_back(pair<u32,double>(index,diff));
|
collect.push_back(pair<u32,double>(index,diff));
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
@ -224,8 +233,7 @@ void brain::build_synapses_fixed(search_params ¶ms) {
|
|||||||
// add the closest ones to the list
|
// add the closest ones to the list
|
||||||
for(u32 n=0; n<num_synapses; ++n) {
|
for(u32 n=0; n<num_synapses; ++n) {
|
||||||
assert(collect[n].first<m_blocks.size());
|
assert(collect[n].first<m_blocks.size());
|
||||||
|
i.get_synapse().push_back(collect[n].first);
|
||||||
i->get_synapse().push_back(collect[n].first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++outer_index;
|
++outer_index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user