Day 3

Posted: September 3rd, 2010 | Author: | Filed under: Creative Pact 2010 | No Comments »

Today was a challenge. I downloaded the BETA of MINM so that I could try the new UGEN api. It is interesting but not fully featured yet. I saw a Granulator in there and I got excited. I wasn’t able to make any good sounds and I ran into some troubles with controlP5 and MINIM where they both had Controller classes and Events.

There is a crazy solution where the name of a controlP5 object can be declared as a global and the slider will update the global. I have to look further into why this works but it certainly minimizes the amount of code I have to write to make a basic GUI.

This example does a simple mapping of the BitCrush UGEN with a slider. It also has a display for the audio output. I would love to have access to the audio input too. More work to be done. I am learning a lot here.




import ddf.minim.*;
import ddf.minim.ugens.*;
import controlP5.*;

ControlP5 controlP5;
Slider bdslider;
public float bitdepth;

Minim minim;
LiveInput in;
AudioOutput out;
Constant controls = new Constant();
BitCrush fx1 = new BitCrush();

void setup(){
  size(500, 400);
  minim = new Minim(this);
  out = minim.getLineOut();
  in = new LiveInput( minim.getInputStream(out.getFormat().getChannels(), out.bufferSize(), out.sampleRate(), out.getFormat().getSampleSizeInBits()) ); 

  controlP5 = new ControlP5(this);
  bdslider = controlP5.addSlider("bitdepth",1,16,  15,height/3-80 , width-100,30);

  bdslider.setValue(8);

  controls.patch(fx1.bitRes);
  controls.setConstant (bitdepth); 

 in.patch(fx1).patch(out);
}

void draw(){
  background(50);
  stroke( 255 );

  controls.setConstant (bitdepth); 

  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 );
    line( x1, height*.75 + out.left.get(i)*50, x2, height*.75 + out.left.get(i+1)*50);
    line( x1, height*.75 + 50 + out.right.get(i)*50, x2, height*.75 + 50 + out.right.get(i+1)*50);
  }
  controlP5.draw();
}

void keyPressed(){
  if (key == ' ')
    saveFrame();
}

void stop()
{
  in.close();
  out.close();
  minim.stop();
  super.stop();
}


Leave a Reply