Reading Audio Data?

Hello. I recently found a script that displays a bunch of values based on the selected audio source…but what do they mean(volume spikes, etc.)? There is a long list of values, are they taken from the song every few seconds?

Code:
var theClip : AudioClip;
function Start () {
audio.clip = theClip;
audio.Play();
var spectrum : float = audio.GetOutputData (128, 2);
for (var i = 0; i < spectrum.Length; i++)
print(spectrum*.ToString());*
}

The values come from pulse-code modulation, and correspond with your speakers’ displacement in physical space along their “z axis”.

Is it calculating new values every frame? How do I access these values in another function? Can I calcculate things like BPM and volume spikes using the GetSpectrumData or GetOutputData?

I’m also having trouble figuring out how GetSpectrumData/GetOutputData work.

I understand why GetSpectrumData returns an array - each value in the array corresponds to a certain amplitude of a frequency defined by the index. However, I don’t understand why GetOutputData returns an array. Should it not just return a float which represents the amplitude of the entire clip? What, technically, does GetOutputData actually return?

Thanks! =)

It returns an array of the amplitudes of the last n played samples (the numSamples parameter). You could just specify one sample, but that wouldn’t be very interesting or representative for the output power (it would be the power of 1/44000 sec in time).

Fantastic! So just to really be redundant, if I wanted to grab the “current amplitude” of an audio source, I would just need to reference the last index in the returned array on every frame?

Examining the value of a single sample probably won’t give you much in the way of useful information. To find out information such as current overall volume, a more sophisticated analysis will most likely be required.