Recitation 7: Neopixel Music Visualization

In this video, the colors of LEDs vary according to the volume of music:

 

import processing.sound.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;
SoundFile sample;
Amplitude analysis;
Serial serialPort;
SerialRecord serialRecord;
int W;         //width of the tiles
int NUM = 60;  //amount of pixels
int[] r = new int[NUM]; //red of each tile
int[] g = new int[NUM]; //red of each tile
int[] b = new int[NUM]; //red of each tile
void setup() {
  size(640, 480);
 
  // load and play a sound file in a loop
  sample = new SoundFile(this, "fur-elise.mp3");
  sample.loop();

  // create the Amplitude analysis object
  analysis = new Amplitude(this);
  // analyze the playing sound file
  analysis.input(sample);
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, "COM4", 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
}

void draw() {
  println(analysis.analyze());
  background(#B4DFFF);
  noStroke();
  

  // analyze the audio for its volume level
  float volume = analysis.analyze();
  for(int n = 0; n<=20;n++){
  // volume is a number between 0.0 and 1.0
  // map the volume value to a useful scale
  float diameter = map(volume, 0, 1, 0, width);
  // draw a circle based on the microphone amplitude (volume)
  
  float redness = map(diameter,0,width,0,255);
 int red = floor(redness);
 fill(random(255),random(255),random(255));
 circle(width/2, height/2, diameter);
  r[n]= red;
  g[n]=(floor(map(n,0,60,0,200)));
  b[n]=abs(floor(50-red));
    serialRecord.values[0] = n;     // which pixel we change (0-59)
    serialRecord.values[1] = r[n];  // how much red (0-255)
    serialRecord.values[2] = g[n];  // how much green (0-255)
    serialRecord.values[3] = b[n];  // how much blue (0-255)
    serialRecord.send();            // send it!
  }
}

In this video, the colors and number of LEDs vary according to the volume of music:

 

 

import processing.sound.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;
SoundFile sample;
Amplitude analysis;
Serial serialPort;
SerialRecord serialRecord;
int W;         //width of the tiles
int NUM = 60;  //amount of pixels
int[] r = new int[NUM]; //red of each tile
int[] g = new int[NUM]; //red of each tile
int[] b = new int[NUM]; //red of each tile
int prevN;
void setup() {
  size(640, 480);
 
  // load and play a sound file in a loop
  sample = new SoundFile(this, "fur-elise.mp3");
  sample.loop();

  // create the Amplitude analysis object
  analysis = new Amplitude(this);
  // analyze the playing sound file
  analysis.input(sample);
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, "COM4", 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
}

void draw() {
  println(analysis.analyze());
  background(#B4DFFF);
  noStroke();
  

  // analyze the audio for its volume level
  float volume = analysis.analyze();
  int numbers = floor(map(volume,0,0.3,0,20));
  for(int n = 0; n<=numbers;n++){
  // volume is a number between 0.0 and 1.0
  // map the volume value to a useful scale
  float diameter = map(volume, 0, 1, 0, width);
  // draw a circle based on the microphone amplitude (volume)
  
  float redness = map(diameter,0,width,0,255);
 int red = floor(redness);
 fill(random(255),random(255),random(255));
 circle(width/2, height/2, diameter);

  r[n]= red;
  g[n]=(floor(map(n,0,60,0,200)));
  b[n]=abs(floor(50-red));
    serialRecord.values[0] = n;     // which pixel we change (0-59)
    serialRecord.values[1] = r[n];  // how much red (0-255)
    serialRecord.values[2] = g[n];  // how much green (0-255)
    serialRecord.values[3] = b[n];  // how much blue (0-255)
    serialRecord.send();            // send it!
    
    serialRecord.values[0] = prevN;     // which pixel we change (0-59)
    serialRecord.values[1] = 0;  // how much red (0-255)
    serialRecord.values[2] = 0;  // how much green (0-255)
    serialRecord.values[3] = 0;  // how much blue (0-255)
    serialRecord.send();     
    prevN=n;// send it!

  }
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *