Non-Linear/Exponential Sound

edited January 2016 in Arduino

Hi,

How do I create non-linear/exponential sound with sinewave code. Below is the code I am currently working with. The frequency is very choppy.

Thanks

    import processing.serial.*;
    import processing.sound.*;
    import cc.arduino.*;

    Arduino arduino;
    SinOsc sine;

    int total1;
    //int total2;
    //int total3;

    float freq=400;
    float amp=0.5;
    float pos;

    void setup() {
      // window size
      size(470, 280);
      background(0);
      // print out all the device connected to serial ports
      println(Arduino.list());

      arduino = new Arduino(this, Arduino.list()[1], 57600);

       // Create and start the sine oscillator.
       sine = new SinOsc(this);

       //Start the Sine Oscillator. 
       sine.play();

    }

    void draw() {
      fill(0,0,0,5);
      rect(0,0,width,height);


     // read capacitive sensor value sent via firmata 
      total1=arduino.analogRead(8) ;

     print("total1 : ");
     print(total1);
     println();

    if (total1 >=40 && total1 <=1200){
    // Map from 0.0 to 1.0 for amplitude
      amp=map(total1, 40, 1200, 0.0, 1.0);
      sine.amp(amp);
    } else if (total1 <=40) {
      amp = 0;
      sine.amp(amp);
    }
      println(total1);

      if (total1 >=40 && total1 <=1200){

    // Map from 20Hz to 1000Hz for frequency  
        freq=map(total1, 40, 1200, 500.0, 1000.0);
        sine.freq(freq);

      }

      // Map from -1.0 to 1.0 for left to right 
      pos=0.0;//map(mouseX, 0, width, -1.0, 1.0);
      sine.pan(pos);

    } // end draw
Tagged:

Answers

Sign In or Register to comment.