Page 1 of 1

A music equalizer visualization?

Posted: Thu Mar 08, 2012 8:33 pm
by Kingdaro
I've always wondered if it would be possible to make an equalizer visualization in love2d, since I've tried adobe aftereffects and that was just too much headache inducing work. It'd honestly be much easier for me if I could do it in lua or if you can think of another alternate method, go ahead and suggest that.

the kind of thing I'm thinking about is how you see some of those videos where you have different bars that react to specific frequencies in the music. example:
http://www.youtube.com/watch?v=oGgIxtoeFCc

I tried it in the past with SoundData but I just kept getting a white screen with "not responding", I was probably doing it wrong, haha
[hr]
Also, please be light on the terminology as I am no expert with love, just yesterday I found out you could find the width of an image object, haha.

Re: A music equalizer visualization?

Posted: Thu Mar 08, 2012 9:57 pm
by Adamantos
hey there,

in an equilizer every single bar represents a specific frequency (or better a range, for example 220Hz-250Hz)
In order to get this information you have to analyse the music on the fly. This is called "fourier transformation"
(see wikipedia for more information)

These calculation can be very fast and efficient (fast fourier - FFT), but still be a big effort.
Handling all these algorithms in lua is some heavy lifting and I don't think this is possible in real time....

If you are still interested, have a look at "LuaFFT"
http://www.mindfarming.de/luafft/

Re: A music equalizer visualization?

Posted: Thu Mar 08, 2012 9:59 pm
by thelinx
Well, there's this.

Re: A music equalizer visualization?

Posted: Fri Mar 09, 2012 12:48 pm
by Lovechild
Well if you are really intent on coding an equalizer, then there are two solutions I present that are not of the moon, but from a drop of milk.

Milkdrop 2.x, with free testing available from foobar2000's Spheck plugin (Windows)

Or if you take the more open route, a ProjectM visualizer. ProjectM is very similar to Milkdrop -- and is in fact made by the same guy (Ryan Geiss) -- that utilizes the PulseAudio sound server for people on systems using PulseAudio (e.g.Ubuntu) as an audio manager.

If you're really, truly intent on coding an Lua/Love visualization, then the code has to get the sound data from SOMEWHERE and interpret it. I would say target ALSA, OSS or Jack first (if sound data can be extracted from them, might be easier aiming for PulseAudio) and go for what Windows and Mac uses later once you have a working prototype on one of the more open sound solutions. So instead of letting Lua do all the heavy work, other components more specialized handle it and all your little app will do is interpret that output.

Re: A music equalizer visualization?

Posted: Mon Mar 12, 2012 12:08 am
by Kingdaro
well I was able to make something:
equalizer.love
(14.04 KiB) Downloaded 633 times
though it only works efficiently on smaller sound files, bigger files just show random spazzing lines that don't go with the music at all. at times I have to multiply dt by 2 for the music and visuals to sync, I'm not sure how to fix this.

Re: A music equalizer visualization?

Posted: Sun Apr 22, 2012 1:21 pm
by bitshifter
Kingdaro wrote:though it only works efficiently on smaller sound files, bigger files just show random spazzing lines that don't go with the music at all. at times I have to multiply dt by 2 for the music and visuals to sync, I'm not sure how to fix this.
I think I've fixed both the equalizer getting out of sync and needing to sometimes multiply dt by 2.

Rather than trying to keep track time to determine what sample the music is up to, you can just do:

Code: Select all

local curSample = music:tell('samples')
The reason you would have had to multiply dt by 2 is because you aren't handling multiple channels (i.e. stereo). For stereo you'll have to deal with two samples for each channel:

Code: Select all

for i=curSample, (curSample+(size-1) / 2) do
     local sample = (sound:getSample(i * 2) + sound:getSample(i * 2 + 1)) * 0.5
     table.insert(wave,complex.new(sample,0))
end