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:
- 19:08862f49cd9e
- Parent:
- 18:204cd747b54a
- Child:
- 30:08cc4ec58d07
--- a/Envelope/Envelope.cpp Thu May 21 22:59:59 2020 +0000
+++ b/Envelope/Envelope.cpp Fri May 22 20:10:00 2020 +0000
@@ -1,5 +1,7 @@
#include "mbed.h"
#include "Envelope.h"
+//Global var.
+volatile int silent_flag;
//constructor/destructor
Envelope::Envelope()
@@ -12,38 +14,79 @@
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
+ 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)
+ rv=r*r*52;// max 63700 = 4 seconds
+ samples=0; //initialise sample 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
+ d_vec=d_vector_calc(dv,sv);
at=0;//initialises
- #ifdef SLOW_TIME
- printf("av= %d,\na vector= %d\n\n",av,a_vec);
- #endif
+ /*
+#ifdef SLOW_TIME
+ 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;
- out=in*at/32767;
-
- #ifdef SLOW_TIME
- printf("FILTER:\nIN= %d,\nOUT = %d\n",in,out);
- printf("CUM. INPUT MULTIPLIER = %d\n",at);
- #endif
- }
+ at=at+a_vec; //max=63980
+ out=(in*at/63980)+32767;
+ //printf("ATTACK");
- #ifdef SLOW_TIME
+ } else if(samples>av && samples<=av+dv) {
+ at=at-d_vec;
+ out=(in*at/63980)+32767;
+ //printf("DECAY");
+ } else if (samples>av+dv) {
+ out=(in*sv/65520)+32767;
+ }
+ #ifdef SLOW_TIME
+ printf("FILTER:\nIN= %d,\nOUT (+offs) = %d\n",in,out);
+ printf("MULTIPLIER = %d\n",at);
printf("SAMPLE_%d\n",samples);
- #endif
- samples=samples+1;
+#endif
+ samples=samples++;
return (out);
}
+uint16_t Envelope::release(int s, int r, int in, bool init)
+{
+ if (init==true) {
+ 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;
+ samples_r=0;
+ silent_flag=0;
+ return(0);
+ } else if (samples_r<=rv) {
+ at=at-r_vec;
+ out=(in*at/63980)+32767;
+ }
+ if(samples_r>rv) {
+ silent_flag=1;
+ }
+ samples_r++;
+ return(out);
+}
//PRIVATE:----------------------------------------------------------------------
-int Envelope::a_vector_calc(int av) {
- a_vec=63980/av;
+int Envelope::a_vector_calc(int av)
+{
+ a_vec=64925/av;
return(a_vec);
- }
\ No newline at end of file
+}
+
+int Envelope::d_vector_calc(int dv, int sv)
+{
+ d_vec=(64925-sv)/dv;
+ return(d_vec);
+}
+int Envelope::r_vector_calc(int sv,int rv)
+{
+ return(sv/rv);
+}
\ No newline at end of file