Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SoundWaveGeneratorTest SoundWaveGeneratorTest
WaveCombo.cpp
- Committer:
- osmeest
- Date:
- 2011-01-24
- Revision:
- 0:ed89ef772e92
File content as of revision 0:ed89ef772e92:
#include "snd_wave_generator/WaveCombo.h"
#include <algorithm>
#include <functional>
#include <numeric>
namespace snd_wave_generator {
WaveCombo & WaveCombo::add(Wave *wave) {
if (wave) {
this->waves.push_back(wave);
this->numWaves = this->waves.size();
}
return *this;
}
void WaveCombo::prepare(std::size_t sampleRate)
{
std::for_each(this->waves.begin(), this->waves.end(),
std::bind2nd(std::mem_fun(&Wave::prepare), sampleRate));
}
struct AccumulateWaveValueAt {
AccumulateWaveValueAt(std::size_t pos) : pos(pos) { }
float operator()(float acc, const Wave *wave) const {
return acc + wave->read(this->pos);
}
std::size_t pos;
};
float WaveCombo::read(std::size_t pos) const {
float v = std::accumulate(this->waves.begin(), this->waves.end(), 0.0f,
AccumulateWaveValueAt(pos));
return v / this->numWaves;
}
} // snd_wave_generator