Laser Harp

Status
Not open for further replies.

Jojamoco

Member
Hey Guys,

I have made a basic laser harp (9 string, red lasers firing into LDR's) using the teensy and the audio library. I have it wokring and its seems quite nice only the strings from the audio library don't sound very harp like. I was wondering is perhaps I could get some help understanding if/how/where I can modify the "string" objects to play with the karplus strong stuff to maybe tune the sound.

Thoughts?

Jon

Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>

//#include "chords.h"

// Video of TouchGuitar in action :)
// https://youtu.be/TidIpeY_6T8?t=12s
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthKarplusStrong  string2;        //xy=55,566.3945713043213
AudioSynthKarplusStrong  string3;        //xy=55,607.3515167236328
AudioSynthKarplusStrong  string4;        //xy=55,651.100923538208
AudioSynthKarplusStrong  string5;        //xy=55,704.1586656570435
AudioSynthKarplusStrong  string6;        //xy=55,754.4239673614502
AudioSynthKarplusStrong  string8;        //xy=55,852.9138088226318
AudioSynthKarplusStrong  string7;        //xy=55.85032653808594,808.8988351821899
AudioSynthKarplusStrong  string1;        //xy=57.792518615722656,513.3368072509766
AudioSynthKarplusStrong  string9;        //xy=59.77735137939453,904.378137588501
AudioMixer4              mixer1;         //xy=329.597412109375,608.2823524475098
AudioMixer4              mixer2;         //xy=464.36792755126953,673.2475929260254
AudioMixer4              mixer3;         //xy=599.1919746398926,736.569242477417
AudioOutputAnalog        dac1;           //xy=769.7055206298828,793.525731086731
AudioConnection          patchCord1(string2, 0, mixer1, 1);
AudioConnection          patchCord2(string3, 0, mixer1, 2);
AudioConnection          patchCord3(string4, 0, mixer1, 3);
AudioConnection          patchCord4(string5, 0, mixer2, 1);
AudioConnection          patchCord5(string6, 0, mixer2, 2);
AudioConnection          patchCord6(string8, 0, mixer3, 1);
AudioConnection          patchCord7(string7, 0, mixer2, 3);
AudioConnection          patchCord8(string1, 0, mixer1, 0);
AudioConnection          patchCord9(string9, 0, mixer3, 2);
AudioConnection          patchCord10(mixer1, 0, mixer2, 0);
AudioConnection          patchCord11(mixer2, 0, mixer3, 0);
AudioConnection          patchCord12(mixer3, dac1);
// GUItool: end automatically generated code
const int ledPin = 13; //for testing

void setup() {
  AudioMemory(15);  
  pinMode(ledPin, OUTPUT);
  //Serial.begin(38400);
  dac1.analogReference(INTERNAL);   // normal volume
  //dac1.analogReference(EXTERNAL); // louder
  mixer1.gain(0, 0.27);
  mixer1.gain(1, 0.27);
  mixer1.gain(2, 0.27);
  mixer1.gain(3, 0.27);
  //mixer2.gain(0, 0.27);input from mix 1 no gain
  mixer2.gain(1, 0.27);
  mixer2.gain(2, 0.27);
  mixer2.gain(3, 0.27);
  //mixer3.gain(0, 0.27);input from mix 2 no gain
  mixer3.gain(1, 0.27);
  mixer3.gain(2, 0.27);
  mixer3.gain(3, 0.27);
  delay(100);
}

int val[9]; //analog readings from LDRs
int ambient[9]; //ambient light levels
bool stringOn[9]; //is the laser "string" currently blocked
bool runOnce = false; //flag for reading ambient light

void loop()
{
  if(!runOnce){
    //Serial.println("RunOnce");
    readStrings();
    for(int i=0;i<9;i++){
      ambient[i] = val[i] + 75;
      //Serial.println(ambient[i]);
    }
    runOnce = true;
  }
  
  readStrings();
  
  playNotes();  
  
}

void readStrings()
{
  val[0] = analogRead(0);
  val[1] = analogRead(1);
  val[2] = analogRead(2);
  val[3] = analogRead(3);
  val[4] = analogRead(4);
  val[5] = analogRead(5);
  val[6] = analogRead(6);
  val[7] = analogRead(7);
  val[8] = analogRead(8);

  /*//for debugging
  Serial.print("Analog 0 is: ");
  Serial.println(val[0]);  
  Serial.print("Analog 1 is: ");
  Serial.println(val[1]);  
  Serial.print("Analog 2 is: ");
  Serial.println(val[2]);  
  Serial.print("Analog 3 is: ");
  Serial.println(val[3]);
  Serial.print("Analog 4 is: ");
  Serial.println(val[4]);
  Serial.print("Analog 5 is: ");
  Serial.println(val[5]);
  Serial.print("Analog 6 is: ");
  Serial.println(val[6]);
  Serial.print("Analog 7 is: ");
  Serial.println(val[7]); 
  Serial.print("Analog 8 is: ");
  Serial.println(val[8]);//*/
}

void playNotes(){
  
  if(val[0] > ambient[0]){
    if(stringOn[0]==false){
      string1.noteOn(220.00, 1.0); //A
      stringOn[0] = true;
    }    
  }else {
    //string1.noteOff(0);
    stringOn[0] = false;
  }
   
  if(val[1] > ambient[1]){
    if(stringOn[1]==false){
      string2.noteOn(233.082, 1.0);//Bb
      stringOn[1] = true;
    }
  }else {
    //string2.noteOff(0);
    stringOn[1] = false;
  }

  if(val[2] > ambient[2]){
    if(stringOn[2]==false){
      string3.noteOn(261.626, 1.0);//C
      stringOn[2] = true;
    }
  }else {
    //string3.noteOff(0);
    stringOn[2] = false;
  }
  
  if(val[3] > ambient[3]){
    if(stringOn[3]==false){
      string4.noteOn(293.665, 1.0);//D
      stringOn[3] = true;
    }
  }else {
    //string4.noteOff(0);
    stringOn[3] = false;
  }

  if(val[4] > ambient[4]){
    if(stringOn[4]==false){
      string5.noteOn(329.628, 1.0);//E
      stringOn[4] = true;
    }    
  }else {
    stringOn[4] = false;
    //string5.noteOff(0);
  }

  if(val[5] > ambient[5]){
    if(stringOn[5]==false){
      string6.noteOn(349.228, 1.0);//F
      stringOn[5] = true;
    }    
  }else {
    //string6.noteOff(0);
    stringOn[5] = false;
  }  
  
  if(val[6] > ambient[6]){
    if(stringOn[6]==false){
      stringOn[6] = true;
      string7.noteOn(391.995, 1.0);//G
    }    
  }else {
    //string7.noteOff(0);
    stringOn[6] = false;
  }

  if(val[7] > ambient[7]){
    if(stringOn[7]==false){
      string8.noteOn(440.00, 1.0);//A
      stringOn[7] = true;
  }
    
  }else {
    //string8.noteOff(0);
    stringOn[7] = false;
  }

  if(val[8] > ambient[8]){
    if(stringOn[8]==false){
      string9.noteOn(466.164, 1.0);//Bb
      stringOn[8] = true;
  }
    
  }else {
    //string9.noteOff(0);
    stringOn[8] = false;
  }

    
}
 
Status
Not open for further replies.
Back
Top