Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Processing audio player customization?

$
0
0
Hey people,

I am new to all this processing stuff (not familiar with all the fancy terms yet) but have a quick question. I am using the following code to match music played with processing to control PWMs on my arduino. Unfortunately the music player that opens if very simple. I can't play/pause the music or fast forward/rewind. Just curious if there is anything to add that might add some more features to the music player?

Thanks
-NJ

Edit: I forgot to mention that I am using processing 1.5.1 for this. No other version will work with this stuff.

//processing code for communicating with arduino using 
//Firmata library.
//In the arduino I've uploaded the StandardFirmata sketch.
//this program blink 5 leds in pins 3,5,6,9,10 
//detecting music rythm
//Code by Damiano Andreghetti
//Example song: No time to stop - Luca Guardigli
//For more information visit www.ilblogdidami.blogspot.com

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*; //Import ddf.minim library
import processing.serial.*; //Import serial library
import cc.arduino.*; //Import Arduino library

Arduino arduino; 
Minim minim;
AudioPlayer song;
FFT fft;
//I create the objects

//To play another song change the song_file value
String song_file = "mag3.mp3"; 
int xmax = 600; //window width
int ymax = 300;//window height
 
void setup()
{
  size(xmax, ymax);
  minim = new Minim(this);
  arduino = new Arduino(this, "COM5", 57600);
  song = minim.loadFile(song_file);
  song.play();
  fft = new FFT(song.bufferSize(), song.sampleRate());
  // in this function I create the minim object, I start 
  //communicating with Arduino,I load the song and I play it and 
  // I start the Fast Fourier Transofrm
}
 
void draw()
{
  background(0);
  fft.forward(song.mix);
  stroke(127, 255, 0, 200); //I set the color of my lines
  for(int i = 10; i < fft.specSize(); i++){
    line(i, height-30, i, height - (30+fft.getFreq(i*10)));
    // I create lines that represent the amplitude
    // of each frequency.
    text("Min Freq", 10, height-10);
    text("Max Freq", fft.specSize(), height-10);
  }
    ledcontrol(); //I call the function for the arduino
}

void ledcontrol(){
  //In this function I use arduino analogWrite function
  // to write in PWM pins the amplitude 
  // of five general frequency
// arduino.analogWrite(6, gate(120,100));
//arduino.analogWrite(5, gate(80,80));
  arduino.analogWrite(3, gate(120,100));
 //arduino.analogWrite(5, int(fft.getFreq(60)));
 // arduino.analogWrite(6, int(fft.getFreq(220)));
 // arduino.analogWrite(3, gate(64,200));
 // arduino.analogWrite(6, gate(300,100));
 // arduino.analogWrite(3, gate(220,100));
// arduino.analogWrite(5, gate(120,100));
 // arduino.analogWrite(3, int(fft.getFreq(220)));
// arduino.analogWrite(3, int(fft.getFreq(1000)));
//  arduino.analogWrite(6, int(fft.getFreq(600)));
 // arduino.analogWrite(5, int(fft.getFreq(1000)));
}

int gate(int i, int j)
{
  if(int(fft.getFreq(i))>j)
  {
    return 255;
  }
  return 0;
}




Viewing all articles
Browse latest Browse all 1768

Trending Articles