Olivier Smeesters
/
DtmfKit
A DTMF sequence editor and player for HAM radio equipment command & control.
Diff: SoundWaveGenerator/SoundWaveGenerator.cpp
- Revision:
- 0:1324e7d9d471
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SoundWaveGenerator/SoundWaveGenerator.cpp Mon Mar 07 22:51:19 2011 +0000 @@ -0,0 +1,28 @@ +#include "snd_wave_generator/SoundWaveGenerator.h" + +namespace snd_wave_generator { + +void SoundWaveGenerator::play(Wave *wave) +{ + wave->prepare(this->sampleRate); + + this->wave = wave; + + this->pos = 0; + this->ticker.attach(this, &SoundWaveGenerator::tickerHandler, 1.0 / this->sampleRate); +} + +void SoundWaveGenerator::stop() +{ + this->ticker.detach(); + this->output.write(0.0); + this->wave = NULL; +} + +void SoundWaveGenerator::tickerHandler() +{ + float v = this->wave ? this->wave->read(this->pos++) : 0.0; + this->output.write(v); +} + +} // snd_wave_generator