Nucleo F446 Envelope Generator

Dependencies:   mbed

Committer:
ryood
Date:
Sat Jun 30 08:51:09 2018 +0000
Revision:
0:c5e94349541f
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 0:c5e94349541f 1 #include "mbed.h"
ryood 0:c5e94349541f 2 #include "EnvelopeADSR.h"
ryood 0:c5e94349541f 3
ryood 0:c5e94349541f 4 #define TITLE_STR1 ("Nucleo F446 EG")
ryood 0:c5e94349541f 5 #define TITLE_STR2 ("2018.06.28")
ryood 0:c5e94349541f 6
ryood 0:c5e94349541f 7 // Internal DAC
ryood 0:c5e94349541f 8 AnalogOut Aout0(PA_4);
ryood 0:c5e94349541f 9
ryood 0:c5e94349541f 10 // ADSR POT
ryood 0:c5e94349541f 11 AnalogIn Ain0(PC_2);
ryood 0:c5e94349541f 12 AnalogIn Ain1(PC_3);
ryood 0:c5e94349541f 13 AnalogIn Ain2(PC_1);
ryood 0:c5e94349541f 14 AnalogIn Ain3(PC_0);
ryood 0:c5e94349541f 15 AnalogIn Ain4(PB_0);
ryood 0:c5e94349541f 16 AnalogIn Ain5(PA_1);
ryood 0:c5e94349541f 17 AnalogIn Ain6(PA_0);
ryood 0:c5e94349541f 18 AnalogIn Ain7(PC_4);
ryood 0:c5e94349541f 19
ryood 0:c5e94349541f 20 // Envelope
ryood 0:c5e94349541f 21 EnvelopeADSR envelope;
ryood 0:c5e94349541f 22 const int sampleMagnify = 10000; // POTの読み取り値が1.0fの場合のA/D/Rの値
ryood 0:c5e94349541f 23
ryood 0:c5e94349541f 24 // Gate
ryood 0:c5e94349541f 25 InterruptIn gateIn(USER_BUTTON);
ryood 0:c5e94349541f 26
ryood 0:c5e94349541f 27 void gateInterruptRise() {
ryood 0:c5e94349541f 28 envelope.gateOff();
ryood 0:c5e94349541f 29 }
ryood 0:c5e94349541f 30
ryood 0:c5e94349541f 31 void gateInterruptFall() {
ryood 0:c5e94349541f 32 envelope.gateOn();
ryood 0:c5e94349541f 33 }
ryood 0:c5e94349541f 34
ryood 0:c5e94349541f 35 int main()
ryood 0:c5e94349541f 36 {
ryood 0:c5e94349541f 37 printf("\r\n%s %s \r\n", TITLE_STR1, TITLE_STR2);
ryood 0:c5e94349541f 38
ryood 0:c5e94349541f 39 gateIn.rise(&gateInterruptRise);
ryood 0:c5e94349541f 40 gateIn.fall(&gateInterruptFall);
ryood 0:c5e94349541f 41
ryood 0:c5e94349541f 42 while(1) {
ryood 0:c5e94349541f 43 float a0 = Ain0.read();
ryood 0:c5e94349541f 44 float a1 = Ain1.read();
ryood 0:c5e94349541f 45 float a2 = Ain2.read();
ryood 0:c5e94349541f 46 float a3 = Ain3.read();
ryood 0:c5e94349541f 47 float a4 = Ain4.read();
ryood 0:c5e94349541f 48 float a5 = Ain5.read();
ryood 0:c5e94349541f 49 float a6 = Ain6.read();
ryood 0:c5e94349541f 50 float a7 = Ain7.read();
ryood 0:c5e94349541f 51
ryood 0:c5e94349541f 52 // Envelope 1
ryood 0:c5e94349541f 53 int a = a0 * sampleMagnify;
ryood 0:c5e94349541f 54 int d = a1 * sampleMagnify;
ryood 0:c5e94349541f 55 float s = a2;
ryood 0:c5e94349541f 56 int r = a3 * sampleMagnify;
ryood 0:c5e94349541f 57
ryood 0:c5e94349541f 58 envelope.setADSR(a, d, s, r);
ryood 0:c5e94349541f 59 float amplitude = envelope.tick();
ryood 0:c5e94349541f 60
ryood 0:c5e94349541f 61 Aout0.write(amplitude);
ryood 0:c5e94349541f 62
ryood 0:c5e94349541f 63 /*
ryood 0:c5e94349541f 64 printf("%.4f\t%.2f\t%.2f\t%.2f\t%.2f\t\r\n",
ryood 0:c5e94349541f 65 amplitude, a0, a1, a2, a3);
ryood 0:c5e94349541f 66 */
ryood 0:c5e94349541f 67
ryood 0:c5e94349541f 68 }
ryood 0:c5e94349541f 69 }