Loading...
Pages: [1]   Go Down
Author Topic: Troubleshooting code for interactive Audio Sculpture  (Read 599 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey there, I have built an instrument that I dreamt up, and am trying to write the code that would allow me to play the instrument as I see fit.  I'm calling it a Victorian Synthesizer.


The arduino board and 1/4" out is mounted underneath the platter, and there are 5 FSR's underneath the silver foil layer underneath each shell, so pressing the shell controls the value read by the analog inputs.

I have written out the code as much as I can understand, and I know that it needs some tweaking in order for it to work properly.  I would truly appreciate any advice that you may have for how to get it up and running properly.
I am pretty well versed in analog audio circuits, and plan on building some sort of VCF to help make the output sound nicer than just a square wave....i've been doing research on how to produce a rough sine wave out of square waves, but that will be a different topic smiley-wink  for now, i'm just trying to get the code up and running.



The wiring is just 5 FSR's hooked up as voltage dividers going into the analog ins.
The four shells on the top will play the root note for a chord, and the shell at the bottom will play the corresponding scale depending on which root note is chosen

Here's the code I have written.  It compiles but is not fully efficient:
Code:
//Victorian Synth Attempts.  
//analog in 0-4 and audio out on digital 3

//define analog inputs
#define SCALE_KEY (0)
#define C1_KEY   (1)
#define Gs1_KEY  (2)
#define D1_KEY   (3)
#define G1_KEY   (4)

void setup() {
  Serial.begin(9600);    //might use the serial monitor once this is up and running
   pinMode (3,OUTPUT);   //Audio Out pin
}

void loop() {
//  int C1_KEYread = analogRead  (A1);
//  int Gs1_KEYread = analogRead (A2);
//  int D1_KEYread = analogRead  (A3);
//  int G1_KEYread = analogRead  (A4);
 

int AudioOut = 3;
AudioOut = analogRead(SCALE_KEY);    //Play the SCALE Key through digital out pin 3

//mapped notes
int mapC1[] = {98,117,131,165,196,233,262,330,392,466,523,659,784,932,
1175,1319,1568,1865
};

int mapGs1[] = {65,78,104,131,156,208,262,311,415,523,622,831,1047,1245,
1661,2093
};

int mapD1[] = {39,44,49,52,58,65,73,78,87,98,104,117,131,147,156,175,196,
208,233,262,294,311,349,392,415,466,523,587,622,698,784,831,932,
1047,1175,1245,1397,1568,1661,1865,2093,2349
};

int mapG1[] = {65,82,98,117,131,165,196,233,262,330,392,466,523,659,784,
932,1175,1319,1568,1865
};


  

// mapped scale to play is dependent upon which key is being pressed

digitalRead(C1_KEY);   //check the state of C1 Key
digitalRead(Gs1_KEY);  //check the state of Gs1 Key
digitalRead(D1_KEY);   //check the state of D1 Key
digitalRead(G1_KEY);   //check the state of G1 Key

if (C1_KEY < 5) {    //if C1 Key is being pressed...(5 was just chosen, can be anything above 0 really)
  tone(3,33);        //play the root note C1 constantly while C1 key is pressed
  int mapC1(analogRead(SCALE_KEY));    //play the C1 scale on the Scale Key
}
  else {
     if (Gs1_KEY < 5) {    //if Gs1 Key is pressed
        tone(3,52);         //play the root note Gs1 constantly while D1 key is pressed
        int mapGs1(analogRead(SCALE_KEY));  //play the Gs1 scale on the Scale Key
     }        
     else {
        if (D1_KEY < 5) {    //if D1 Key is pressed
          tone(3,37);          //play the root note D1 constantly while D1 key is pressed
          int mapD1(analogRead(SCALE_KEY));    //play the D1 scale on the Scale key
        }
       else {
          if (G1_KEY < 5) {    //if G1 Key is pressed
            tone(3,49);          //play the root note G1 constantly while G1 key is pressed
             int mapG1(analogRead(SCALE_KEY));
          }  
}
}
}  
}
  


Here's the Chart that states the Note recognized through the library pitches.h as well as the number value.  I just used the number value instead of including the library.

C1   33   <--ROOT
G2   98   <--Corresponding Scale
As2   117
C3   131
E3   165
G3   196
As3   233
C4   262
E4   330
G4   392
As4   466
C5   523
E5   659
G5   784
As5   932
C6   1175
E6   1319
G6   1568
As6   1865

Gs1   52  <--ROOT
C2   65       <---corresponding scale
Ds2   78
Gs2   104
C3   131
Ds3   156
Gs3   208
C4   262
Ds4   311
Gs4   415
C5   523
Ds5   622
Gs5   831
C6   1047
Ds6   1245
Gs6   1661
C7   2093

D1   37  <--ROOT
Ds1   39      <---corresponding scale
F1   44
G1   49
Gs1   52
As1   58
C2   65
D2   73
Ds2   78
F2   87
G2   98
Gs2   104
As2   117
C3   131
D3   147
Ds3   156
F3   175
G3   196
Gs3   208
As3   233
C4   262
D4   294
Ds4   311
F4   349
G4   392
Gs4   415
As4   466
C5   523
D5   587
Ds5   622
F5   698
G5   784
Gs5   831
As5   932
C6   1047
D6   1175
Ds6   1245
F6   1397
G6   1568
Gs6   1661
As6   1865
C7   2093
D7   2349

G1   49  <--ROOT
C2   65  <--Corresponding Scale
E2   82
G2   98
As2   117
C3   131
E3   165
G3   196
As3   233
C4   262
E4   330
G4   392
As4   466
C5   523
E5   659
G5   784
As5   932
C6   1175
E6   1319
G6   1568
As6   1865

Thank you so much for any assistance you may be able to provide.
« Last Edit: May 19, 2012, 07:44:44 pm by Drc3p0 » Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
digitalRead(C1_KEY);   //check the state of C1 Key
digitalRead(Gs1_KEY);  //check the state of Gs1 Key
digitalRead(D1_KEY);   //check the state of D1 Key
digitalRead(G1_KEY);   //check the state of G1 Key

You are discarding the results of reading the keys. Look at some of the examples. It would be more like:

Code:
byte c1KeyPressed = digitalRead(C1_KEY);   //check the state of C1 Key



Code:
if (C1_KEY < 5) {    //if C1 Key is being pressed...(5 was just chosen, can be anything above 0 really)

This is just saying, in effect:

Code:
if (1 < 5) {    //if C1 Key is being pressed...(5 was just chosen, can be anything above 0 really)

... which will always be true.

So you really want something like:

Code:
if (c1KeyPressed == HIGH) { //if C1 Key is being pressed
« Last Edit: May 20, 2012, 02:08:42 am by Nick Gammon » Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So you really want something like:

Code:
if (c1KeyPressed == HIGH) { //if C1 Key is being pressed

oh yes, you're right!  It really is either going to be high or low.  then, i can control the if statement to state that
if (c1KeyPressed == HIGH)
then the root note would be played and the scale key would be assigned map C1.

Someone mentioned that I reassigned the audio out in 2 different places.  I just wasn't sure how to declare that all the audio would be played through pin 3

And i'm not sure if the map[] is being written properly, or if it is being transmitted to tones properly.

I'll try to rewrite the if statements like you mentioned.  This still has some tweaking that needs to be done.
Thanks for your advice.
Logged

Pages: [1]   Go Up
Print
 
Jump to: