Luke Cartwright / Mbed 2 deprecated ELEC2645_Project_el18loc_nearlythere

Dependencies:   mbed

Revision:
18:204cd747b54a
Child:
19:08862f49cd9e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Envelope/Envelope.cpp	Thu May 21 22:59:59 2020 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "Envelope.h"
+
+//constructor/destructor
+Envelope::Envelope()
+{
+}
+Envelope::~Envelope()
+{
+}
+//PUBLIC------------------------------------------------------------------------
+uint16_t Envelope::env_in(int a, int d, int s, int r, int in, bool init)
+{
+    if(init==true) {
+        av=a*1828;// max 63980 = 4 seconds (ish)
+        dv=a*1828;// max 63980 = 4 seconds
+        sv=a*1872;// max 65520 =  Max Volume (ish)
+        rv=a*1828;// max 63980 = 4 seconds
+        samples=0; //initialise samplke counter
+        a_vec=a_vector_calc(av); //initialise a value for a dif
+        d_vec=0; //placeholder
+        r_vec=sv; ///sets to be sustain value
+        at=0;//initialises
+        #ifdef SLOW_TIME
+        printf("av= %d,\na vector= %d\n\n",av,a_vec);
+        #endif
+    }
+    if (samples<=av) {
+        at=at+a_vec;
+        out=in*at/32767;
+        
+        #ifdef SLOW_TIME
+        printf("FILTER:\nIN= %d,\nOUT = %d\n",in,out);
+        printf("CUM. INPUT MULTIPLIER = %d\n",at);
+        #endif
+        }
+
+    #ifdef SLOW_TIME
+    printf("SAMPLE_%d\n",samples);
+    #endif
+    samples=samples+1;
+    return (out);
+}
+
+//PRIVATE:----------------------------------------------------------------------
+int Envelope::a_vector_calc(int av) {
+    a_vec=63980/av;
+    return(a_vec);
+    }
\ No newline at end of file