A DTMF sequence editor and player for HAM radio equipment command & control.

Dependencies:   mbed ExtTextLCD

Committer:
osmeest
Date:
Mon Mar 07 22:51:19 2011 +0000
Revision:
0:1324e7d9d471

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
osmeest 0:1324e7d9d471 1 #include "snd_wave_generator/WaveCombo.h"
osmeest 0:1324e7d9d471 2
osmeest 0:1324e7d9d471 3 #include <algorithm>
osmeest 0:1324e7d9d471 4 #include <functional>
osmeest 0:1324e7d9d471 5 #include <numeric>
osmeest 0:1324e7d9d471 6
osmeest 0:1324e7d9d471 7 namespace snd_wave_generator {
osmeest 0:1324e7d9d471 8
osmeest 0:1324e7d9d471 9 WaveCombo & WaveCombo::add(Wave *wave) {
osmeest 0:1324e7d9d471 10 if (wave) {
osmeest 0:1324e7d9d471 11 this->waves.push_back(wave);
osmeest 0:1324e7d9d471 12 this->numWaves = this->waves.size();
osmeest 0:1324e7d9d471 13 }
osmeest 0:1324e7d9d471 14
osmeest 0:1324e7d9d471 15 return *this;
osmeest 0:1324e7d9d471 16 }
osmeest 0:1324e7d9d471 17
osmeest 0:1324e7d9d471 18 void WaveCombo::prepare(std::size_t sampleRate)
osmeest 0:1324e7d9d471 19 {
osmeest 0:1324e7d9d471 20 std::for_each(this->waves.begin(), this->waves.end(),
osmeest 0:1324e7d9d471 21 std::bind2nd(std::mem_fun(&Wave::prepare), sampleRate));
osmeest 0:1324e7d9d471 22 }
osmeest 0:1324e7d9d471 23
osmeest 0:1324e7d9d471 24 struct AccumulateWaveValueAt {
osmeest 0:1324e7d9d471 25 AccumulateWaveValueAt(std::size_t pos) : pos(pos) { }
osmeest 0:1324e7d9d471 26 float operator()(float acc, const Wave *wave) const {
osmeest 0:1324e7d9d471 27 return acc + wave->read(this->pos);
osmeest 0:1324e7d9d471 28 }
osmeest 0:1324e7d9d471 29
osmeest 0:1324e7d9d471 30 std::size_t pos;
osmeest 0:1324e7d9d471 31 };
osmeest 0:1324e7d9d471 32
osmeest 0:1324e7d9d471 33 float WaveCombo::read(std::size_t pos) const {
osmeest 0:1324e7d9d471 34 float v = std::accumulate(this->waves.begin(), this->waves.end(), 0.0f,
osmeest 0:1324e7d9d471 35 AccumulateWaveValueAt(pos));
osmeest 0:1324e7d9d471 36
osmeest 0:1324e7d9d471 37 return v / this->numWaves;
osmeest 0:1324e7d9d471 38 }
osmeest 0:1324e7d9d471 39
osmeest 0:1324e7d9d471 40 } // snd_wave_generator