2

Xcode インストゥルメントを使用して、レガシー デバイスで適切に実行できるようにアプリを十分に高速化する方法を見つけようとしています。ほとんどの時間はオーディオ コールバックに費やされます。具体的には次のとおりです。

パーセンテージを示すスクリーンショット

void Analyzer::mergeWithOld(tones_t& tones) const {
    tones.sort();
    tones_t::iterator it = tones.begin();
    // Iterate over old tones
    for (tones_t::const_iterator oldit = m_tones.begin(); oldit != m_tones.end(); ++oldit) {
        // Try to find a matching new tone
        while (it != tones.end() && *it < *oldit) ++it;
        // If match found
        if (it != tones.end() && *it == *oldit) {
            // Merge the old tone into the new tone
            it->age = oldit->age + 1;
            it->stabledb = 0.8 * oldit->stabledb + 0.2 * it->db;
            it->freq = 0.5 * oldit->freq + 0.5 * it->freq;
        } else if (oldit->db > -80.0) {
            // Insert a decayed version of the old tone into new tones
            Tone& t = *tones.insert(it, *oldit);
            t.db -= 5.0;
            t.stabledb -= 0.1;
        }
    }
}

ようやくリスを捕まえた犬が、次に何をすべきかわからないことに気がついたような気がします。これをスピードアップできますか?

編集: もちろん— tones_t は typedef std::list<Tone> tones_t;

Tone は構造体です。

struct Tone {
    static const std::size_t MAXHARM = 48; ///< The maximum number of harmonics tracked
    static const std::size_t MINAGE = TONE_AGE_REQUIRED; // The minimum age required for a tone to be output
    double freq; ///< Frequency (Hz)
    double db; ///< Level (dB)
    double stabledb; ///< Stable level, useful for graphics rendering
    double harmonics[MAXHARM]; ///< Harmonics' levels
    std::size_t age; ///< How many times the tone has been detected in row

  double highestFreq;
  double lowestFreq;
  int function;
  float timeStamp;

    Tone(); 
    void print() const; ///< Prints Tone to std::cout
    bool operator==(double f) const; ///< Compare for rough frequency match
    /// Less-than compare by levels (instead of frequencies like operator< does)
    static bool dbCompare(Tone const& l, Tone const& r) { 
    return l.db < r.db;
  }
};
4

1 に答える 1

0

最適化は複雑なものです。いくつかのアプローチを試す必要があるかもしれません。

1: m_tones と tones を新しいリストにマージし、そのリストを m_tones に割り当てます。事前に新しいリストの容量を設定してください。

これにより、2 つのリスト コピーがミックスに追加されますが、すべての挿入が削除されます。より高速かどうかをテストする必要があります。

2: 別の構造のリストをダンプします。m_tones をリストではなく std::set として保存できますか?

順序付けられた方法で m_tones を取得する必要がある場合は、std::sort を呼び出す必要がありますが、順序付けされた反復が必要ない場合、または頻繁にしか必要としない場合は、より高速になる可能性があります。

これらは、問題を別の方法で考える方法の単なるアイデアです。どのオプションが最高のパフォーマンスを発揮するかを確認するには、テスト テストをテストする必要があります。

于 2012-05-09T15:25:47.143 に答える