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/snd_wave_generator/SoundWaveGenerator.h	Mon Jan 24 22:44:39 2011 +0000
@@ -0,0 +1,45 @@
+#ifndef SOUND_WAVE_GENERATOR_H_
+#define SOUND_WAVE_GENERATOR_H_
+
+#include "snd_wave_generator/Wave.h"
+#include "mbed.h"
+
+namespace snd_wave_generator {
+
+/**
+ * @brief A class to handle computed sound wave generation.
+ * The generator is bound to an AnalogOut pin (p18 on LPC1768).
+ * It has a fixed sample rate.
+ */
+class SoundWaveGenerator {
+public:
+    SoundWaveGenerator(std::size_t sampleRate, PinName pin = p18) : 
+        sampleRate(sampleRate), wave(NULL), pos(0), output(pin), ticker()
+    { }
+    
+    /**
+     * @brief Starts playing a given wave.
+     * The wave will be prepared for the generator's sample rate and then played back
+     * on the bound analog output.
+     */
+    void play(Wave *wave);
+    
+    /**
+     * @brief Stops playing.
+     */
+    void stop();
+    
+private:
+    void tickerHandler();
+    
+    std::size_t sampleRate;
+    
+    Wave *wave;    
+    std::size_t pos;
+    AnalogOut output;
+    Ticker ticker;
+};
+  
+} // snd_wave_generator
+  
+#endif // SOUND_WAVE_GENERATOR_H_