diff options
| -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++;    } | 
