Browse Source

add tmp dir with old sketch

frtk 4 years ago
parent
commit
986894f366
3 changed files with 633 additions and 0 deletions
  1. 250
    0
      tmp/sptlzr_0.ino
  2. 271
    0
      tmp/sptlzr_1.ino
  3. 112
    0
      tmp/sptlzr_pots_test.ino

+ 250
- 0
tmp/sptlzr_0.ino View File

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

+ 271
- 0
tmp/sptlzr_1.ino View File

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

+ 112
- 0
tmp/sptlzr_pots_test.ino View File

@@ -0,0 +1,112 @@
1
+/*
2
+
3
+  @file     sptlzr_pots_test.ino
4
+  @purpose  Spatializer module potentiometers test
5
+  @links    https://www.arduino.cc/en/tutorial/pushbutton
6
+  @notes
7
+    Potentiometers :
8
+      + 3 analog potentiometer : arduino pins A0, A1, A2
9
+      + 1 push button : arduino pin 2 (digital) 
10
+      + 1 control voltage input : analog pin A3
11
+
12
+*/
13
+
14
+
15
+/**
16
+ *
17
+ * INCLUDE
18
+ *
19
+ */
20
+// SPI library:
21
+#include <SPI.h>
22
+
23
+
24
+
25
+/**
26
+ *
27
+ * GLOBAL VARIABLES
28
+ *
29
+ */
30
+// Serial console messages
31
+boolean serial_on = true;
32
+long serial_rate = 9600; 
33
+boolean serial_dbug = true;
34
+
35
+// Digital pots
36
+int dpot_pb_pin = 2;
37
+
38
+// Analog pots
39
+int apot_1_pin = A0;
40
+int apot_2_pin = A1;
41
+int apot_3_pin = A2;
42
+
43
+// trigger input (cv in)
44
+int cvin_pin = A3;
45
+
46
+
47
+
48
+/**
49
+ *
50
+ * SETUP
51
+ *
52
+ */
53
+void setup() {
54
+
55
+  //
56
+  if (serial_on) Serial.begin(serial_rate);
57
+  // push button
58
+  pinMode(dpot_pb_pin, INPUT);
59
+  digitalWrite(dpot_pb_pin, HIGH); // pull-up
60
+
61
+}
62
+
63
+
64
+
65
+/**
66
+ *
67
+ * LOOP
68
+ *
69
+ */
70
+void loop() {
71
+  //
72
+  Serial.println("$$$  Pots values  $$$");
73
+  //
74
+  Serial.print("analog pots: 1= ");
75
+  Serial.print(readAnalogPot(apot_1_pin));
76
+  Serial.print(", 2= "); 
77
+  Serial.print(readAnalogPot(apot_2_pin));
78
+  Serial.print(", 3= "); 
79
+  Serial.print(readAnalogPot(apot_3_pin));
80
+  //
81
+  Serial.print(" | push_button : "); 
82
+  int push_button_state = readPushButtonState();
83
+  Serial.print(push_button_state ? "DOWN" : "UP");
84
+  //
85
+  Serial.print(" | CV IN = "); 
86
+  Serial.println(readAnalogPot(cvin_pin));
87
+    
88
+
89
+  // delay sequence speed
90
+  delay(100); 
91
+}
92
+
93
+
94
+
95
+/**
96
+ *
97
+ * GENERAL FUNCTIONS
98
+ *
99
+ */
100
+//
101
+int readAnalogPot(int pin) {
102
+  return analogRead(pin);
103
+}
104
+
105
+
106
+//
107
+int readPushButtonState() {
108
+  int button_pressed = !digitalRead(dpot_pb_pin); // pin low -> pressed 
109
+  return button_pressed;
110
+}
111
+
112
+

Loading…
Cancel
Save