Browse code

add tmp dir with old sketch

frtk authored on 18/03/2016 20:19:00
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,250 @@
0
+/*
1
+
2
+  @file     tb3337.ino
3
+  @purpose  Arduino audio spatializer module
4
+  @links    https://www.arduino.cc/en/Tutorial/DigitalPotControl       
5
+            http://auto.polytech.univ-tours.fr/telechargements/fichiers/SA.poly.pdf 
6
+  @notes  
7
+  Controls :
8
+  + 1 digital potentiometer [audio volumes for each channel/speaker]
9
+  + 1 analog potentiometer [sequence switch]
10
+  + 1 analog potentiometer [sequence speed]
11
+  ? 1 analog potentiometer [signal shape: linear, sin, gaussian?, etc..]
12
+  ? 1 analog input [trigger spatialization effect on audio input]
13
+
14
+  @todo
15
+  - add signal shape functions (lin, sin, gauss, etc..)
16
+  - add trigger input interactions
17
+  - add colliding sound walls and rotating sound slice effects
18
+ 
19
+*/
20
+
21
+/**
22
+ *
23
+ * INCLUDE
24
+ *
25
+ */
26
+// SPI library:
27
+#include <SPI.h>
28
+
29
+
30
+/**
31
+ *
32
+ * GLOBAL VARIABLES
33
+ *
34
+ */
35
+// Serial console messages
36
+boolean serial_on = true;
37
+long serial_rate = 9600; 
38
+boolean serial_dbug = true;
39
+
40
+// set pin 10 as the slave select for the digital pot:
41
+const int slaveSelectPin = 10;
42
+
43
+//la vitesse, ou plus exactement le délai entre chaque pas de séquence.
44
+//Cette valeur est lue sur le input analogue A0 dans la fonction readSpeed. 
45
+unsigned char myspeed=10;
46
+
47
+int main_speakers[2] = {0, 1};
48
+
49
+int n_speakers = 6;
50
+int* seq;
51
+int seq1[6] = {0,1,2,3,4,5}; 
52
+int seq2[6] = {0,5,4,3,2,1};
53
+int seq3[6] = {0,3,5,1,4,2};
54
+
55
+bool seq_on = false;
56
+
57
+int seq_size = 6;
58
+int seq_step = 0;
59
+
60
+int sp_vol[6] = {0,0,0,0,0,0};   
61
+
62
+int curr_sp_idx = 0;
63
+int curr_seq_idx = 0;
64
+int next_sp_idx = 0;
65
+int next_seq_idx = 0;
66
+
67
+int curr_step_idx = 0;
68
+int n_steps = 8;  // peut etre modifie par un potard aussi
69
+int vol_step = 256/n_steps;
70
+const int vol_max = 255;
71
+
72
+
73
+
74
+/**
75
+ *
76
+ * SETUP
77
+ *
78
+ */
79
+void setup() {
80
+  // set the slaveSelectPin as an output:
81
+  Serial.begin(9600);
82
+  pinMode(slaveSelectPin, OUTPUT);
83
+  // initialize SPI
84
+  SPI.begin();
85
+
86
+  // 
87
+  seq = (int *)seq1;
88
+  curr_seq_idx = 0;
89
+  next_seq_idx = 1;
90
+  next_sp_idx = seq[next_seq_idx];
91
+}
92
+
93
+
94
+
95
+/**
96
+ *
97
+ * LOOP
98
+ *
99
+ */
100
+void loop() {
101
+
102
+  // check if sequence was changed (analog pot A2)
103
+  checkSequenceSwitch();
104
+   
105
+  // update current sequence
106
+  updateSeq(); 
107
+
108
+  // new speakers volume calculation
109
+  updateSpeakersVolume();
110
+
111
+  // send speakers volume to digital pot 
112
+  for (int channel = 0; channel < 6; channel++) { 
113
+    digitalPotWrite(channel,sp_vol[channel]);
114
+  }
115
+
116
+  // dbug
117
+  if (serial_dbug) {
118
+    printSpeakersVolume(); 
119
+    //printIdx();
120
+  }
121
+
122
+  // delay sequence speed
123
+  delay(readSpeed()); 
124
+}
125
+
126
+
127
+
128
+/**
129
+ *
130
+ * GENERAL FUNCTIONS
131
+ *
132
+ */
133
+void checkSequenceSwitch(){
134
+  int sensorValue2 = analogRead(A2);
135
+  //Serial.println(sensorValue2);
136
+
137
+  seq_on = true;
138
+  if (sensorValue2 >= 256 && sensorValue2 < 512) seq=(int*)seq1;
139
+  else if (sensorValue2 >= 512 && sensorValue2 < 768) seq=(int*)seq2;
140
+  else if (sensorValue2 >= 768) seq=(int*)seq3;
141
+  else seq_on = false;
142
+}
143
+
144
+
145
+void updateSeq() {
146
+  //
147
+  if (curr_step_idx < n_steps - 1) {
148
+    curr_step_idx++;     
149
+  } else {
150
+    curr_step_idx = 0;
151
+    incrSeqIdx(); 
152
+  }
153
+  //
154
+  curr_sp_idx = seq[curr_seq_idx];
155
+  next_sp_idx = seq[next_seq_idx]; 
156
+  
157
+}
158
+
159
+
160
+void incrSeqIdx() { 
161
+  //
162
+  if (next_seq_idx == seq_size - 1) {
163
+    next_seq_idx = 0;
164
+    curr_seq_idx = seq_size - 1; 
165
+  } else {
166
+    //Serial.println("YOOOOOOOOOOOOOOOOOOOO");
167
+    next_seq_idx++;
168
+    curr_seq_idx++; 
169
+  }
170
+}
171
+
172
+
173
+
174
+void updateSpeakersVolume() {
175
+  if (seq_on) {
176
+    for (int idx = 0; idx < n_speakers; idx++) { 
177
+      if (idx == curr_sp_idx) {
178
+        sp_vol[idx] = (sp_vol[idx] - vol_step >= 0) ? sp_vol[idx] - vol_step : 0;  
179
+      } else if (idx == next_sp_idx) {
180
+        sp_vol[idx] = (sp_vol[idx] + vol_step < vol_max) ? sp_vol[idx] + vol_step : vol_max;  
181
+      } else {
182
+        sp_vol[idx]= 0;
183
+      }
184
+    }
185
+  } else {
186
+    sp_vol[0] = 230;
187
+    sp_vol[1] = 230;
188
+    sp_vol[2] = 0;
189
+    sp_vol[3] = 0;
190
+    sp_vol[4] = 0;
191
+    sp_vol[5] = 0;
192
+  } 
193
+}
194
+
195
+
196
+
197
+/*
198
+ *  
199
+ *  FUNCTIONS
200
+ * 
201
+ */
202
+int readSpeed(){
203
+  int sensorValue = analogRead(A0)/10 +1;
204
+  if (myspeed/4 != sensorValue/4) {
205
+    myspeed = sensorValue;
206
+  }
207
+  return sensorValue;
208
+}
209
+
210
+
211
+// 
212
+void digitalPotWrite(int address, int value) {
213
+  // take the SS pin low to select the chip:
214
+  digitalWrite(slaveSelectPin, LOW);
215
+  //  send in the address and value via SPI:
216
+  SPI.transfer(address);
217
+  SPI.transfer(value);
218
+  // take the SS pin high to de-select the chip:
219
+  digitalWrite(slaveSelectPin, HIGH);
220
+}
221
+
222
+
223
+//
224
+void printSpeakersVolume() { 
225
+  //
226
+  if (serial_on) {
227
+    Serial.println("$ Speakers volumes:"); 
228
+    for (int i = 0; i < n_speakers; i++) { 
229
+      Serial.print(sp_vol[i]);
230
+      Serial.print(", ");
231
+    }
232
+    Serial.println("");
233
+  }
234
+}
235
+
236
+
237
+//
238
+void printIdx() { 
239
+  //
240
+  if (serial_on) {
241
+    Serial.print(curr_seq_idx);
242
+    Serial.print(", ");
243
+    Serial.print(curr_sp_idx);
244
+    Serial.print(", ");  
245
+    Serial.print(next_seq_idx);
246
+    Serial.print(", ");
247
+    Serial.println(next_sp_idx); 
248
+  }
249
+}
0 250
\ No newline at end of file
1 251
new file mode 100644
... ...
@@ -0,0 +1,271 @@
0
+/*
1
+
2
+  @file     sptlzr.ino
3
+  @purpose  Arduino audio spatializer module
4
+  @links    https://www.arduino.cc/en/Tutorial/DigitalPotControl       
5
+            http://auto.polytech.univ-tours.fr/telechargements/fichiers/SA.poly.pdf 
6
+  @notes  
7
+  Controls :
8
+  + 1 digital potentiometer [audio volumes for each channel/speaker] : slave select set to pin 10
9
+  + 1 analog potentiometer ? [sequence switch]
10
+  + 1 analog potentiometer ? [sequence speed]
11
+  + 1 analog potentiometer ? [signal shape: linear, sin, gaussian?, etc..]
12
+  + 1 push button ?
13
+  + 1 control voltage input ? [trigger spatialization effect on audio input]
14
+
15
+  @todo
16
+  - add signal shape functions (lin, sin, gauss, etc..)
17
+  - add trigger input interactions
18
+  - add colliding sound walls and rotating sound slice effects
19
+ 
20
+*/
21
+
22
+
23
+/*
24
+
25
+  INCLUDE
26
+ 
27
+*/
28
+// SPI library:
29
+#include <SPI.h>
30
+
31
+
32
+
33
+/*
34
+ 
35
+  GLOBAL VARIABLES
36
+ 
37
+*/
38
+
39
+/*
40
+ * Serial console messages
41
+ */
42
+boolean serial_on = true;
43
+long serial_rate = 9600; 
44
+boolean serial_dbug = true;
45
+
46
+/*
47
+ * Arduino pins
48
+ */
49
+// Speakers volume digital pot slave select pin
50
+const int dpot_sp_vol_pin = 10;
51
+// sequence witch analog pot pin 
52
+int seq_switch_pot_pin = A0;
53
+// sequence speed analog pot pin
54
+int seq_speed_pot_pin = A1; 
55
+// signal shape analog pot pin
56
+int sig_shape_pot_pin = A2;
57
+// push button pin
58
+int button_pin = 2;
59
+// cv input pin
60
+int cvin_pin = 3;
61
+
62
+/*
63
+ * Speakers
64
+ */
65
+const int n_speakers = 6;
66
+unsigned char sp_vol[n_speakers] = { 0 };
67
+
68
+/*
69
+ * Sequence
70
+ */
71
+int* seq;
72
+int seq1[6] = {0,1,2,3,4,5}; 
73
+int seq2[6] = {0,5,4,3,2,1};
74
+int seq3[6] = {0,3,5,1,4,2};
75
+bool seq_on = false;
76
+int seq_size = 6;
77
+int seq_step = 0;
78
+unsigned char seq_speed = 10;
79
+
80
+
81
+int curr_sp_idx = 0;
82
+int curr_seq_idx = 0;
83
+int next_sp_idx = 0;
84
+int next_seq_idx = 0;
85
+
86
+int curr_step_idx = 0;
87
+int n_steps = 8;  // peut etre modifie par un potard aussi
88
+int vol_step = 256/n_steps;
89
+const int vol_max = 255;
90
+
91
+
92
+
93
+
94
+
95
+/**
96
+ *
97
+ * SETUP
98
+ *
99
+ */
100
+void setup() {
101
+  // set the slaveSelectPin as an output:
102
+  Serial.begin(9600);
103
+  pinMode(dpot_sp_vol_pin, OUTPUT);
104
+  // initialize SPI
105
+  SPI.begin();
106
+
107
+  // 
108
+  seq = (int *)seq1;
109
+  curr_seq_idx = 0;
110
+  next_seq_idx = 1;
111
+  next_sp_idx = seq[next_seq_idx];
112
+}
113
+
114
+
115
+
116
+/**
117
+ *
118
+ * LOOP
119
+ *
120
+ */
121
+void loop() {
122
+
123
+  // check if sequence was changed (analog pot A2)
124
+  checkSequenceSwitch();
125
+   
126
+  // update current sequence
127
+  updateSeq(); 
128
+
129
+  // new speakers volume calculation
130
+  updateSpeakersVolume();
131
+
132
+  // send speakers volume to digital pot 
133
+  for (int channel = 0; channel < 6; channel++) { 
134
+    digitalPotWrite(channel,sp_vol[channel]);
135
+  }
136
+
137
+  // dbug
138
+  if (serial_dbug) {
139
+    printSpeakersVolume(); 
140
+    //printIdx();
141
+  }
142
+
143
+  // delay sequence speed
144
+  delay(readSpeed()); 
145
+}
146
+
147
+
148
+
149
+/**
150
+ *
151
+ * GENERAL FUNCTIONS
152
+ *
153
+ */
154
+void checkSequenceSwitch(){
155
+  int sensorValue2 = analogRead(A2);
156
+  Serial.println(sensorValue2);
157
+
158
+  seq_on = true;
159
+  if (sensorValue2 >= 256 && sensorValue2 < 512) seq=(int*)seq1;
160
+  else if (sensorValue2 >= 512 && sensorValue2 < 768) seq=(int*)seq2;
161
+  else if (sensorValue2 >= 768) seq=(int*)seq3;
162
+  else seq_on = false;
163
+}
164
+
165
+
166
+void updateSeq() {
167
+  //
168
+  if (curr_step_idx < n_steps - 1) {
169
+    curr_step_idx++;     
170
+  } else {
171
+    curr_step_idx = 0;
172
+    incrSeqIdx(); 
173
+  }
174
+  //
175
+  curr_sp_idx = seq[curr_seq_idx];
176
+  next_sp_idx = seq[next_seq_idx]; 
177
+  
178
+}
179
+
180
+
181
+void incrSeqIdx() { 
182
+  //
183
+  if (next_seq_idx == seq_size - 1) {
184
+    next_seq_idx = 0;
185
+    curr_seq_idx = seq_size - 1; 
186
+  } else {
187
+    //Serial.println("YOOOOOOOOOOOOOOOOOOOO");
188
+    next_seq_idx++;
189
+    curr_seq_idx++; 
190
+  }
191
+}
192
+
193
+
194
+
195
+void updateSpeakersVolume() {
196
+  if (seq_on) {
197
+    for (int idx = 0; idx < n_speakers; idx++) { 
198
+      if (idx == curr_sp_idx) {
199
+        sp_vol[idx] = (sp_vol[idx] - vol_step >= 0) ? sp_vol[idx] - vol_step : 0;  
200
+      } else if (idx == next_sp_idx) {
201
+        sp_vol[idx] = (sp_vol[idx] + vol_step < vol_max) ? sp_vol[idx] + vol_step : vol_max;  
202
+      } else {
203
+        sp_vol[idx]= 0;
204
+      }
205
+    }
206
+  } else {
207
+    sp_vol[0] = 230;
208
+    sp_vol[1] = 230;
209
+    sp_vol[2] = 0;
210
+    sp_vol[3] = 0;
211
+    sp_vol[4] = 0;
212
+    sp_vol[5] = 0;
213
+  } 
214
+}
215
+
216
+
217
+
218
+/*
219
+ *  
220
+ *  FUNCTIONS
221
+ * 
222
+ */
223
+int readSpeed(){
224
+  int sensorValue = analogRead(A0)/10 +1;
225
+  if (seq_speed/4 != sensorValue/4) {
226
+    seq_speed = sensorValue;
227
+  }
228
+  return sensorValue;
229
+}
230
+
231
+
232
+// 
233
+void digitalPotWrite(int address, int value) {
234
+  // take the SS pin low to select the chip:
235
+  digitalWrite(dpot_sp_vol_pin, LOW);
236
+  //  send in the address and value via SPI:
237
+  SPI.transfer(address);
238
+  SPI.transfer(value);
239
+  // take the SS pin high to de-select the chip:
240
+  digitalWrite(dpot_sp_vol_pin, HIGH);
241
+}
242
+
243
+
244
+//
245
+void printSpeakersVolume() { 
246
+  //
247
+  if (serial_on) {
248
+    Serial.println("$ Speakers volumes:"); 
249
+    for (int i = 0; i < n_speakers; i++) { 
250
+      Serial.print(sp_vol[channel]);
251
+      Serial.print(", ");
252
+    }
253
+    Serial.println("");
254
+  }
255
+}
256
+
257
+
258
+//
259
+void printIdx() { 
260
+  //
261
+  if (serial_on) {
262
+    Serial.print(curr_seq_idx);
263
+    Serial.print(", ");
264
+    Serial.print(curr_sp_idx);
265
+    Serial.print(", ");  
266
+    Serial.print(next_seq_idx);
267
+    Serial.print(", ");
268
+    Serial.println(next_sp_idx); 
269
+  }
270
+}
0 271
\ No newline at end of file
1 272
new file mode 100644
... ...
@@ -0,0 +1,112 @@
0
+/*
1
+
2
+  @file     sptlzr_pots_test.ino
3
+  @purpose  Spatializer module potentiometers test
4
+  @links    https://www.arduino.cc/en/tutorial/pushbutton
5
+  @notes
6
+    Potentiometers :
7
+      + 3 analog potentiometer : arduino pins A0, A1, A2
8
+      + 1 push button : arduino pin 2 (digital) 
9
+      + 1 control voltage input : analog pin A3
10
+
11
+*/
12
+
13
+
14
+/**
15
+ *
16
+ * INCLUDE
17
+ *
18
+ */
19
+// SPI library:
20
+#include <SPI.h>
21
+
22
+
23
+
24
+/**
25
+ *
26
+ * GLOBAL VARIABLES
27
+ *
28
+ */
29
+// Serial console messages
30
+boolean serial_on = true;
31
+long serial_rate = 9600; 
32
+boolean serial_dbug = true;
33
+
34
+// Digital pots
35
+int dpot_pb_pin = 2;
36
+
37
+// Analog pots
38
+int apot_1_pin = A0;
39
+int apot_2_pin = A1;
40
+int apot_3_pin = A2;
41
+
42
+// trigger input (cv in)
43
+int cvin_pin = A3;
44
+
45
+
46
+
47
+/**
48
+ *
49
+ * SETUP
50
+ *
51
+ */
52
+void setup() {
53
+
54
+  //
55
+  if (serial_on) Serial.begin(serial_rate);
56
+  // push button
57
+  pinMode(dpot_pb_pin, INPUT);
58
+  digitalWrite(dpot_pb_pin, HIGH); // pull-up
59
+
60
+}
61
+
62
+
63
+
64
+/**
65
+ *
66
+ * LOOP
67
+ *
68
+ */
69
+void loop() {
70
+  //
71
+  Serial.println("$$$  Pots values  $$$");
72
+  //
73
+  Serial.print("analog pots: 1= ");
74
+  Serial.print(readAnalogPot(apot_1_pin));
75
+  Serial.print(", 2= "); 
76
+  Serial.print(readAnalogPot(apot_2_pin));
77
+  Serial.print(", 3= "); 
78
+  Serial.print(readAnalogPot(apot_3_pin));
79
+  //
80
+  Serial.print(" | push_button : "); 
81
+  int push_button_state = readPushButtonState();
82
+  Serial.print(push_button_state ? "DOWN" : "UP");
83
+  //
84
+  Serial.print(" | CV IN = "); 
85
+  Serial.println(readAnalogPot(cvin_pin));
86
+    
87
+
88
+  // delay sequence speed
89
+  delay(100); 
90
+}
91
+
92
+
93
+
94
+/**
95
+ *
96
+ * GENERAL FUNCTIONS
97
+ *
98
+ */
99
+//
100
+int readAnalogPot(int pin) {
101
+  return analogRead(pin);
102
+}
103
+
104
+
105
+//
106
+int readPushButtonState() {
107
+  int button_pressed = !digitalRead(dpot_pb_pin); // pin low -> pressed 
108
+  return button_pressed;
109
+}
110
+
111
+