| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

FINAL PROJECT- Light Up Your Music

Page history last edited by mauraaz@... 7 years, 3 months ago

 

FINAL PROJECT- LIGHT UP YOUR MUSIC!!!

 


 

 

VIDEO: Light Up Your Music- in use!

Check out: http://www.youtube.com/watch?v=JGkg_DhNVYk&feature=youtu.be

 

POINT OF VIEW:

I wanted to create something for this project that I would actually use. I wanted it to be something that I could share with my friends and was fun. I realized that when we get to get together to celebrate, we usually just pull up some music in someone's laptop. But, we needed a better way to take our music to the next level at our parties. I wanted us to feel it. To visualize it.

And so the idea for Light Up Your Music was born...

 

 

DESIGN DIRECTIVES:

  1. One had to feel the music more with this, to take the music to the next level. 
  2. Had to be able to play any song (from YouTube, iTunes, etc)
  3. Could be easily set up in anyone's computer

 

 

VERPLANK DIAGRAM:

 

 

STATE DIAGRAM:


 

 

HOW IT WORKS:

Most of the processing actually takes place in the computer. This was a fine way to operate because my visualizer was meant to be used with a laptop. Broadly speaking, the music feeds in via serial. I use Processing to apply a Fourier transform (FFT) to analyze the frequency of the music coming in. Then, different parts of the spectrum are assigned different colors. Bass is green; blue are the midtones; and red is treble. I also use BeatDetect of the Minim library (included with Processing for analysis of audio) to detect each beat. The Arduino receives this information and the LEDs are turned on accordingly.

 

 

HOW THE DESIGN DIRECTIVES WERE MET: (directly in response to Design Directives section)

  1. It's amazing, but being in a room with lights flashing to the beat of your music really does make you feel the music more. It quickly turns a casual setup into a clear party!
  2. Originally, I had written my code such that you had to upload each song you wanted to play and the code actually had to specify the name of it. Thought it was really cool that I finally got that to work, it was impractical. I did not want to be limited to a restrained list of songs pre-saved on an SD card. So, I learned how to do that for Lab 6 and then designed this visualizer for the context in which I imagined it: at a casual party where a computer would already be used to play music and be physically set up at a place where my visualizer could join. By setting up my computer as both the input and output of the sound (as explained later), this is no longer constrained and can play any song! YouTube, iTunes... everything works. Moreover, it doesn't pick up sound and flash according to it. (You can imagine that you don't want drunk people randomly screaming at a party affecting the quality of your visual experience.)
  3. When I finished writing my code, I exported it as an application so that anyone can use it even if they don't have Processing installed. I then saved this application on a flashdrive along with Soundflower (which you'll also hear about below). So, now everything is consolidated and ready to be used there, as part of the Light Up Your Music kit.

 

 

