Classes to produce a computed sound wave on the analog output.
Dependents: SoundWaveGeneratorTest SoundWaveGeneratorTest
SoundWaveGenerator.cpp
- Committer:
- osmeest
- Date:
- 2011-02-08
- Revision:
- 1:6864fd480178
- Parent:
- 0:ed89ef772e92
File content as of revision 1:6864fd480178:
#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