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: Envelope/Envelope.cpp
- Revision:
- 31:cfdb014ff086
- Parent:
- 30:08cc4ec58d07
--- a/Envelope/Envelope.cpp Tue May 26 10:17:47 2020 +0000
+++ b/Envelope/Envelope.cpp Tue May 26 14:21:36 2020 +0000
@@ -1,7 +1,7 @@
#include "mbed.h"
#include "Envelope.h"
//Global var.
-volatile int silent_flag;
+volatile int silent_flag; //used to trigger note off
//constructor/destructor
Envelope::Envelope()
@@ -13,8 +13,8 @@
//PUBLIC------------------------------------------------------------------------
uint16_t Envelope::env_in(int a, int d, int s, int r, int in, bool init)
{
- if(init==true) {
- printf("INITIATING ENVELOPE\n");
+ if(init==true) { //initial value set
+ //printf("INITIATING ENVELOPE\n");
av=a*a*52;// max 63700 = 4 seconds (ish)
dv=d*d*52;// max 63700 = 4 seconds
sv=s*s*53;// max 64925 = Max Volume (ish)
@@ -23,51 +23,51 @@
a_vec=a_vector_calc(av); //initialise a value for a dif
d_vec=d_vector_calc(dv,sv); //initialise a value for d dif
at=0;//initialises
-#ifdef SLOW_TIME
+#ifdef SLOW_TIME //SLOW_TIME print variables
printf("INITIATING ENVELOPE\n");
printf("a=%d,av= %d,a vector= %d\n",a,av,a_vec);
printf("d=%d,dv= %d,d vector= %d\n",d,dv,d_vec);
printf("s=%d,sv= %d\n",s,sv);
#endif
}
- if (samples<=av) {
- at=at+a_vec; //max=63980
+ if (samples<=av) { //Attack transient
+ at=at+a_vec; //itterates multiplier
out=(in*at/63980)+32767;
//printf("ATTACK");
- } else if(samples>av && samples<=av+dv) {
- at=at-d_vec;
+ } else if(samples>av && samples<=av+dv) { //Decay Transient
+ at=at-d_vec; //iterates multiplier
out=(in*at/63980)+32767;
//printf("DECAY");
- } else if (samples>av+dv) {
+ } else if (samples>av+dv) { //Sustain
out=(in*sv/65520)+32767;
}
- #ifdef SLOW_TIME
+ #ifdef SLOW_TIME //SLOW_TIME print statements
printf("FILTER:\nIN= %d,\nOUT (+offs) = %d\n",in,out);
printf("MULTIPLIER = %d\n",at);
printf("SAMPLE_%d\n",samples);
#endif
- samples=samples++;
+ samples=samples++; //itterates samples
return (out);
}
uint16_t Envelope::release(int s, int r, int in, bool init)
{
- if (init==true) {
+ if (init==true) { //Initial Value Set
sv=s*s*53;// max 64925 = Max Volume (ish)
rv=r*r*52;// max 63700 = 4 seconds
r_vec=r_vector_calc(sv,rv);
- at=sv;
+ at=sv; //Initial Value
samples_r=0;
silent_flag=0;
return(0);
- } else if (samples_r<=rv) {
- at=at-r_vec;
+ } else if (samples_r<=rv) { //upto end of decay transient
+ at=at-r_vec; //itterates Multiplier
out=(in*at/63980)+32767;
}
- if(samples_r>rv) {
- silent_flag=1;
+ if(samples_r>rv) { //past note end
+ silent_flag=1; //Triggers Note off
}
- samples_r++;
+ samples_r++; //itterates samples
return(out);
}
//PRIVATE:----------------------------------------------------------------------