while (position < streamLength)
{
float[] d = new float[spectrumSize];
Bass.BASS_ChannelGetData(stream, d, maxFFT);
posTofftData.Add(d);
position = Bass.BASS_ChannelGetPosition(stream);
}
For a certain MP3, the position does not advance from 37494784 to 37495296. So I get a memory overflow (the d array is initialized in a while (true). Any ideas? Who needs, I can give the mp3 (it's too big to attach it here). Thank you.
What line does the problem occur at? I'm not a .Net user myself, so I'm not certain how things work there, but perhaps the problem is the "new" call in the loop? There is no real need for that to be inside the loop (unless it's needed by the "posTofftData.Add" line?), so you could try moving it outside the loop, eg. to just before the "while" line. If the problem still happens, also try using BASS_ChannelIsActive (rather than the position) to detect when the end is reached, like this...
float[] d = new float[spectrumSize];
while (Bass.BASS_ChannelIsActive(stream))
{
Bass.BASS_ChannelGetData(stream, d, maxFFT);
posTofftData.Add(d);
}
I do not know how BASS_ChannelGetData provides the data:
on an aprox 400 sec length mp3 file:
If I give BASS_DATA_FFT4096, then I get 4241 arrays of 2048 and a big spectrum of frequencies (2048 frequencies)
If I give BASS_DATA_FFT256, then I get more than 67841 arrays of 128 and a smaller spectrum of frequencies (128 frequencies)
1) From what I understand, getting data with BASS_ChannelGetData advances the song. Why does it advance differently in these 2 cases?
That is because different amounts of sample data are required for the different FFT sizes, ie. BASS_DATA_FFT4096 requires 4096 samples from the stream, while BASS_DATA_FFT256 requires 256 samples.
2) How can I get more arrays with BASS_DATA_FFT4096? Is it possible without setting the position in song? Is there any way to get BASS_DATA_FFT4096 on a fixed number of msec from a song? (Ex: I want the BASS_DATA_FFT4096 on 20 msec sections of a song). I may need more data on less timespan. 4096 gives around 10 arrays/second, I may need more than that.
No, you would need to set the position (via BASS_ChannelSetPosition) before each BASS_ChannelGetData call in that case.
3) The values in the float arrays returned, are the intensity of the frequency? I get the frequency using Utils.FFTIndex2Frequency.
Each FFT bin/value contains the amplitude of (or close to) the frequency given by FFTIndex2Frequency in the stream. For example, if the stream has a 1000 Hz tone with an amplitude of 0.5, then the FFT bin corresponding to 1000 Hz will have an ampitude of 0.5 (may be slightly lower if 1000 Hz isn't the bin's centre frequency).