… sorry about that. I can update it so it will Sync TO VBL, want me to change the music? I only picked something that you could actually see the changes being made.
Update: Ok, so I added Sync to VBL and I changed the music. Hopefully it’s less annoying now. Anyone know a way to average these values so it’s no so erratic? Thanks
I didn’t think it was that good, I was just showing the spectrum analysis. Since no one else has posted anything about it, I thought someone would think it was interesting… but I guess I thought wrong
thank you!
finally a first little demo/example of spectrum analysis
it’s my most wanted features needed for U3… and i didn’t know it was already into v3 until today!
i have it… but the docs are really a few words sentence!
anyway (on imac 2.8) i see several bad rendering with U3 betas…
v2.6 is perfect… so i hope there’s still some bug somewhere
pelase keep on with sharing prototypes!
some code would be welcome also!
It will be dependent on material. Run your audio through a spectral analyzer of some sort to get an idea of what you’l need. (Logic and Soundtrack would be my choices.) Channel should be easy enough to find; just pick the one that lights up prettiest when you hear what you want to trigger something. Freq will be in the middle of the hump that corresponds to what you’re listening for. numSamples will have to be bigger, the lower freq is.
I don’t know anything about window functions but Wikipedia seems to have a good entry, so I’ll start there when I have some time to read up.
I use either 0 or 1 for channel, try both and test to see which works out better for you. Number of samples must be a power of 2, I have mine set at 256. Frequency you should just change values at runtime and adjust to your liking. Hope that helps?
what I was saying is how to get this kind of thing to get audio spectrum in -real time- from incoming audio (mic), not as it is now, from playing buffers of audio…
So, Audio.GetSpectrumData() - That’s a .net class?
All the unity classes I’ve been able to find are under AudioSouce or AudioListener.
Is there more goodness under Audio.?? :)?
Another thing. Loading the new .mod files off of WWW . It seems there is no built in way to do it. (There is one for Ogg). Though there is a way to load bytes or text. But that isn’t straight forward. Maybe through the AssetBundles? I was wondering are the assetBundle functions no longer pro only? The manual doesn’t state that they are pro only, so I’m wondering.
Thanks for the example script. Here is a script that will allow you to see the audio spectrum as bars. Im new to unity and I havent finished this properly, basically Im trying to make it clever enough to deal with a range of different number of samples without lots of the bars disappearing beyond the camera, but its not right yet and Ive run out of time so I shall post it as it. It isnt too bad if you have the number of samples set to 64 and the camera z position set to around -12.
Create a prefab that is just a basic cube. Attach this script to the camera. Drag your cube prefab to Abar. Put your audio Source near to the camera. Set numSamples. Run.
var Audio : AudioListener;
var numSamples : int;
var numberleft = new Array ();
var numberright = new Array ();
var thebarsleft = new Array(GameObject);
var thebarsright = new Array(GameObject);
var abar : GameObject;
function Start () {
var spacing = 0.4 - (numSamples * 0.001f);
var width = 0.3 - (numSamples * 0.001f);
for(i=0; i < numSamples; i++){
var xpos = i*spacing -8.0f;
var positionleft = Vector3(xpos,3, 0);
thebarsleft[i] = Instantiate(abar, positionleft, Quaternion.identity);
thebarsleft[i].transform.localScale.x = width;
thebarsleft[i].transform.localScale.z = 0.2;
var positionright = Vector3(xpos,-3, 0);
thebarsright[i] = Instantiate(abar, positionright, Quaternion.identity);
thebarsright[i].transform.localScale.x = width;
thebarsright[i].transform.localScale.z = 0.2;
}
}
function Update () {
var numberleft = Audio.GetSpectrumData(numSamples, 0, FFTWindow.BlackmanHarris);
var numberright = Audio.GetSpectrumData(numSamples, 1, FFTWindow.BlackmanHarris);
for(i=0; i < numSamples; i++){
thebarsleft[i].transform.localScale.y = numberleft[i]*30;
thebarsright[i].transform.localScale.y = numberright[i]*30;
}
}
What you will likely notice is that the spectrum data is much weaker once you get beyond the first few samples. You can compensate for this by using a larger multiplier as you go through the array of samples, so for example you could change the last few lines of code to something like the following (not a very sophisticated example, Im only just starting this voyage):
Also what you really need to do to make this stuff visually appealing is to smooth out the values quite a bit over time so that the bars arent flickering so wildly every frame.