Recitation 7: Neopixel Music Visualization

 

For the start of recitation we needed to download all neseccary libraries and to connect the neopixel strip. It was easy enough for me. For the second task we used the codes which were wrote in class and tried them. Accidently, I forgot to close the Arduino IDE programm, so nothing worked. Now I learned this lesson. read instructions more careful.

For the third task, we needed to add music. It was fun to choose song in my native language. Some people including me had troubles with playing this music. I converted the file to aiff format and tryied some variations of where to put the file. Finally, Professor helped us to treplace the music file, so it all worked pretty good.

For the second step at first I added just some simple rectangles which were working by the same mechanism as the circle in the code from class. Later, I wanted to try different visualisation, so I added the change of colors according to the volume. I mapped volume with the color. 

For the next task, I added some more color modifications with the use of millis(). I analyzed the output information on the serial monitor and the numbers helped me to get to know which of them to use as starting points. 

For the last step, I just added some more variations. And tried to play with the code and music and lights. 

import processing.serial.*;
import osteele.processing.SerialRecord.*;

Serial serialPort;
SerialRecord serialRecord;

int W;         //width of the tiles
int NUM = 26;  //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

import processing.sound.*;





SoundFile sample;
Amplitude analysis;

void setup() {
  size(640, 480);
  // load and play a sound file in a loop
  sample = new SoundFile(this, "million.aiff.aiff");
  sample.loop();

  // create the Amplitude analysis object
  analysis = new Amplitude(this);
  // analyze the playing sound file
  analysis.input(sample);
  
  W = width/NUM;


  // You can use this syntax and change COM3 for your serial port
  // printArray(Serial.list());
  // serialPort = new Serial(this, "COM3", 9600);
  // in MacOS it looks like "/dev/cu.usbmodem1101"
  //or you can try to use this instead:
  
  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
  rectMode(CENTER);

}

void draw() {
  println(analysis.analyze());
  noStroke();
  fill(255, 0, 150);
  
  //long t = millis();
  //if(t < 2000){
  //  background(0);
  //}
  //else if (t < 4000){ // background(255, 0,0); //} //else { // background(0, 255, 0); //} // analyze the audio for its volume level float volume = analysis.analyze(); if (volume > 0.4 && volume < 0.7){ background(0, 0, 255); } else if (volume > 0.7){
    background(255, 0, 0);
  }
  else {
    background(255);
  }
  
  
  float x = map( volume, 0, 1, 0, 255);
  // 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 colorOfCircle = map(volume, 0, 1, 0, 255);
  fill(colorOfCircle);
  circle(width/2, height/2,diameter);
  
  
    for (int i=0; i<NUM; i ++) {
    fill(r[i], g[i], b[i]);
    rect(i * W + W/2, height/2, 10, 10);

}

if (mousePressed == true) { 
    int n = floor(constrain(mouseX/W , 0, NUM-1));

    r[n] = floor(x);
    g[n] = floor(x);
    b[n] = floor(x);

    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!
  }}















 

 

 

Leave a Reply

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