RECITATION 7
task 1:
task 2:
task 3:
I changed part of the codes to let the LED lights interact with the music. The louder the music is, the more lights would be on. Also, the circle still beats with the music though it runs a little stuck.
/* This is a code example for Processing, to be used on Recitation 7 You need to have installed the SerialRecord library. Interaction Lab IMA NYU Shanghai 2022 Fall */ import processing.serial.*; import osteele.processing.SerialRecord.*; import processing.sound.*; SoundFile sample; Amplitude analysis; Serial serialPort; SerialRecord serialRecord; //width of the tiles int NUM = 60; //amount of pixels void setup() { size(600, 200); sample = new SoundFile(this, "マクロスMACROSS 82-99 - 『82.99 AM』.aiff"); sample.loop(); // create the Amplitude analysis object analysis = new Amplitude(this); // analyze the playing sound file analysis.input(sample); // 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()); background(#6FA0D3); noStroke(); fill(#3B49BC); // 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, 80); circle(300, 100, diameter); // draw a circle based on the microphone amplitude (volume) for (int m=0; m<60; m ++) { int i = (int)map(volume, 0, 1, 0, 60); if (m<i){ serialRecord.values[0] = m; // which pixel we change (0-59) serialRecord.values[1] = 0; // how much red (0-255) serialRecord.values[2] = 50; // how much green (0-255) serialRecord.values[3] = 100; // how much blue (0-255) serialRecord.send(); // send it! } else{ serialRecord.values[0] = m; // 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(); // send it! } } }
Leave a Reply