KIK 01 Prototype 05

Dependencies:   AverageMCP3008 mbed-rtos mbed mcp3008

Fork of KIK01_Proto03 by Ryo Od

Revision:
12:5b498285d121
Parent:
11:7e11404adca0
Child:
13:43a43da257e3
--- a/main.cpp	Tue Jun 06 12:25:19 2017 +0000
+++ b/main.cpp	Tue Jun 06 15:31:41 2017 +0000
@@ -10,13 +10,14 @@
 #include "rtos.h"
 
 #define UART_TRACE      (1)
+#define PIN_CHECK       (1)
 #define TITLE_STR1      ("KIK01 Kick Machine")
 #define TITLE_STR2      ("20170606")
 
 #define PI_F            (3.1415926f)
 #define SAMPLING_RATE   (96000)
 #define SAMPLING_PERIOD (1.0f/SAMPLING_RATE)
-#define UPDATE_RATE     (32000)
+#define ENVELOPE_UPDATE_RATE    (32000)
 
 AnalogOut Dac1(PA_5);
 
@@ -34,6 +35,9 @@
 AnalogIn Ain10(PC_5);
 AnalogIn Ain11(PA_6);
 
+DigitalOut Dout0(PA_10);
+DigitalOut Dout1(PB_3);
+
 class EnvelopeAR
 {
 public:
@@ -189,13 +193,20 @@
     envelopeTicks++;
     if (envelopeTicks >= envelopeLength) {
         envelopeTicks = 0;
+        phi = PI_F / 2.0f;
     }
 }
 
 void update()
 {
+#if (PIN_CHECK)
+        Dout0 = 1;
+#endif
     ticks++;
-    if (ticks >= SAMPLING_RATE / UPDATE_RATE) {
+    if (ticks >= SAMPLING_RATE / ENVELOPE_UPDATE_RATE) {
+#if (PIN_CHECK)
+        Dout1 = 1;
+#endif        
         ticks = 0;
 
         // set envelope parameters
@@ -216,14 +227,20 @@
         envelopeFrequency.setReleaseTauRatio(frequencyParam.releaseTauRatio);
 
         generateEnvelope();
+#if (PIN_CHECK)
+        Dout1 = 0;
+#endif
     }
     generateWave();
+#if (PIN_CHECK)
+        Dout0 = 0;
+#endif
 }
 
 void setParams()
 {
     bpm = Ain0.read() * 180.0f + 60.0f;
-    envelopeLength = 60 * UPDATE_RATE / bpm;
+    envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
 
     amplitudeParam.attack = Ain1.read() * envelopeLength;
     amplitudeParam.release = Ain2.read() * envelopeLength;