diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-04-24 21:12:06 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-04-24 21:12:06 +0200 |
commit | f40d8ff14a4e51ecc255800c24ce4be291e05eca (patch) | |
tree | a61e00183212d00d415b7c34c07448449210ff3f /src | |
parent | 6dbcd24cee07b519981f128c1fae8870e839e79e (diff) |
Fix nasty bug in power list handling. Should fix reported velocity problems (all samples played with the same power regardless of midi velocity).
Diffstat (limited to 'src')
-rw-r--r-- | src/instrument.cc | 9 | ||||
-rw-r--r-- | src/instrumentparser.cc | 7 | ||||
-rw-r--r-- | src/powerlist.cc | 25 |
3 files changed, 24 insertions, 17 deletions
diff --git a/src/instrument.cc b/src/instrument.cc index 43ee4ac..8c88503 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -109,14 +109,17 @@ Sample *Instrument::sample(level_t level, size_t pos) void Instrument::addSample(level_t a, level_t b, Sample *s) { samples.insert(a, b, s); -#ifdef NEW_ALGORITHM - powerlist.add(s); -#endif/*NEW_ALGORITHM*/ } void Instrument::finalise() { #ifdef NEW_ALGORITHM + std::vector<Sample*>::iterator s = samplelist.begin(); + while(s != samplelist.end()) { + powerlist.add(*s); + s++; + } + powerlist.finalise(); #endif/*NEW_ALGORITHM*/ } diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc index 84cbe23..3a07f1f 100644 --- a/src/instrumentparser.cc +++ b/src/instrumentparser.cc @@ -178,12 +178,7 @@ void InstrumentParser::endTag(std::string name) instrument.samplelist.push_back(s); -#ifdef EXPERIMENTAL - // TODO: New algorithm needs this here. Thresholds are ignored, hence '0' - instrument.addSample(0, 0, s); -#endif/*EXPERIMENTAL*/ - - s = NULL; + s = NULL; } if(name == "instrument") { diff --git a/src/powerlist.cc b/src/powerlist.cc index cf843a3..86378ca 100644 --- a/src/powerlist.cc +++ b/src/powerlist.cc @@ -32,11 +32,14 @@ #include <hugin.hpp> +// Enable to calculate power on old samples without power attribute +//#define AUTO_CALCULATE_POWER + #define SIZE 500 // Box–Muller transform. // See: http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform -float box_muller_transform(float mean, float stddev) +static float box_muller_transform(float mean, float stddev) { float U1 = (float)rand() / (float)RAND_MAX; float U2 = (float)rand() / (float)RAND_MAX; @@ -133,6 +136,7 @@ Channel *PowerList::getMasterChannel() void PowerList::finalise() { +#ifdef AUTO_CALCULATE_POWER Channel *master_channel = getMasterChannel(); if(master_channel == NULL) { @@ -141,13 +145,15 @@ void PowerList::finalise() } DEBUG(rand, "Master channel: %s\n", master_channel->name.c_str()); +#endif/*AUTO_CALCULATE_POWER*/ std::vector<PowerListItem>::iterator si = samples.begin(); while(si != samples.end()) { PowerListItem &item = *si; Sample *sample = item.sample; - DEBUG(rand, "Sample: %s\n", sample->name.c_str()); + #ifdef AUTO_CALCULATE_POWER + DEBUG(rand, "Sample: %s\n", sample->name.c_str()); AudioFile *master = NULL; @@ -166,10 +172,13 @@ void PowerList::finalise() } master->load(); +#endif/*AUTO_CALCULATE_POWER*/ - float power = 0; +#ifdef AUTO_CALCULATE_POWER if(sample->power == -1) { // Power not defined. Calculate it! DEBUG(powerlist, "Calculating power\n"); + + float power = 0; size_t s = 0; for(; s < SIZE && s < master->size; s++) { power += master->data[s] * master->data[s]; @@ -179,13 +188,13 @@ void PowerList::finalise() if(power > power_max) power_max = power; - item.power = power; - } else { // Power defined in xml - DEBUG(powerlist, "Using power from xml\n"); - power = sample->power; + sample->power = power; } +#endif/*AUTO_CALCULATE_POWER*/ + + item.power = sample->power; - DEBUG(rand, " - power: %f\n", power); + DEBUG(rand, " - power: %f\n", item.power); si++; } |