Classes to produce a computed sound wave on the analog output.

Dependents:   SoundWaveGeneratorTest SoundWaveGeneratorTest

Revision:
0:ed89ef772e92
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoundWaveGenerator.cpp	Mon Jan 24 22:44:39 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