• Spectral Peaks of “Incontri di Fasce Sonore” – Processing •

Low quality Video (VIMEO link: https://vimeo.com/77850335)

Processing Code

AudioContext ac;
SamplePlayer player;
Sample buf;

FFT fft;
PowerSpectrum ps;
Frequency f;
SpectralCentroid sc;
SpectralPeaks sp;
int nPeaks;
Gain g;

String source;
SamplePlayer.LoopType tipo;

float fColor = 0;

void setup()
{
  size(500,500,P3D);
  background(0);  

  ellipseMode(CENTER);
  nPeaks = 128;
  /*schema
   sample - (input) -> gain g - (input) ->  ac.out --> USCITA
                                                  |
                                                  | --> ShortFrameSegmenter - FFT-Pot-Freq
   */
  ac = new AudioContext();
  g = new Gain(ac, 1, 1); 

  source=sketchPath("") + "audio/Franco_Evangelisti_incontri_fasce_sonore.wav";
  try
  {
    buf =  new Sample(source);
    player = new SamplePlayer(ac, new Sample(source));
    player.setKillOnEnd(false);
    //player.setToLoopStart();
    //player.setLoopType(tipo.LOOP_FORWARDS);
    //player.setRate(rateValue);
    player.start();
    g.addInput(player);
  }
  catch (Exception e)
  {
    println("ERROR !!!");
    e.printStackTrace();
    exit();
  }
  ac.out.addInput(g);

  //analis in frame
  //-TREE = UGen -> AudioSegmenter
  ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);
  sfs.addInput(ac.out);

  fft = new FFT();
  sfs.addListener(fft);
  ps = new PowerSpectrum();
  fft.addListener(ps);

  f = new Frequency((float)ac.getSampleRate());
  ps.addListener(f);

  sc = new SpectralCentroid((float)ac.getSampleRate());
  ps.addListener(sc);

  sp = new SpectralPeaks(ac,nPeaks);
  ps.addListener(sp);
  ac.out.addDependent(sfs);
  ac.start();

void draw()
{
  background(map(fColor,30,255,10,40));
  drawSpectralPeaks();
}

void drawSpectralPeaks()
{
  if( sp.getFeatures() != null )
  {
    int s = 0;
    float[][] spectral  = sp.getFeatures(); //[Freq, Pot]

    for (int i = 0; i < nPeaks; i++)
    {
      int f = Math.min((int)(spectral[i][0] * width), width - 1); // freq
      s = Math.min((int)(spectral[i][1] * (height-40)), height - 40- 1); // gain
      fColor = map(spectral[i][0],0,22050,30,255);
      float f1 = random(f);
      float f2 = random(f);  

      random((height/2),(height/2)+15), random((width/4),(width/2)+35), f1,f2);
      noStroke();
      smooth();
      fill(fColor,random(fColor),fColor);
      ellipse(f1,f2,s,s);
      fill(255);
      stroke(5);
      ellipse(f1,f2,s/70,s/70);
      fill(fColor,random(fColor),random(fColor));
      noStroke();
      ellipse(width/2,height/2,s,s);
    }
  }
}

Spectral Peaks of