How to remove flange effect from sound?

edited January 2014 in Library Questions

I'm trying to add and remove an effect, e.g. flange. The sketch below will play a sound and when I press 'f' will add the flange effect via 'patch'. This works just fine. When I press 'u' I'd like to remove the flange and hear the regular sound again. Using 'unpatch' on the FilePlayer to remove the AudioOutput and putting it back does not remove the flange.

Any idea what I need to do to get the unpatch to work would be appreciated.

import ddf.minim.*;
import ddf.minim.spi.*; // for AudioRecordingStream
import ddf.minim.ugens.*;

Minim minim;
FilePlayer filePlayer1;
AudioOutput out1;
Flanger flange;

String fileName1 = "http://code.compartmental.net/minim/examples/audio/groove.mp3";

void setup()
{
  size(640, 240);

  minim = new Minim(this);
  AudioRecordingStream myFile1 = minim.loadFileStream( fileName1, 1024, true);

  filePlayer1 = new FilePlayer( myFile1 );
  filePlayer1.loop();

  flange = new Flanger( 4,     // delay length in milliseconds ( clamped to [0,100] )
                        0.5f,   // lfo rate in Hz ( clamped at low end to 0.001 )
                        4,     // delay depth in milliseconds ( minimum of 0 )
                        0.9f,   // amount of feedback ( clamped to [0,1] )
                        0.9f,   // amount of dry signal ( clamped to [0,1] )
                        0.9f    // amount of wet signal ( clamped to [0,1] )
                       );

  out1 = minim.getLineOut();

  filePlayer1.patch(out1);

}

void keyPressed()
{
  if (key == 'f'){
    //adding the flange works!
    filePlayer1.patch(flange);
  } else if (key == 'u'){
    //get rid of the flange effect does NOT work
    filePlayer1.unpatch(out1);
    filePlayer1.patch(out1);
  }
}

void draw()
{
  background( 0 );
  stroke( 255 );
  for( int i = 0; i < out1.bufferSize() - 1; i++ )
  {
    float x1  =  map( i, 0, out1.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out1.bufferSize(), 0, width );
    line( x1, 50 + out1.left.get(i)*50, x2, 50 + out1.left.get(i+1)*50);
    line( x1, 150 + out1.right.get(i)*50, x2, 150 + out1.right.get(i+1)*50);
  }  
}

Answers

Sign In or Register to comment.