• fullscreen
  • NoiseInstrument.pde
  • background.pde
  • ghosty_wind.pde
  • // Every instrument must implement the Instrument interface so 
    // playNote() can call the instrument's methods.
    
    // This noise instrument uses white noise and two bandpass filters
    // to make a "whistling wind" sound.  By changing using the methods which
    // change the frequency and the bandwidth of the filters, the sound changes.
    
    class NoiseInstrument implements Instrument
    {
      // create all variables that must be used throughout the class
      Noise myNoise;
      Multiplier multiply;
      AudioOutput out;
      BandPass filt1, filt2;
      Summer sum; 
      float freq1, freq2, freq3;
      float bandWidth1, bandWidth2;
      float filterFactor;
      
      // constructors for this intsrument
      NoiseInstrument( float amplitude, AudioOutput output )
      {
        // equate class variables to constructor variables as necessary 
        out = output;
        
        // give some initial values to the realtime control variables
        freq1 = 150.0;
        bandWidth1 = 10.0;
        filterFactor = 1.7;
        
        // create new instances of any UGen objects
        myNoise = new Noise( amplitude, Noise.Tint.WHITE );
        multiply = new Multiplier( 0 );
        filt1 = new BandPass( freq1, bandWidth1, out.sampleRate() );
        filt2 = new BandPass( freq2(), bandWidth2(), out.sampleRate() );
        sum = new Summer();
    
        // patch everything (including the out this time)
        myNoise.patch( filt1 ).patch( sum );
        myNoise.patch( filt2 ).patch( sum );
        sum.patch( multiply );
      }
      
      // every instrument must have a noteOn( float ) method
      void noteOn( float dur )
      {
        // set the multiply to 1 to turn on the note
        multiply.setValue( 1 );
        multiply.patch( out );
      }
      
      // every instrument must have a noteOff() method
      void noteOff()
      {
        // set the multiply to 0 to turn off the note 
        multiply.setValue( 0 );
        multiply.unpatch( out );
      }
      
      // this is a helper method only used internally to find the second filter
      float freq2()
      {
        // calculate the second frequency based on the first
        return filterFactor*freq1;
      }
      
      // this is a helper method only used internally 
      // to find the bandwidth of the second filter
      float bandWidth2()
      {
        // calculate the second bandwidth based on the first
        return filterFactor*bandWidth1;
      }
      
      // this is a method to set the center frequencies
      // of the two filters based on the CF of the first
      void setFilterCF( float cf )
      {
        freq1 = cf;
        filt1.setFreq( freq1 );
        filt2.setFreq( freq2() );
      }
      
      // this is a method to set the bandwidths
      // of the two filters based on the BW of the first
      void setFilterBW( float bw )
      {
        bandWidth1 = bw;
        filt1.setBandWidth( bandWidth1 );
        filt2.setBandWidth( bandWidth2() );
      }
     
      // this is a method to set the Q (inverse of bandwidth)
      // of the two filters based on the  
      void setFilterQ( float q )
      {
        setFilterBW( freq1/q );
      }
    }
    
    
    
    
    import ddf.minim.*;
    import ddf.minim.ugens.*;
    import ddf.minim.effects.*;
    
    Minim minim;
    AudioOutput out;
    NoiseInstrument myNoise;
    
    int i, x, y,x1,x2;
    
    float freq = 60;
    float h; 
    
    float xpos =350;
    float ypos =200;
    
    float angle = 0.0;
    float offset = 60;
    float scalar = 40;
    float speed = 0.05;
    
    float opacity = 50; 
    
    float xoff = 0.0;
    float xincrement = 0.005;
    float n=0;
    float talla=0;
    
    void setup() {
      
      size(700, 400,P2D); 
      background (0);
      smooth();
      noFill();
      noCursor();
     
      minim = new Minim(this);
      out = minim.getLineOut(Minim.STEREO); 
      
      myNoise = new NoiseInstrument( 1.0, out );
      out.playNote( 0, 100.0, myNoise );
    
      h = height ;
      x = 0;
      y = 10;
    }
    
    void draw() {
      background(0); 
     
        talla=random(height,width);
    
     
      float red = 255 - (20 * i); 
    
      if(red > 255) red = 255; 
      
      stroke(255, red, 0, opacity);
      
      i = 0; 
      
       beginShape(LINES);
      
    
      for (int i= int(random(-(width*1.5),width*2.5)) ; i<talla; i++) { 
     strokeWeight(random(5, 15));
      
        n = noise(xoff)*(width/2);
        xoff += xincrement/2;
     
        vertex(i, n);
      }
     
      endShape();
      
      while(i < y) {
        xpos = xpos + (mouseX - xpos) /30.0;
        ypos = ypos +(mouseY -ypos)/30.0;
    
        beginShape();
     
        for( int i = 0; i < out.bufferSize() - 1; i++ )
      {
        
        float x1  =  map( i, 0, out.bufferSize(), 0, width );
        float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
       
      }  
        
        float y1=offset +sin(angle) * scalar;
        float y2=offset +sin(angle +0.4) *scalar;
        float y3=offset +sin(angle + 0.8) *scalar;
        float y4 =offset +sin (angle+1.2)*scalar;
        float y5=offset +sin(angle+1.6) * scalar;
        float y6=offset +sin(angle +2) *scalar;
        float y7=offset +sin(angle + 2.4) *scalar;
        float y8 =offset +sin (angle+2.8)*scalar;
    
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+10, mouseY+10, mouseX+ 0, mouseY+90, xpos + 25 + out.left.get(i+1)*100, ypos+80+y1);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+10, mouseY+30, mouseX+ 0, mouseY+90, xpos - 25 + out.left.get(i+1)*50, ypos+80+y2);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+20, mouseY+20, mouseX+ 0, mouseY+80, xpos + 15 + out.left.get(i+1)*50, ypos+60+y3);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+20, mouseY+40, mouseX+ 0, mouseY+80, xpos - 15 + out.left.get(i+1)*50, ypos+60+y4);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+30, mouseY+30, mouseX+ 0, mouseY+70, xpos + 35 + out.left.get(i+1)*50, ypos+80+y5);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+30, mouseY+50, mouseX+ 0, mouseY+70, xpos - 35 + out.left.get(i+1)*50, ypos+80+y6);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+40, mouseY+40, mouseX+ 0, mouseY+60, xpos + 45 + out.left.get(i+1)*50, ypos+60+y7);
        bezier(mouseX, mouseY + out.left.get(i)*100, mouseX+40, mouseY+60, mouseX+ 0, mouseY+60, xpos - 45 + out.left.get(i+1)*50, ypos+60+y8);
     
        angle +=speed;
        endShape();
        i++;
      }
    }
    
    void keyPressed() {
      if(keyCode == UP) {
        y++;
        freq++; 
        
    
      }
      else if(keyCode == DOWN) {
        y--; 
        if(y < 1) y = 1;
        freq--; 
        if(freq < 50) freq = 50;
        
      }
      else if(keyCode == LEFT) {
        opacity -= 3;
        if(opacity < 5) opacity = 5; 
      }
      else if(keyCode == RIGHT) {
        opacity +=3;
        if(opacity > 100) opacity = 100;
      }
    }
    
    
    void mouseMoved()
    {
     
      float freq = map( mouseY, 0, height, 1500, 150 );
      float q = map( mouseX, 0, width, 0.9, 100 );
     
      myNoise.setFilterCF( freq );
      myNoise.setFilterQ( q );
    }
    
    
    void stop()
    {
      
      out.close();
      
      minim.stop();
     
      super.stop();
    }
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Pablo Rodriguez

    "ghosty wind” SOUND SHAPE PJ3

    Add to Faves Me Likey@! 2
    You must login/register to add this sketch to your favorites.

    use arrows keys

    Jean Gilbert
    2 Mar 2013
    Hi Pablo,
    thank you for the source, I use it for AV performances and added the body motion control with a kinect camera.
    Welcome on http://www.jean-gilbert.com, credits are also there.
    Regards,
    Jean Gilbert
    You need to login/register to comment.