VIDEO & SOUND
I want to make videos that captured by webcam to be filtered by music/sound.
here is my code:
function preload(){
    music = loadSound('SampleAudio.mp3');
}
function setup(){
  createCanvas(600,600);
  video = createCapture(VIDEO);
  video.size(600,600);
  video.hide();
  pixelDensity(1);
  fill(250);
  music.play();
  fft = new p5.FFT();
  audio = new p5.AudioIn();
  audio.start();
}
function draw(){
  //background(250);
  video.loadPixels();
  loadPixels();
  var audiomap = round(map(audio.getLevel(),0,0.1,10,50));
  var spectrum = fft.analyze();
for (var i = 0; i <video.width ; i+=audiomap){
    for (var q = 0; q<video.height; q+=audiomap){
      var index = (video.width - i +(q*video.width))*4;
      var r = video.pixels[index+0];
      var g = video.pixels[index+1];
      var b = video.pixels[index+2];
      // var r = 255-music.pan();
      // var g = 255-music.pan();
      fill(r,g,random(60,100),80);
      noStroke();
      rect(i-10,q,r,g);
      //rect(i+50,q,width / spectrum.length,width / spectrum.length);
  }
 }
}
Back to Top