Luke Cartwright / Mbed 2 deprecated ELEC2645_Project_el18loc_nearlythere

Dependencies:   mbed

Committer:
lukeocarwright
Date:
Thu May 21 22:59:59 2020 +0000
Revision:
18:204cd747b54a
Child:
19:08862f49cd9e
Got attack working with hardware glitch (slew rate issue and distortion likely due to loading and amp module). Generates CSV file to check output with envelope.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukeocarwright 18:204cd747b54a 1 #include "mbed.h"
lukeocarwright 18:204cd747b54a 2 #include "Envelope.h"
lukeocarwright 18:204cd747b54a 3
lukeocarwright 18:204cd747b54a 4 //constructor/destructor
lukeocarwright 18:204cd747b54a 5 Envelope::Envelope()
lukeocarwright 18:204cd747b54a 6 {
lukeocarwright 18:204cd747b54a 7 }
lukeocarwright 18:204cd747b54a 8 Envelope::~Envelope()
lukeocarwright 18:204cd747b54a 9 {
lukeocarwright 18:204cd747b54a 10 }
lukeocarwright 18:204cd747b54a 11 //PUBLIC------------------------------------------------------------------------
lukeocarwright 18:204cd747b54a 12 uint16_t Envelope::env_in(int a, int d, int s, int r, int in, bool init)
lukeocarwright 18:204cd747b54a 13 {
lukeocarwright 18:204cd747b54a 14 if(init==true) {
lukeocarwright 18:204cd747b54a 15 av=a*1828;// max 63980 = 4 seconds (ish)
lukeocarwright 18:204cd747b54a 16 dv=a*1828;// max 63980 = 4 seconds
lukeocarwright 18:204cd747b54a 17 sv=a*1872;// max 65520 = Max Volume (ish)
lukeocarwright 18:204cd747b54a 18 rv=a*1828;// max 63980 = 4 seconds
lukeocarwright 18:204cd747b54a 19 samples=0; //initialise samplke counter
lukeocarwright 18:204cd747b54a 20 a_vec=a_vector_calc(av); //initialise a value for a dif
lukeocarwright 18:204cd747b54a 21 d_vec=0; //placeholder
lukeocarwright 18:204cd747b54a 22 r_vec=sv; ///sets to be sustain value
lukeocarwright 18:204cd747b54a 23 at=0;//initialises
lukeocarwright 18:204cd747b54a 24 #ifdef SLOW_TIME
lukeocarwright 18:204cd747b54a 25 printf("av= %d,\na vector= %d\n\n",av,a_vec);
lukeocarwright 18:204cd747b54a 26 #endif
lukeocarwright 18:204cd747b54a 27 }
lukeocarwright 18:204cd747b54a 28 if (samples<=av) {
lukeocarwright 18:204cd747b54a 29 at=at+a_vec;
lukeocarwright 18:204cd747b54a 30 out=in*at/32767;
lukeocarwright 18:204cd747b54a 31
lukeocarwright 18:204cd747b54a 32 #ifdef SLOW_TIME
lukeocarwright 18:204cd747b54a 33 printf("FILTER:\nIN= %d,\nOUT = %d\n",in,out);
lukeocarwright 18:204cd747b54a 34 printf("CUM. INPUT MULTIPLIER = %d\n",at);
lukeocarwright 18:204cd747b54a 35 #endif
lukeocarwright 18:204cd747b54a 36 }
lukeocarwright 18:204cd747b54a 37
lukeocarwright 18:204cd747b54a 38 #ifdef SLOW_TIME
lukeocarwright 18:204cd747b54a 39 printf("SAMPLE_%d\n",samples);
lukeocarwright 18:204cd747b54a 40 #endif
lukeocarwright 18:204cd747b54a 41 samples=samples+1;
lukeocarwright 18:204cd747b54a 42 return (out);
lukeocarwright 18:204cd747b54a 43 }
lukeocarwright 18:204cd747b54a 44
lukeocarwright 18:204cd747b54a 45 //PRIVATE:----------------------------------------------------------------------
lukeocarwright 18:204cd747b54a 46 int Envelope::a_vector_calc(int av) {
lukeocarwright 18:204cd747b54a 47 a_vec=63980/av;
lukeocarwright 18:204cd747b54a 48 return(a_vec);
lukeocarwright 18:204cd747b54a 49 }