/
AudioSynthBraids.ino
123 lines (105 loc) · 2.87 KB
/
AudioSynthBraids.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//************LIBRARIES USED**************
// include the ResponsiveAnalogRead library for analog smoothing
#include <ResponsiveAnalogRead.h>
#include <Wire.h>
#include <TeensyThreads.h>
#include "synth_braids.h"
#include <Audio.h>
AudioSynthBraids synthBraids;
AudioPlayMemory playmem;
AudioOutputAnalog dacs1;
AudioMixer4 mix1;
AudioConnection patchCord11(playmem, 0, mix1, 0);
AudioConnection patchCord1(synthBraids, 0, mix1, 1);
AudioConnection patchCord2(mix1, 0, dacs1, 0);
// define the pins you want to use and the CC ID numbers on which to send them..
volatile const int ANALOG_PINS[4] = {A0,A1,A2,A3};
// initialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead analog[]{
{ANALOG_PINS[0],true},
{ANALOG_PINS[1],true},
{ANALOG_PINS[2],true},
{ANALOG_PINS[3],true}
};
// initialize required values
// val -> used for set_parameters
// msec -> used for the sequencer
// th1 -> used for thread
volatile int val = 0;
elapsedMillis msec = 0;
int th1;
// initiaize the sequencer
volatile int SEQUENCER_NOTES[8] = {30,40,20,30,40,30,36,30};
volatile int lastnote = 0;
// thread to get parameters from the analog pins
void get_parameters(){
while(1){
for (int i=0;i<3;i++){
analog[i].update();
if (analog[i].hasChanged()) {
val = analog[i].getValue();
Serial.print((val>>4));
Serial.print("\n");
if(val>0){
if(i == 0){
synthBraids.set_braids_shape(val>>4);
}
if(i == 1){
synthBraids.set_braids_color(val<<6);
}
if(i == 2){
synthBraids.set_braids_timbre((val<<6));
}
}
}
}
threads.delay(100);
}
}
// sequencer
void noteSeq(){
// if(msec>=250 && msec<=260){
// playmem.play(AudioSampleSnare);
// }
if(msec>=500){
synthBraids.set_braids_pitch(SEQUENCER_NOTES[lastnote] << 7);
lastnote = lastnote + 1;
if(lastnote == 8){
lastnote = 0;
}
msec = 0;
}
// if(msec>=10){
// analog[3].update();
// if (analog[3].hasChanged()) {
// Serial.print((analog[3].getValue()>>2)<<7);
// Serial.print("\n");
// synthBraids.set_braids_pitch((analog[3].getValue()>>2)<<7);
// }
// msec = 0;
// }
}
//************SETUP**************
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWriteFast(13,HIGH);
// Configure the ADCs
analogReadResolution(9);
analogReadAveraging(4);
analogReference(EXTERNAL);
// Configure the DACs
dacs1.analogReference(INTERNAL);
AudioMemory(100);
mix1.gain(0,5);
mix1.gain(1,5);
// start the parameters thread
th1 = threads.addThread(get_parameters);
// init the audio object AudioSynthBraids
synthBraids.init_braids();
}
//************LOOP**************
void loop() {
noteSeq();
}