User Tools

Site Tools


prensf2010:normalize

This is an old revision of the document!


// Nels Oscar
// Simple normalization using Minims AudioEffecs interface
 
import ddf.minim.*;
import ddf.minim.signals.*;
 
Minim minim;
 
AudioSample sample;
 
AudioSignal modified;
 
AudioOutput out;
 
void setup(){
  size(200,100);
  background(0);
  minim=new Minim(this);
  out=minim.getLineOut();
  sample=minim.loadSample("c4.wav",1024);
  sample.addEffect(new Nermalize());
}
 
void draw(){
  background(0);
  text(sample.isEffected() ? "Normalized":"Normal",10,height-10);
}
 
void keyPressed(){
  if(sample.isEffected())
    sample.disableEffect(0);
  else
    sample.enableEffect(0);
  sample.trigger();
}
 
 
 
void stop(){
  minim.stop();
  super.stop();
}
 
class Nermalize implements AudioEffect{
   public Nermalize(){}
 
   void process(float[] sig){
     float hiSample=0.;
     for (int j = 0; j < sig.length/2; j++) {
       if(hiSample<abs(sig[j]))
         hiSample=abs(sig[j]);
     }
     float diff=1.+hiSample;
     for(int i=0; i<sig.length; i++){
       sig[i]*=diff;
     }
   }
   void process(float[] sigL, float[] sigR){
     process(sigL);
     process(sigR);
   }
 
}
prensf2010/normalize.1278343048.txt.gz · Last modified: 2010/07/05 10:17 by nels_oscar