If i remember correctly (no time to properly check right now, so please take with caution!) - the bins are divided in a linear fashion, so:
Code:binWidth = nyquistFreq / numBins
binWidth = 22050 / 256 = 86.1328 Hz (example)
To important thing is that the very 1st bin of the spectrum will always only be half the width of all other bins:
Code:binWidth_0 = binWidth / 2;
That leads us then to the Matching-A-Freq-To-A-Bin equation:
Code:int binIndex = (int)( (freq-binWidth_0) / binWidth + 1 );
binIndex = (int)((440-43.0664)/86.1328 + 1) = 5
In order to get the average level of a whole frequency band, you'd then have to get the bin indices of the band's lower and upper bounds and then compute the mean of all contributing bin values... Marius, maybe that's a nice candidate function for your helper library?
Re: logarithmic scale - this is more required when trying to work out the bandwidth of filters and/or for musical analysis, since the frequency range of each consecutive octave is doubling. e.g. A0 = 440Hz, A1 = 880Hz, A2 = 1760Hz etc.
Again, this is all just off the top of my hat, without any warranty...
I'd very much appreciate getting any clarifications about this myself, though - so please do let us know if the above is incorrect! Cheers.