Pages: [1] 2   Go Down
Author Topic: [noob] Music responsive visuals  (Read 2493 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I've been working with Processing to create visuals from my music, but I can't have efficient beat detection, so I thought it might be easier to use all my available line outs from my soundcard to send separate elements, send them to the Arduino which would communicate with Processing via Firmata... The thing is I know nothing about dealing with audio using the Arduino, I guess I need some components to convert the line signal to a 0-5V signal, and couldn't find any noob oriented tutorial on the web.

Thanks for your input!
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 10
Posts: 1235
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What problem are you having with beat detection in Processing? BeatDetect class in Minim not working for you? Why do you believe the Arduino will be better at processing audio than a CPU thousands of times more powerful?
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, it's not working fine, not even with the audio file included ("kick" lights up when there is no kick, "snare" too, and "hi-hat" seems almost random) and my skills do not allow me to improve it. I just want the Arduino to send levels to Processing, is that too much for it? I don't want it to perform any FFT...
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 10
Posts: 1235
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Processing's beat detection is not going to be perfect, but probably as good as anything you'll accomplish with an Arduino in the mix. What "levels" were you wanting to send? Various frequency bands?
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Offline Offline
Edison Member
*
Karma: 6
Posts: leet
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made a cool light show with the MSGEQ7 chip and 4 LED's.
Also works with El wire.

Code:
#define f11 turn on LED 1
#define f01 turn off LED 1
...

 digitalWrite(resetPin, HIGH);
 digitalWrite(resetPin, LOW);
 for(int i = 0; i < 7; i++) {
   digitalWrite(strobePin,LOW);
   delayMicroseconds(30); //to allow the output to settle
   spectrumValue[i] = analogRead(analogPin)-100;
   digitalWrite(strobePin,HIGH);
   }
//you can choose any bands 0-6
if(spectrumValue[0]>was[0]+100+j    ) f11
if(spectrumValue[2]>was[2]+100+j- 20) f12
if(spectrumValue[3]>was[3]+100+j- 20) f13
if(spectrumValue[5]>was[5]+100+j- 40) f14
if(any){
  j+=40;  //how often
  delay(8);  //if you increase this my LEDs will fry
  f01 f02 f03 f04
  delay(4);  //needed because I didn't use any resistors
  }
j--;
for(int i=0;i<=7;i++)was[i]=spectrumValue[i];
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Processing's beat detection is not going to be perfect, but probably as good as anything you'll accomplish with an Arduino in the mix. What "levels" were you wanting to send? Various frequency bands?
nope, i want to send separate tracks and simply check how loud the audio is for each track. i'm trying to actually avoid beat detection.
Logged

Offline Offline
Edison Member
*
Karma: 6
Posts: leet
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How many tracks?  That's easy.  Sample them all at once.  Either a simple envelope follower circuit for each track or do it in software.  Don't let anyone tell you the Uno doesn't have enough processing power.  Your project sounds simple compared to FFT.  First some simple calculations.  Let's say N tracks.  60khz/N = how often you can sample each track.  If N=60 then only 1khz, which will miss the high end, but over time it doesn't matter.  How often do you want to calculate a sound level?
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

SF Bay Area
Offline Offline
Edison Member
*
Karma: 10
Posts: 1235
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In Processing and Minim you have direct access to the waveform data, so you can run whatever calculations you want. More importantly you can simply use the "level" method to directly get the volume of any AudioBuffer. I'll just paste the example directly from the Minim docs:
Code:
/**
  * This sketch is an example of how to use the <code>level</code> method of an <code>AudioBuffer</code> to get the
  * level of one of an <code>AudioSource</code>'s sample buffers. The classes in Minim that extend <code>AudioSource</code>
  * and therefore inherit the <code>left</code>, <code>right</code>, and <code>mix</code> buffers of that class, are
  * <code>AudioInput</code>, <code>AudioOutput</code>, <code>AudioSample</code>, and <code>AudioPlayer</code>.
  * Not coincidentally, these are also all of the classes in Minim that are <code>Recordable</code>.
  * <p>
  * The value returned by <code>level</code> will always be between zero and one, but you may find that the value
  * returned is often smaller than you expect. The level is found by calculating the root-mean-squared amplitude of the
  * samples in the buffer. First the samples are all squared, then the average (mean) of all the samples is taken (sum
  * and then divide by the number of samples), then the square root of the average is returned. This is why the range can be
  * determined as [0, 1] because the largest value a squared sample can have is 1. However, in order for the RMS amplitude
  * to equal 1, every sample must have either -1 or 1 as its value (amplitude). This is only going to be the case
  * if your sound is a square wave at full amplitude. If your sound is a song or other complex sound source,
  * the level is generally going to be much lower.
  */
 
import ddf.minim.*;
import ddf.minim.signals.*;
 
Minim minim;
AudioPlayer groove;
 
void setup()
{
  size(200, 200, P3D);
  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3");
  groove.loop();
  rectMode(CORNERS);
}
 
void draw()
{
  background(0);
  fill(255);
  // draw the current level of the left and right sample buffers
  // level() returns a value between 0 and 1, so we scale it up
  rect(0, height, width/2, height - groove.left.level()*1000);
  rect(width/2, height, width, height - groove.right.level()*1000);
}
 
void stop()
{
  // always close Minim audio classes when you finish with them
  groove.close();
  // always stop Minim before exiting
  minim.stop();
 
  super.stop();
}

sbright33: The OP is suggesting that Processing can't do what they want, and proposes sending audio out to an Arduino and then pulling it back into the computer. They haven't said they even want to do anything else with the Arduino besides use it to process audio. The whole idea seems completely backwards and inefficient compared to just learning to use the tools in Processing correctly, which is why I'm trying to point out easier ways.
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Offline Offline
Edison Member
*
Karma: 6
Posts: leet
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right, if you're going to use a PC anyway, there's no need for Arduino.  How many inputs does a sound card have?  If there's only 2 I can see an advantage to his method.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How many tracks?  That's easy.  Sample them all at once.  Either a simple envelope follower circuit for each track or do it in software.  Don't let anyone tell you the Uno doesn't have enough processing power.  Your project sounds simple compared to FFT.  First some simple calculations.  Let's say N tracks.  60khz/N = how often you can sample each track.  If N=60 then only 1khz, which will miss the high end, but over time it doesn't matter.  How often do you want to calculate a sound level?
Thanks for your help! 6 tracks, so 10kHz. Software or hardware, I don't know how to do it either way. Do you know where I can learn, starting from almost 0?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In Processing and Minim you have direct access to the waveform data, so you can run whatever calculations you want. More importantly you can simply use the "level" method to directly get the volume of any AudioBuffer. I'll just paste the example directly from the Minim docs:
Code:
/**
  * This sketch is an example of how to use the <code>level</code> method of an <code>AudioBuffer</code> to get the
  * level of one of an <code>AudioSource</code>'s sample buffers. The classes in Minim that extend <code>AudioSource</code>
  * and therefore inherit the <code>left</code>, <code>right</code>, and <code>mix</code> buffers of that class, are
  * <code>AudioInput</code>, <code>AudioOutput</code>, <code>AudioSample</code>, and <code>AudioPlayer</code>.
  * Not coincidentally, these are also all of the classes in Minim that are <code>Recordable</code>.
  * <p>
  * The value returned by <code>level</code> will always be between zero and one, but you may find that the value
  * returned is often smaller than you expect. The level is found by calculating the root-mean-squared amplitude of the
  * samples in the buffer. First the samples are all squared, then the average (mean) of all the samples is taken (sum
  * and then divide by the number of samples), then the square root of the average is returned. This is why the range can be
  * determined as [0, 1] because the largest value a squared sample can have is 1. However, in order for the RMS amplitude
  * to equal 1, every sample must have either -1 or 1 as its value (amplitude). This is only going to be the case
  * if your sound is a square wave at full amplitude. If your sound is a song or other complex sound source,
  * the level is generally going to be much lower.
  */
 
import ddf.minim.*;
import ddf.minim.signals.*;
 
Minim minim;
AudioPlayer groove;
 
void setup()
{
  size(200, 200, P3D);
  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3");
  groove.loop();
  rectMode(CORNERS);
}
 
void draw()
{
  background(0);
  fill(255);
  // draw the current level of the left and right sample buffers
  // level() returns a value between 0 and 1, so we scale it up
  rect(0, height, width/2, height - groove.left.level()*1000);
  rect(width/2, height, width, height - groove.right.level()*1000);
}
 
void stop()
{
  // always close Minim audio classes when you finish with them
  groove.close();
  // always stop Minim before exiting
  minim.stop();
 
  super.stop();
}

sbright33: The OP is suggesting that Processing can't do what they want, and proposes sending audio out to an Arduino and then pulling it back into the computer. They haven't said they even want to do anything else with the Arduino besides use it to process audio. The whole idea seems completely backwards and inefficient compared to just learning to use the tools in Processing correctly, which is why I'm trying to point out easier ways.

I've been playing with Minim already:


But I couldn't get it to work with any audio in from my soundcard, it just seems to listen to the motherboard's line in which I don't use. If you know how to tell Minim to listen to my other inputs (2 at once), please tell.
I've only got 2 line ins on my soundcard anyway, so I can't process 6 signals at once with Processing, unless there's a ReWire library.
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 10
Posts: 1235
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The AudioInput is supposed to use whatever you have selected as your mixer input on your computer. As far as I know, it won't let you record from multiple sources at once...just like the majority of the programs out there that don't have special hardware associated.

However, at the beginning of this thread you said you were going to send the audio OUT of your computers sound card, so I assumed that you had control of the audio in the first place. Apparently that's not true, you're pulling in audio from some other source? Because if you did use Processing to play the audio, then you would have software access to everything.
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The AudioInput is supposed to use whatever you have selected as your mixer input on your computer. As far as I know, it won't let you record from multiple sources at once...just like the majority of the programs out there that don't have special hardware associated.

However, at the beginning of this thread you said you were going to send the audio OUT of your computers sound card, so I assumed that you had control of the audio in the first place. Apparently that's not true, you're pulling in audio from some other source? Because if you did use Processing to play the audio, then you would have software access to everything.
Ok, maybe I messed when I tried using AudioInput, I'll try again. And no, I'm not using Processing to generate or play the audio, it comes from other software which allows me to send whatever I want to any of my outputs... Sorry if I haven't been clear enough, English isn't my mother tongue, I'm struggling sometimes... smiley-razz
Logged

Offline Offline
Edison Member
*
Karma: 6
Posts: leet
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just make sure the voltage is between 0-5v to go into A/D.  You need to choose a time interval to measure the sound level.  During that time look for the maximum and minimum sample value.  Subtract.  Scale to a range you want.  I can write you some pseudocode if you like.  You can fill in the details.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just make sure the voltage is between 0-5v to go into A/D.  You need to choose a time interval to measure the sound level.  During that time look for the maximum and minimum sample value.  Subtract.  Scale to a range you want.  I can write you some pseudocode if you like.  You can fill in the details.
Thanks a lot for offering your help, but I actually have no idea about the hardware part, I'm finding very interesting things from google results but nothing telling me what components I need and how to convert a line audio signal to a 0-5V signal.
Logged

Pages: [1] 2   Go Up
Jump to: