Page 1 of 2

LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Thu Feb 16, 2017 7:29 pm
by darkmetalic
Hello guys, I making avaliable a sequence of sound effects in spectral waveform with colors, only in Lua. I got it somewhere and I changed all the code and optimized, removed bugs and added more functions and effects.

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Thu Feb 16, 2017 7:29 pm
by raidho36
OK, cool.

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Thu Feb 16, 2017 8:01 pm
by Positive07
raidho36 wrote: Thu Feb 16, 2017 7:29 pmOK, cool.
I got nothing more to say than what raidho said... This looks great!

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Fri Feb 17, 2017 1:32 am
by bgordebak
Cool!

I tried with some other audio files too. Works great!

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Fri Feb 17, 2017 3:10 pm
by darkmetalic
bgordebak wrote: Fri Feb 17, 2017 1:32 am Cool!

I tried with some other audio files too. Works great!
This is the good side, you can put any kind of audio supported without rules being stereo or mono, the problem is there are stereo sounds that you can barely see good visual effects because the frequency rate is very high

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Fri Feb 17, 2017 7:44 pm
by zorg
Oh, so it's a Spectrum Analyzer, nice work; i hate you for the initial fullscreen though. :3

That being said, if you're using a better FFT than what i found on github, i'll start to like you instead :D

Looks like you're using the same shitty lib i am, that doesn't support different sampling rates, and it has tons of issues... welp, too bad. :|

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Sat Feb 18, 2017 4:03 pm
by Ref
Great!
Just wondering how frequency is related to spectrum:abs() value.

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Sat Feb 18, 2017 4:35 pm
by zorg
Ref wrote: Sat Feb 18, 2017 4:03 pm Great!
Just wondering how frequency is related to spectrum[ i ]:abs() value.
The spectrum table holds the bins the FFT lib calculated; bins are complex numbers, and each real and imaginary part is signed, since it's not amplitude, but phase information; the abs method on those complex numbers does a "sqrt(re^2 + im^2)", so basically it returns the geometric distance, which probably corresponds to the amplitude of the signal for one component of the spectrum.

Then again, this might be wrong, since for the most part, he just copied the supplied example project from the github repo (which, again, is a horribad fft implementation for various reasons); whether or not that operation is correct is sadly something i don't know; one might just get the real part and show that instead; since this is a visualizer, it doesn't have that much effect on anything but the visuals.

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Sat Feb 18, 2017 5:34 pm
by Ref
But isn't there some relationship between 'i' and 'frequency'?
Otherwise, what does the 'visualizer' show?

Re: LOVE2D - SoundEffect Spectrum Surge (pure Lua)

Posted: Sat Feb 18, 2017 6:33 pm
by zorg
Ref wrote: Sat Feb 18, 2017 5:34 pm But isn't there some relationship between 'i' and 'frequency'?
Otherwise, what does the 'visualizer' show?
Ah, but there is! Or at least, it would be if the fft implementation wouldn't suck.
The way i'd imagine it, is that you give the fourier transform a maximum frequency (a sampling rate of 44.1 kHz, for example), and the number of bins you want to get out of the signal you pass into it... (First one should be the DC component in all cases though, basically the main offset of the signal, which also has a constant 0 imaginary part)

The library used here has one input, a table of samplepoints.
...
If you pass it 1024 smp-s, you get back 1024 bins. (Half of it mirrored on the nyquist frequency (samplingrate / 2), of course, so totally useless from a visualization standpoint)
...
If your sampling rate is anything but 44.1 kHz, then the relationship is messed up, but otherwise, for that exact rate, it works, somehow.
Also, the equation is this: frequency (Hz) = i / (#spectrum (number of bins) / 44100)
At least, iirc that was in the original code example.
Also sorry for my overall tone, it's not the OP whose code i'm mad about, to be clear, but the person who made the lua port of the fft lib, that he uses.

In any case, the fft does give back a table with values relating to frequency ranges, but the partition sizes, count, and the frequency limit is what's inflexible; It's still in the Frequency Domain.

Worth noting that while i do dabble in music, both from a coding and a composing perspective, i don't claim that i understand everything regarding fourier transforms and related stuff; i might be wrong.

Also some disclosure: I use the same p.o.c. lua fft lib in my visualizers as well.