CSUSM FM Synth 2017 / Mbed 2 deprecated FMSynthCSUSM

Dependencies:   mbed

Fork of STM32FMSynth by Steven Clark

Revision:
2:5454dee210ed
Parent:
1:f3350a372732
Child:
3:83ac767f3a63
diff -r f3350a372732 -r 5454dee210ed main.cpp
--- a/main.cpp	Thu Nov 09 22:40:50 2017 +0000
+++ b/main.cpp	Mon Nov 27 22:05:48 2017 +0000
@@ -20,6 +20,11 @@
 AnalogIn ADC14(PC_4);
 AnalogIn ADC15(PC_5);
 
+BusIn keyBank(PC_10, PC_11, PC_12, PC_13, PC_14, PC_15);
+BusOut keySelect(PB_0, PB_1, PB_2, PB_3, PB_4, PB_5, PB_6, PB_7, PB_8);
+BusIn numerator(PA_8, PA_9, PA_10, PA_11);
+BusIn denominator(PA_12, PA_13, PA_14, PA_15);
+
 //Renaming ports
 #define inVol ADC0
 #define inModAmt ADC1
@@ -33,11 +38,14 @@
 #define inModR ADC15
 #define outMono DAC0
 
-#define numKeys 88
+#define numKeys 49
 #define PI M_PI
 
 //possible constants
 int carrierIncrements[numKeys];
+/*
+going to build table here later.
+*/
 const int attackLimit = (0x1 << 16) - 1;
 const int fixed2Pi = (int) ((2.0 * PI) * (0x1 << 16));
 
@@ -50,7 +58,8 @@
 int modVol;
 int modAmpI;
 int carAmpS;
-bool keysPressed[numKeys];
+//bool keysPressed[numKeys];
+int64_t keyboard;
 int carrierPhases[numKeys];
 int modulatorPhases[numKeys];
 short envelopeStatesC[numKeys];
@@ -74,7 +83,7 @@
 void synthesize(){
     carAmpS = 0;
     for(int i = 0; i < numKeys; ++i){
-        if(keysPressed[i]){
+        if(keyboard & (0x1 << i)){
             if(envelopeStatesC[i] < 2)
                 envelopeStatesC[i] = 4;
             if(envelopeStatesM[i] < 2)
@@ -148,4 +157,27 @@
 
 
 int main() {
+    int ratNumer;
+    int ratDenom;
+    
+    while(true){
+        ratNumer = 0xf & ~ numerator;
+        ratDenom = 0xf & ~ denom;
+        FMult = (ratNumer << 16) / ratDenom;
+        
+        Volume = (int)inVol.read_u16();
+        modVol = (int)inModAmt.read_u16();
+        
+        carA = 0xffff / ((int)inCarA.read_u16());
+        carD = 0xffff / ((int)inCarD.read_u16());
+        carS = (int)inCarS.read_u16();
+        carR = 0xffff / ((int)inCarR.read_u16());
+        
+        modA = 0xffff / ((int)inModA.read_u16());
+        modD = 0xffff / ((int)inModD.read_u16());
+        modS = (int)inModS.read_u16();
+        modR = 0xffff / ((int)inModR.read_u16());
+        
+        
+    }
 }