Changing the instrument with Minim

Hello guys,

How could I change the type of instrument using the Minim library?

For example, like to switch Piano Violin, etc ...

I managed to do this with the soundcipher library, but some things have to do with Minim, I would have a fft and sinusoidal signal ... below is the sample code.

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

Minim minim;
AudioOutput out;
ToneInstrument myNote;

int note = 150;

void setup(){
  size(512, 200, P2D);

  minim = new Minim(this);
  out = minim.getLineOut(Minim.STEREO, 1024);

  //myNote = new ToneInstrument( 200.f, 0.3, 0.5f, 1.0f );
  //out.playNote(0.f, 8.f, myNote );
}

void draw(){
  background( 0 );
  stroke( 255 );
  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, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    //line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }  
}

void mousePressed(){
  //out.instrument(0); //??
  out.playNote(0.f, 1, note );  
}

void keyPressed(){
  if (key == 'M' || key == 'm') note++;
  else if (key == 'N' || key == 'n') note--;
}

class ToneInstrument implements Instrument{
  Oscil sineOsc, lFOOsc;
  Balance balance;

  ToneInstrument(float frequency, float amplitude, float lfoFrequency, float lfoAmplitude){
    sineOsc = new Oscil(frequency, amplitude, Waves.SINE);
    lFOOsc = new Oscil(lfoFrequency, lfoAmplitude, Waves.SINE);
    balance = new Balance( 0.5 );
    lFOOsc.patch( balance.balance );

    sineOsc.patch( balance );
  }
  void noteOn(float dur){
    balance.patch(out);
  }

  // every instrument must have a noteOff() method
  void noteOff(){
    balance.unpatch(out);
  }
}

Thanks for listening

Answers

  • Hello,

    Anyone can help?

    Would it really not possible, the curious thing is that with the library soundcipher it usually works ... but I could not with this other library analyze the signal, make a fft, etc ...

    Thank you,

Sign In or Register to comment.