Recitation 7: Neopixel Music Visualization

TASK 1 (Yes I changed red into green)

TASK 2:

(⬆️I really think this strip looks like Thanos’s glove.)

TASK 4:

 

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, "夏日入侵企画 - 🎇.mp3");
  sample.loop();

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

void draw() {
  println(analysis.analyze());
  background(#C6E3F0);
  noStroke();
  fill(#E0873D);

  // analyze the audio for its volume level
  float volume = analysis.analyze();

  // 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)
  circle(width/2, height/2, diameter);
}

Sadly I didn’t achieve the step 2… I wanted to let the stripe change color along with the music, and meanwhile we can see the circle bumping. However, I worked so hard but failed to find the bug(there should only be one bug but stop it from running)⬇️ Hopefully I can see the sample code and try it later😭

import processing.sound.*;
import osteele.processing.SerialRecord.*;

serialPort;
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


SoundFile sample;
Amplitude analysis;

void setup() {
  size(640, 480);
  W = width/NUM;

 

  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  serialRecord = new SerialRecord(this, serialPort, 4);
  serialRecord.logToCanvas(false);
  //rectMode(CENTER);
   // load and play a sound file in a loop
  sample = new SoundFile(this, "夏日入侵企画 - 🎇.mp3");
  sample.loop();

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


void draw() {
  println(analysis.analyze());
  background(#C6E3F0);
  noStroke();
  fill(#E0873D);

  // analyze the audio for its volume level
  float volume = analysis.analyze();

  // volume is a number between 0.0 and 1.0
  // map the volume value to a useful scale
  // draw a circle based on the microphone amplitude (volume)
 float diameter=map(volume, 0, 1, 0, width);
 circle(width/2,height/2,diameter);
  
  /*r[n] = floor(volume);
   g[n] = floor(volume);
   b[n] = floor(volume);*/
  //for (int n=0; n<60; n++) {
int n = floor(map(volume, 0, 1, 0, 60));
    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 *