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.
Envelope/Envelope.cpp@30:08cc4ec58d07, 2020-05-26 (annotated)
- Committer:
- lukeocarwright
- Date:
- Tue May 26 10:17:47 2020 +0000
- Revision:
- 30:08cc4ec58d07
- Parent:
- 19:08862f49cd9e
- Child:
- 31:cfdb014ff086
Sorted Settings Menu Final Touches. More Code Tidying.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lukeocarwright | 18:204cd747b54a | 1 | #include "mbed.h" |
| lukeocarwright | 18:204cd747b54a | 2 | #include "Envelope.h" |
| lukeocarwright | 19:08862f49cd9e | 3 | //Global var. |
| lukeocarwright | 19:08862f49cd9e | 4 | volatile int silent_flag; |
| lukeocarwright | 18:204cd747b54a | 5 | |
| lukeocarwright | 18:204cd747b54a | 6 | //constructor/destructor |
| lukeocarwright | 18:204cd747b54a | 7 | Envelope::Envelope() |
| lukeocarwright | 18:204cd747b54a | 8 | { |
| lukeocarwright | 18:204cd747b54a | 9 | } |
| lukeocarwright | 18:204cd747b54a | 10 | Envelope::~Envelope() |
| lukeocarwright | 18:204cd747b54a | 11 | { |
| lukeocarwright | 18:204cd747b54a | 12 | } |
| lukeocarwright | 18:204cd747b54a | 13 | //PUBLIC------------------------------------------------------------------------ |
| lukeocarwright | 18:204cd747b54a | 14 | uint16_t Envelope::env_in(int a, int d, int s, int r, int in, bool init) |
| lukeocarwright | 18:204cd747b54a | 15 | { |
| lukeocarwright | 18:204cd747b54a | 16 | if(init==true) { |
| lukeocarwright | 19:08862f49cd9e | 17 | printf("INITIATING ENVELOPE\n"); |
| lukeocarwright | 19:08862f49cd9e | 18 | av=a*a*52;// max 63700 = 4 seconds (ish) |
| lukeocarwright | 19:08862f49cd9e | 19 | dv=d*d*52;// max 63700 = 4 seconds |
| lukeocarwright | 19:08862f49cd9e | 20 | sv=s*s*53;// max 64925 = Max Volume (ish) |
| lukeocarwright | 19:08862f49cd9e | 21 | rv=r*r*52;// max 63700 = 4 seconds |
| lukeocarwright | 19:08862f49cd9e | 22 | samples=0; //initialise sample counter |
| lukeocarwright | 18:204cd747b54a | 23 | a_vec=a_vector_calc(av); //initialise a value for a dif |
| lukeocarwright | 30:08cc4ec58d07 | 24 | d_vec=d_vector_calc(dv,sv); //initialise a value for d dif |
| lukeocarwright | 18:204cd747b54a | 25 | at=0;//initialises |
| lukeocarwright | 19:08862f49cd9e | 26 | #ifdef SLOW_TIME |
| lukeocarwright | 19:08862f49cd9e | 27 | printf("INITIATING ENVELOPE\n"); |
| lukeocarwright | 19:08862f49cd9e | 28 | printf("a=%d,av= %d,a vector= %d\n",a,av,a_vec); |
| lukeocarwright | 19:08862f49cd9e | 29 | printf("d=%d,dv= %d,d vector= %d\n",d,dv,d_vec); |
| lukeocarwright | 19:08862f49cd9e | 30 | printf("s=%d,sv= %d\n",s,sv); |
| lukeocarwright | 19:08862f49cd9e | 31 | #endif |
| lukeocarwright | 18:204cd747b54a | 32 | } |
| lukeocarwright | 18:204cd747b54a | 33 | if (samples<=av) { |
| lukeocarwright | 19:08862f49cd9e | 34 | at=at+a_vec; //max=63980 |
| lukeocarwright | 19:08862f49cd9e | 35 | out=(in*at/63980)+32767; |
| lukeocarwright | 19:08862f49cd9e | 36 | //printf("ATTACK"); |
| lukeocarwright | 19:08862f49cd9e | 37 | } else if(samples>av && samples<=av+dv) { |
| lukeocarwright | 19:08862f49cd9e | 38 | at=at-d_vec; |
| lukeocarwright | 19:08862f49cd9e | 39 | out=(in*at/63980)+32767; |
| lukeocarwright | 19:08862f49cd9e | 40 | //printf("DECAY"); |
| lukeocarwright | 19:08862f49cd9e | 41 | } else if (samples>av+dv) { |
| lukeocarwright | 19:08862f49cd9e | 42 | out=(in*sv/65520)+32767; |
| lukeocarwright | 19:08862f49cd9e | 43 | } |
| lukeocarwright | 19:08862f49cd9e | 44 | #ifdef SLOW_TIME |
| lukeocarwright | 19:08862f49cd9e | 45 | printf("FILTER:\nIN= %d,\nOUT (+offs) = %d\n",in,out); |
| lukeocarwright | 19:08862f49cd9e | 46 | printf("MULTIPLIER = %d\n",at); |
| lukeocarwright | 18:204cd747b54a | 47 | printf("SAMPLE_%d\n",samples); |
| lukeocarwright | 19:08862f49cd9e | 48 | #endif |
| lukeocarwright | 19:08862f49cd9e | 49 | samples=samples++; |
| lukeocarwright | 18:204cd747b54a | 50 | return (out); |
| lukeocarwright | 18:204cd747b54a | 51 | } |
| lukeocarwright | 18:204cd747b54a | 52 | |
| lukeocarwright | 19:08862f49cd9e | 53 | uint16_t Envelope::release(int s, int r, int in, bool init) |
| lukeocarwright | 19:08862f49cd9e | 54 | { |
| lukeocarwright | 19:08862f49cd9e | 55 | if (init==true) { |
| lukeocarwright | 19:08862f49cd9e | 56 | sv=s*s*53;// max 64925 = Max Volume (ish) |
| lukeocarwright | 19:08862f49cd9e | 57 | rv=r*r*52;// max 63700 = 4 seconds |
| lukeocarwright | 19:08862f49cd9e | 58 | r_vec=r_vector_calc(sv,rv); |
| lukeocarwright | 19:08862f49cd9e | 59 | at=sv; |
| lukeocarwright | 19:08862f49cd9e | 60 | samples_r=0; |
| lukeocarwright | 19:08862f49cd9e | 61 | silent_flag=0; |
| lukeocarwright | 19:08862f49cd9e | 62 | return(0); |
| lukeocarwright | 19:08862f49cd9e | 63 | } else if (samples_r<=rv) { |
| lukeocarwright | 19:08862f49cd9e | 64 | at=at-r_vec; |
| lukeocarwright | 19:08862f49cd9e | 65 | out=(in*at/63980)+32767; |
| lukeocarwright | 19:08862f49cd9e | 66 | } |
| lukeocarwright | 19:08862f49cd9e | 67 | if(samples_r>rv) { |
| lukeocarwright | 19:08862f49cd9e | 68 | silent_flag=1; |
| lukeocarwright | 19:08862f49cd9e | 69 | } |
| lukeocarwright | 19:08862f49cd9e | 70 | samples_r++; |
| lukeocarwright | 19:08862f49cd9e | 71 | return(out); |
| lukeocarwright | 19:08862f49cd9e | 72 | } |
| lukeocarwright | 18:204cd747b54a | 73 | //PRIVATE:---------------------------------------------------------------------- |
| lukeocarwright | 19:08862f49cd9e | 74 | int Envelope::a_vector_calc(int av) |
| lukeocarwright | 19:08862f49cd9e | 75 | { |
| lukeocarwright | 19:08862f49cd9e | 76 | a_vec=64925/av; |
| lukeocarwright | 18:204cd747b54a | 77 | return(a_vec); |
| lukeocarwright | 19:08862f49cd9e | 78 | } |
| lukeocarwright | 19:08862f49cd9e | 79 | |
| lukeocarwright | 19:08862f49cd9e | 80 | int Envelope::d_vector_calc(int dv, int sv) |
| lukeocarwright | 19:08862f49cd9e | 81 | { |
| lukeocarwright | 19:08862f49cd9e | 82 | d_vec=(64925-sv)/dv; |
| lukeocarwright | 19:08862f49cd9e | 83 | return(d_vec); |
| lukeocarwright | 19:08862f49cd9e | 84 | } |
| lukeocarwright | 19:08862f49cd9e | 85 | int Envelope::r_vector_calc(int sv,int rv) |
| lukeocarwright | 19:08862f49cd9e | 86 | { |
| lukeocarwright | 19:08862f49cd9e | 87 | return(sv/rv); |
| lukeocarwright | 19:08862f49cd9e | 88 | } |