Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Music/Music.cpp
- Revision:
- 0:d7214673ab2d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Music/Music.cpp Mon Jul 22 14:45:38 2019 +0000
@@ -0,0 +1,57 @@
+
+#include "Music.h"
+AnalogOut speaker(DAC0_OUT);
+/**
+* @brief Constructor (no paramateters)
+*/
+Music::Music()
+{
+
+}
+/**
+* @brief Deconstructor
+*/
+Music::~Music()
+{
+
+
+
+}
+
+/**
+* @brief Initialiser. Takes the sound data and initialises the buzzer
+* @param const int* data @details The audio data. A array of the amplitude of
+* the waveform over time
+* @param length @details Length of above sound array
+*/
+void Music::init(const int* data,int length)
+{
+
+ _data = data;
+ _length = length;
+ // Has to << then 1/sample rate
+ // until music played stay silent
+ _index = 0;
+
+}
+/**
+* @brief Plays the next sound sample. Must be called at the sample rate
+*/
+void Music::play_next()
+{
+ double duty_cycle;
+ duty_cycle = _data[_index];
+ //printf("%i = %f\n",_index,duty_cycle);
+
+ if (_index < _length) {
+ speaker = duty_cycle/255;
+ //printf("%f\n",duty_cycle/255);
+
+ _index++;
+ } else {
+ _index = 0;
+ }
+
+}
+
+