Spectrum Analyser!

Community Forums/Showcase/Spectrum Analyser!

Boiled Sweets(Posted 2006) [#1]
I've always wanted to be able react to an audio stream in Blitz. I don't just mean play an MP3 and react to it I mean 'hear' what the user is listening to, whether it's coming in from your sound cards audio in, internet radio, media player etc etc.

This little puppy is capable of showing the amplitude of 2048 different frequencies per channel in real time! Well here it is...



I guess it will just remain a technical demo but could be useful to make screen savers that react to what the user is listening to or even music based games. If there is any interest in this I might continue to develop it, either into an app or as a Blitz helper library. It uses BASS. If you want to try it let me know, I might be willing to post a working demo if there is any interest.

The amplitute meters push up the peak meters which hold for a moment then drop. All nice and smooth too!

Thanks for listening (pun intended).

Thanks to Lab[au]


OJay(Posted 2006) [#2]
hm, i wonder if it would be possible to do lipsync-facial animation while a npc is speaking...or even better: a player in a multiplayer game is speaking through his headset to you and the model does react realistical to his words...wouldnt THAT be cool? ^_^

maybe language has a typical sound-spectrum, which can be analysed? what do you think?


Boiled Sweets(Posted 2006) [#3]
Send me a voice (spoken) sound file (mp3).


Beaker(Posted 2006) [#4]
I tried something similar to what OJay is talking about a while back, just using the volume of the incoming audio. It didn't work that great, not least cos of a slight lag. It did have novelty comedy value tho. :)


OJay(Posted 2006) [#5]
sure, if it would be THAT easy, EVERY game would have that feature :D


*(Posted 2006) [#6]
how did you get the levels of the channels, ive been trying to find a way of doing that for ages :)


Ross C(Posted 2006) [#7]
Why not store the data beaker? If you can work out the lag, you could fix that problem?


Boiled Sweets(Posted 2006) [#8]
Edzup,

grabbing the FFT sample data in a memory bank.

The only lag I see is asking poor old Blitz to do 4096 2d rects and 4096 2d lines!!!


polygoon(Posted 2006) [#9]
Nearest I can come up with as a use for that is as follows:

Get a mike and plug it in, dangle it out the window.

Somehow get input from an AM radio to the line in and makesure it is NOT tuned to a station.

Light sensing diode or what ever looking for sudden brightness changes, also dangled out of window.

Then using your skill and judgement as the coder of this opus, you listen on the radio for a crakle, then check the visual for sudden brightening, and finaly wait for the audio to piuck up the rumble.

What you got there is a lightning strike distance revealer! Just adjust for the known speeds for sound, light, and radio propagation and you can figure out the distance. Add a few more light probes and you might make a stab at the direction too! You just time log each incident and then apply the maths. Once in a while you'll be right on the money too.

Simple fun project, which would be incredibly cool once debugged. Plenty of little problems around all this to make it rewarding to get it right too.


*(Posted 2006) [#10]
Got an example, it would be greatly appreciated.


Boiled Sweets(Posted 2006) [#11]
polygoon,

hahahahhahaa - nice one!

EdzUp,

how about a working exe?


Beaker(Posted 2006) [#12]
Ross C - yes could do that, but I was just doing it for fun, and an excuse to model a head with a moving mouth.

What you really need is to be able to detect the right mouth shapes. That might be possible with the seperated frequencies, but you can't beat doing it by hand.


John Blackledge(Posted 2006) [#13]
Beaker - yes, but even a simple up/down jaw (so long as it is synced) is better than a constantly moving up/down jaw. I know, I've faked both, and the difference is remarkable.

Boiled - keep on. A lib sounds like a great idea.


*(Posted 2006) [#14]
the only question I have is can it be done in native Blitz without the need for external dll's etc (not including windows ones) the only reason I ask is I want to capture microphone input for a project im working on and I havent worked out how to do that yet. I have asked several times on the forum to no avial.


Boiled Sweets(Posted 2006) [#15]
EdzUp,

whilst I am no expert on this I would say the answer to your question is no, Blitz cannot do this without an external DLL hence me spending a week to get it working with BASS.DLL.

The only problem I can see with using a BASS is that it's not free. What other problem do you have with using a DLL?


*(Posted 2006) [#16]
thats the main one, I wanted it to work with Hunted so creatures could 'hear' you make to much noise ;)


Boiled Sweets(Posted 2006) [#17]
Well BASS is free for non commercial use and only £67 for multiple shareware products so...


*(Posted 2006) [#18]
ah will have a looky


Yan(Posted 2006) [#19]
the only question I have is can it be done in native Blitz without the need for external dll's etc (not including windows ones)
If you mean recording from the mic then, yes. If you mean the spectrum analyser thing, I'm not sure, but probably not.

I've got some MCI code laying around if you need it.

[edit]
Ah...I've just noticed this...
thats the main one, I wanted it to work with Hunted so creatures could 'hear' you make to much noise ;)
Probably not what you want then.
[/edit]


*(Posted 2006) [#20]
Yan email it to ed@... and I will have a look :)


jfk EO-11110(Posted 2006) [#21]
This is fascinating, I didn't know it's so easy to grab fast fourier transformation data. I was trying to implement this in software, and of course miserably failed :o)

Will you release the source for this?

This would be extremly useful for me. I got a radio scanner up to 2.4 GHz and I'd like to decode embassy faxes and stuff :)

I currently cannot afford WAVECOM, so something written in blitz would be great ;)


Boiled Sweets(Posted 2006) [#22]
jfk,

well the bulk of the work is done by the BASS library. Blitz simply gets the data from BASS in a few lines of code.

The problem I have is creating a tidy files containing just the BASS consts and the decls. It will take some time but not impossible. I only converted the bits I needed to make this work.

The other consideration is whether I 'wrap' the BASS library and then provide the wrapper Blitz library or simply give away what I have dones so far (which I'm reluctant to do as this project may develop into somehting else).

Perhaps I'll just clean up the consts and decls for the latest BASS and release that to the community -- it's the least I can do for all the help I've had. Regards the grabbing of the FFT data I'll post an example...


*(Posted 2006) [#23]
I just want to get the volume level of the microphone, will have to look at bass more closely as there isnt a source demo for it.


Boiled Sweets(Posted 2006) [#24]
Getting the volume level of the mic is pretty easy using BASS something like...

BASS_RecordInit(-1)
record_input = -1
i = 0
While record_input <> 0
   record_input = BASS_RecordGetInput(i)
   if record_input <> 0
      If BASS_RecordGetInputName(i) = "Microphone"
         mic_volume = loword(record_input)
      EndIf
      i = i + 1
   EndIf	
Wend

Function LoWord(Value)
   Return (Value And $0000FFFF)
End Function



jfk EO-11110(Posted 2006) [#25]
Does anybody know if the BLitzBASS dll supports FFT access?


Boiled Sweets(Posted 2006) [#26]
It does but only from a file or url you play yourself.

If you want to get the FFT from say the audio in then you need to do this through the BASS record functions which are not available in the old Blitz BASS


LAB[au](Posted 2006) [#27]
Well to be more exact it supports it ... even audio in, but you'll have to select this input manually in sound/audio control panel in windows. There are 2 versions of BlitzBass, the very first one was done for Bass 1.4 (no recording features) then a second one has been released for Bass 1.6 with recording features.

Yet doing a newer/updated version would be a good idea.


Yan(Posted 2006) [#28]
@Edzup - Sorry, I forgot all about this (I doubt it's going to be of any use to you anyway).

There really isn't much code so I'll post it here (apologies for the mini hi-jack)...



*(Posted 2006) [#29]
Thanks yan will have a look as soon as I get back to my computer


jfk EO-11110(Posted 2006) [#30]
Thanks for the info. I have BlitzBass160.zip on my harddrive. I tried to start the examples. A runtimeerror says:
"Non-existant or Incorrect Version of Bass.dll! Terminating!"
Tho, the bass.dll in the folder is the only one on my system, extracted from the zipfile.

I didn't see a decs file in the zip, nor was it mentioned somewhere. Is there something I am missing?


jfk EO-11110(Posted 2006) [#31]
Ok, now I found a working version of a decls for Bass.dll directly.
I'm using BASS_ChannelGetData%(channel,bank,BASS_DATA_FFT1024)

seems to work, but I can't help myself, it seems to me the higher frequencies have a much lower amplitude?

Do I have to grab the amplitude floats right from the bank, or is there still some mysterious thing to do with the floats before I can use them as band amplitudes? Like, sin(value) or somthing?

EDIT: well actually your screenies show the same thing, is that normal?


jfk EO-11110(Posted 2006) [#32]
Well.. sorry for hijacking this. Thanks for pointing me tho this however. It's very funny stuff.

With this you can demodulate audio signals, including multiplexed data.

Another question I got is: is there a way to calculate the corresponding middle frequency of one band returned by bass_data_fftN ?


Boiled Sweets(Posted 2006) [#33]
Lower frequencies are 'louder' than higher frequencies in this instance, its perfectly normal. I think there is (somewhere) an algorithm to 'level' out the amplitudes.

If you find it please post it here.


jfk EO-11110(Posted 2006) [#34]
That would be fine!