SOME PROBLEMS I FACED:

  • I kept getting an "RXTX Version Mismatch error" and could not figure out for the longest time what was wrong. Turns out there is a problem with Processing in the new version--but Processing 1.5 works well! So, I downloaded the older version and suprisingly the problem was resolved. 
  • For a long time, I could tell it was working because the LEDs flashed consistently with the music I played. But, I could not actually hear any sound. This helped me understand how to configure sound  input & output:  http://apple.stackexchange.com/questions/50904/if-we-use-soundflower-to-record-the-systems-audio-output-then-we-cant-hear-it

          (Not to worry, I've included this in the explanation of how to make this project.) 

  • Make sure all pieces of your box are going to imbed well! It's very easy to cut a tab the opposite way so that it doesn't imbed. Making sure the pieces are flush with each other is also tricky. See advice on making the acrylic case under "Do It Yourself! Here's How."
  • When I tried to hide all the electronics, the wires came easily undone--especially because they end up twisted and in weird configurations. In particular, the wires coming off the LED strip kept getting disconnected--which, you may understand, is a major problem for this project. I actually ended up spending a few hours just trying to fix this. Part of the problem was that these wires are round but all connectors in the lab are square--and that was enough wiggle room for this not to work reliably. Long story short, cutting the end that comes with the LED strip, soldering longer wires, and adding heat shrink around these is a good way to fix it. They always stay on now! *Another tip here is that I actually never glued the top of the box (top piece + sides all glued) to the bottom because this allows me to easily check the cables are ok inside. But, I cut it so that the acrylic imbeds well, so it's not a problem not to have glue in that connection.
  • Other naive issues I struggled with (like having transistors that weren't powerful enough!...my first electronics class) are already incorporated into the explanation of how to do this, and should not be a problem for you! 

 

 

DO IT YOURSELF! HERE'S HOW:

(I've tried to leave this pretty detailed and with specifics for anyone at Stanford. :) I know many of you approached me with the idea of doing this over the summer, so I hope you enjoy! Feel free to shoot me any email if you have any questions! mauraaz@stanford.edu)

  1. Procure materials.
    1. LED strip-  $12!!! for 5m (This price is one of the coolest parts of the project!!!)
      1. http://www.amazon.com/gp/product/B006LW2NJM/ref=oh_details_o01_s00_i00?ie=UTF8&psc=1 (This is the one I bought & it works great! Other options also available on Amazon.)
      2. http://www.adafruit.com/products/285
    2. Acrylic plastic for casing
      1. Recommend clear frosted acryllic from Tap Plastic @ 312 Castro Street, Mountain View
    3. Arduino
      1. $30 at Radio Shack: 490 S Cal Ave (I actually ended up using both a Micro & a Nano for this project. Either work well!)
    4. Electronic components
      1. 3 TIP120 NPN transistors- http://www.radioshack.com/product/index.jsp?productId=2062617
      2. 3 220 ohm resistors
      3. 1 small breadboard
      4. Sufficient wires
      5. 8 AA batteries
      6. battery case - also available at Radio Shack
    5. Cardboard cylinder- I used this to wrap the LEDs around and reflect evenly. Easily procured in Room 36! Of course, you can use other things also.
    6. Software
      1. Arduino- http://arduino.cc/en/Main/Software
      2. Processing- https://processing.org/download/ ***NOTE: You want version 1.5--not the latest!!!
      3. SoundFlower- http://code.google.com/p/soundflower/ *This software will help you make the line in of your computer the output of the sound card.
  2. Construct & assemble.
    1. Make your acrylic case using a laser cutter at the PRL or R36
      1. Advice: Before using your nice, expensive frosted acrylic, do some test runs. First, use foam board (similar thickness!), then try it with the acrylic pieces they sell to you in R36. That is much cheaper plastic and will give you a perfect idea of how you're doing. You'll want to take into account the curf of the machine you're using and adjust your files accordingly so that the box imbeds very well. (For this, first cut a 1 inch circle, measure the material actually cut out, and take into account the difference.) To seal together, use acrylic cement. (But, beware that this glue will only work effectively if the two surfaces actually touch well, so you have to be careful and perhaps design the pieces that fit in just a few thousands of an inch larger than those they fit into--if you want it to look really nice.)
    2. Wrap white paper around inner tube, and the top as well. - This will leave you with only the lights inside the box and the whiteness. Otherwise, any other color stands out and distracts from the effect you are seeking lighting up your music. (For the same reason, try to hide all your cables inside the inner tube!)
    3. Put together your circuit as described in the following image: 
      1.  
  3. Write the code. ** See my code below- feel free to use!
    1. NOTE that I borrowed heavily and are thankful for the ideas of John Whittington: http://engineer.john-whittington.co.uk/2012/06/musical-rainbows-in-the-van/ 
    2. Open Arduino and run the Standard Firmata. Find this under: File > Examples > Firmata > Standard Firmata.
    3. You will need both the BeatListener and MusicalColorsFri sketches (= a Processing file or document) in the same folder, saved inside your Processing folder. 
    4. To be able to use this on any of your friends' computers, make an application! On Processing, go to File > Export as Application. You can select for it to work on Mac, Linux, and Windows also.
  4. Configure the sound on your computer. 
    1. Search for Audio MIDI Setup on your computer. Select as follows:

      

          ii. Right click on "Multi-Output Device" and select "Use this device for sound output" every time you want to use this. ****    

 5. Test! You should be ready to go! LIGHT UP THAT MUSIKKKK!!!!

 

Data Sheets- for your reference:

 

Other pictures of the project:

(Notice the compact design with hidden electronics, plus long-lasting & easily exchangeable batteries on the back.)

 

Code:

1ST FILE: MusicalColorsFri

 

/**

This script takes the line in of the computer sound card and extracts Forward Fourier Transform (FFT). The spectrum is then

broken into Bass, Mid and Treble and amplitude of each used to flash an LED. The Bass section is only flashed on detection of a beat,

using BeatDetect.

 

John Whittington @j_whittington - June 2012

 

Modified by Maura Aranguren - May/June 2013

**/

 

//Import

import processing.serial.*;

import ddf.minim.*;

import ddf.minim.analysis.*;

import cc.arduino.*;

 

Minim minim;

AudioInput song; // need?

BeatDetect beat;

BeatListener bl;

Arduino arduino;

FFT fft;

 

//Variables

int GreenPin =  6;    // Green Pin

int RedPin =  5;    // Red Pin

int BluePin =  3;    // Blue Pin

//Colour voltage definitions

int G = 255;

int R = 255;

int B = 255;

 

//Freq range variables

int BassAmp = 0;

int MidAmp = 0;

int TreAmp = 0;

int MaxBass = 0;

int MaxMid = 0;

int MaxTre = 0;

 

//Text size variable for beat display

float txtSize;

 

void setup() {

  size(512, 200, P3D);

 

  minim = new Minim(this);

  minim.debugOn(); // need?

  //Setup the arduino

  arduino = new Arduino(this, Arduino.list()[1], 57600);

 

  //Take the linein, this can be a song using minim.loadFile (see FreqEnergy example)

  song = minim.getLineIn(Minim.STEREO, 512);

  // set to SOUND_ENERGY mode (not args)

  beat = new BeatDetect();

  beat.setSensitivity(300);  

  txtSize = 16;

  // make a new beat listener, so that we won't miss any buffers for the analysis

  bl = new BeatListener(beat, song);  

  textFont(createFont("Helvetica", 16));

  textAlign(CENTER);

 

  fft = new FFT(song.bufferSize(),song.sampleRate());

 

  //Setup arduino outputs

  arduino.pinMode(GreenPin, Arduino.OUTPUT);    

  arduino.pinMode(RedPin, Arduino.OUTPUT);  

  arduino.pinMode(BluePin, Arduino.OUTPUT); 

 

}

 

void draw() {

  background(0);

  fill(255,0,0);

  stroke(255);

 

  fft.forward(song.mix);

 

  //Get the amplitudes of sound ranges

  for(int i = 0; i <= 20; i++) {

    BassAmp = BassAmp + floor(fft.getBand(i));   

  }

 

  for(int i = 20; i <= 60; i++) {

    MidAmp = MidAmp + floor(fft.getBand(i));

  }

 

  for(int i = 60; i < fft.specSize(); i++) {

    TreAmp = TreAmp + floor(fft.getBand(i));

  }

 

  //Audio leveling (the amplitude depends on the volume of your line in and so need leveling)

  if (BassAmp > MaxBass) {

      MaxBass = BassAmp;

  }

 

  if (MidAmp > MaxMid) {

      MaxMid = MidAmp;

  }

 

  if (TreAmp > MaxTre) {

      MaxTre = TreAmp;

  }

 

  int BassLvl = 255 - MaxBass;

  int TreLvl = 0;

  int MidLvl = 0;

  if (TreAmp > 5) {

    TreLvl = 255 - MaxTre;

  } else {

    TreLvl = 0;

  }

 

  if (MidAmp > 5) {

    MidLvl = 255 - MaxMid;

  } else {

    MidLvl = 0;

  }

 

  //Making the LEDs flash          

  if(beat.isOnset()) { //Bass flashes on a beat

    arduino.analogWrite(GreenPin, G);

    txtSize = 32; }

  //The others flash around the beats, depending on the amplitude  

  else {

    arduino.analogWrite(RedPin, TreLvl+TreAmp);

    arduino.analogWrite(BluePin, MidLvl+MidAmp);

    //arduino.analogWrite(GreenPin, BassLvl+BassAmp);

    arduino.analogWrite(GreenPin, 0);    // set the LED off

  }

 

//  }

 

  //Turn off LEDs between beats, I just turn bass off so it really flashes on a beat.

  //turning the others creates a nasty strobe effect

 // arduino.analogWrite(GreenPin, 0);    // set the LED off

arduino.analogWrite(RedPin, 0);    // set the LED off

//  arduino.analogWrite(BluePin, 0);    // set the LED off

 

  //Visually show a beat on screen  

  textSize(txtSize);

  text("BEAT", width/5, height/2);

  txtSize = constrain(txtSize * 0.95, 16, 32);

  text(BassAmp, 2*width/5, height/2);

  text(MidAmp, 3*width/5, height/2);

  text(TreAmp, 4*width/5, height/2);

  for(int i = 0; i < fft.specSize(); i++) {

    line(i, height, i, height - fft.getBand(i)*4);

  }

 

  //Reset the amplitude values between samples

  BassAmp = 0;

  MidAmp = 0;

  TreAmp = 0;

 

}

 

void stop() {

  // always close Minim audio classes when you are finished with them

  song.close();

  // always stop Minim before exiting

  minim.stop();

  // this closes the sketch

  super.stop();

}

 

 

 

2ND FILE: BeatListener

class BeatListener implements AudioListener

{

  private BeatDetect beat;

  private AudioInput source; //change from audioplayer since we are not using it

 

  BeatListener(BeatDetect beat, AudioInput source) //as above

  {

    this.source = source;

    this.source.addListener(this);

    this.beat = beat;

  }

 

  void samples(float[] samps)

  {

    beat.detect(source.mix);

  }

 

  void samples(float[] sampsL, float[] sampsR)

  {

    beat.detect(source.mix);

  }

}

 

Comments (0)

You don't have permission to comment on this page.