Cendroid determines the time-variant spectral centroid for a soundfile, and allows the user to specify the concentration of spectral energy around that centroid, change that concentration over the length of the file, and modify various other sonic parameters. Cendroid acts like a self-tuning, or adaptive, band-pass filter, following the spectral centroid. Like a filter, the bandwidth, "Q", and other time-variant parameters are open to user control.
Cendroid was written as an example program for a graduate seminar in timbre at Dartmouth College, to provide students with some sample code and ideas for manipulating spectral data with Erbe's Spectral Assistant.
The spectral centroid of a sound is a concept adapted from psychoacoustics and music cognition. It measures the average frequency, weighted by amplitude, of a spectrum. In cognition applications, it is usually averaged over time.
The standard formula for the (average) spectral centroid of a sound is:

where ci is the centroid for one spectral frame, and i is the number of frames for the sound. A spectral frame is some number of samples which is equal to the size of the FFT. The (individual) centroid of a spectral frame is defined as the ave rage frequency weighted by amplitudes, divided by the sum of the amplitudes, or:

In practice, Cendroid finds this frequency for a given frame, and then finds the nearest spectral bin for that frequency. This yields an accuracy which is dependent upon the analysis framesize. For example, for an FFT size of 2048, the bin sizes ar e approximately 20 Hz, so the maximum error would be 10 Hz.
The centroid is usually a lot higher than one might intuitively expect, because there is so much more energy above (than below) the fundamental which contributes to the average. Care should be taken not to confuse the centroid with the fundamental. Rather , it is often used as a measure of "brightness" in comparing sounds. The higher the centroid, the "brighter"the sound. Time-varying centroids like those in our implementation, are uncommon in the literature, but can be useful in comparing sound morphologi es, or in this case, in designing a kind of experimental filter.
To use Cendroid, you must first use Tom Erbe's SoundHack to spectrally analyse a soundfile. Do this in SoundHack under the "Hack" menu. This will save the spectral data analysis of the soundfile as an "SA" file, SoundHack's spe ctral datatype consisting of a list of magnitude/phase pairs.
Cendroid only works on mono files. Do not pass it the results of a stereo file analysis - although it probably won't crash, the results will be completely unpredictable.

Cendroid will pop up a dialog box which allows you to set a number of parameters. These parameters provide different ways to redistribute the spectral energy around the centroid over time. This is similar to working with the shape of a filter.

spread start: The initial energy concentration value.
spread end: The final energy concentration value.
decay rate: This value specifies the sharpness of the energy dropoff away from the centroid (for a given value for spread). Considered as a bandpass filter (where the center frequency is the centroid, and the bandwidth is controlled by spread), thi s is like the Q of the filter. Larger values make the dropoff quicker, or make the Q greater.
interp(olation). type: A value of 0 tells the program to linearly interpolate between the starting and ending spread value. A value of 1 tells it to use an exponential interpolation (see interpolation degree, below).
interp(olation).degreee: For exponential interpolations of spread, you can set the function's exponent, affecting the time varying steepness, or rate of change of the slope of the interpolation trajectory. Interpolation degrees greater than 1 make it move slowly at first, and then more rapidly. Values less than 1 do the opposite. Here are some examples:

freq(uency). bias: This is a single value which offsets the centroid frequency by a constant amount. This can produce some interesting, pitch-shifting kinds of effects.
bias jitter: This sets a frequency range, between 0 and the number entered, for randomizing the frequency bias of each frame. The bias jitter is the possible range of random variation around the bias-adjusted centroid (which changes over time). T ry making this larger for some interesting effects.
Once the parameters are set, hit the "Make it so" button, and then hit the "spectral centroid" button on the ugly looking window. Cendroid will ask you to save the output file.
(This file will then need to be resynthesized using the Spectral Resynthesis item under the "hack" menu in SoundHack.)
Cendroid will next ask you to save the "centroid data" to a data file. This is a text file containing a list of each frame's centroid frequency. This is for analysis purposes, graphing, or whatever you like.
Once Cendroid starts processing, be patient, it takes a long time since it reads everything directly off disk. Cendroid uses the standard interface inherited from the Spectral Assistant template. You can speed it up a bit by clicking once on the graphics window, which toggles the display off and on. The display is also a bit unusual - it scrolls by periodically restarting or wrapping around to the beginning of the window. The little incrementing number indicates the frame being read. The top window is a sonogram of the input file, the bottom, the output file (the result of Cendroid). Spectral amplitudes are indicated by color.
These output files are big (twice as big as the soundfile would be), so make sure there is plenty of space where you're putting it. If not, Cendroid will tell you that it couldn't write an output file.
Erbe, Tom. SoundHack. http://shoko.calarts.edu/~tre.
You can get Spectral Assistant here, if you are interested in writing your own programs like this.
Thanks to Jamshed Bharucha, Mark Tramo, and John Puterbaugh for advice on centroids.
Cendroid is a free, public domain program. Please send us comments, suggestions, bugs, etc.