Luke Cartwright / Mbed 2 deprecated ELEC2645_Project_el18loc_nearlythere

Dependencies:   mbed

Revision:
14:9cfe0041cc4e
Child:
15:1c67f064278e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sound/Sound.cpp	Tue May 19 15:04:33 2020 +0000
@@ -0,0 +1,44 @@
+#include "Sound.h"
+
+//Global Variables
+volatile extern uint16_t sin_wavtable[1024];
+volatile extern uint16_t tri_wavtable[1024];
+volatile extern uint16_t pulse_wavtable[1024];
+
+//Constructor/Destructor
+Sound::Sound()
+{
+}
+Sound::~Sound()
+{
+}
+
+//PUBLIC:-----------------------------------------------------------------------
+
+uint16_t Sound::sound_main(bool initial, int waveform, int frequency)
+{
+    if (initial==true) {
+        i=0;
+        return(i);
+    }
+    i=wavetable_itt(i,frequency);
+    if (waveform==1) {
+        #ifdef SLOW_TIME
+        printf("SIN_wavtable[%u]=",i)
+        #endif
+        return (sin_wavtable[i]);
+    }
+    return(0);
+}
+
+//PRIVATE:----------------------------------------------------------------------
+uint16_t Sound::wavetable_itt(uint16_t i, int frequency)
+{
+    i_d = i + ((1024*frequency)/4000); //i+((samples*f)*Ts)
+    i=ceil(i_d); //ROUND IN FUTURE*************
+
+    if (i>=1024) {
+        i=i-1024;
+    }
+    return(i);
+}
\ No newline at end of file