Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
DWORD BASS_ChannelGetData( DWORD handle, void *buffer, DWORD length );
handle | The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. | ||||||||||||||||||||||||||||||||
buffer | Pointer to a buffer to receive the data... can be NULL when handle is a recording channel (HRECORD), to discard the requested amount of data from the recording buffer. | ||||||||||||||||||||||||||||||||
length | Number of bytes wanted (up to 268435455 or 0xFFFFFFF), and/or the following flags.
|
BASS_ERROR_HANDLE | handle is not a valid channel. |
BASS_ERROR_ENDED | The channel has reached the end. |
BASS_ERROR_NOTAVAIL | The BASS_DATA_AVAILABLE flag cannot be used with a decoding channel. It is not possible to get data from final output mix streams (using STREAMPROC_DEVICE). |
BASS_ERROR_ILLPARAM | Invalid flags were used, eg. BASS_DATA_NOREMOVE on a non-recording channel. |
When requesting data from a decoding channel, data is decoded directly from the channel's source (no playback buffer) and as much data as the channel has available can be decoded at a time.
When retrieving sample data, 8-bit samples are unsigned (0 to 255), 16-bit samples are signed (-32768 to 32767), 32-bit floating-point samples range from -1 to +1 (not clipped, so can actually be outside this range). That is unless the BASS_DATA_FLOAT flag is used, in which case the sample data will be converted to 32-bit floating-point (if it is not already).
Unless complex data is requested via the BASS_DATA_FFT_COMPLEX flag, the magnitudes of the first half of an FFT result are returned. For example, with a 2048 sample FFT (BASS_DATA_FFT2048), there will be 1024 floating-point values returned. Each value, or "bin", ranges from 0 to 1 (can actually go higher if the sample data is floating-point and not clipped). The 1st bin contains the DC component, the 2nd contains the amplitude at 1/2048 of the channel's sample rate, followed by the amplitude at 2/2048, 3/2048, etc. A Hann window is applied to the sample data to reduce leakage, unless the BASS_DATA_FFT_NOWINDOW flag is used. When a window is applied, it causes the DC component to leak into the next bin, but that can be removed (reduced to 0) by using the BASS_DATA_FFT_REMOVEDC flag. Doing so slightly increases the processing required though, so it should only be done when needed, which is when a window is applied and the 2nd bin value is important.
Channels that have 2 or more sample channels (ie. stereo or above) may have FFT performed on each individual channel, using the BASS_DATA_FFT_INDIVIDUAL flag. Without this flag, all of the channels are combined, and a single mono FFT is performed. Performing the extra individual FFTs of course increases the amount of processing required. The return values are interleaved in the same order as the channel's sample data, eg. stereo = left,right,left,etc.
This function is most useful if you wish to visualize (eg. spectrum analyze) the sound.
float fft[512]; // fft data buffer BASS_ChannelGetData(channel, fft, BASS_DATA_FFT1024); for (int a = 0; a < 512; a++) printf("%d: %f\n", a, fft[a]);
Perform a 1024 sample FFT on a channel and list the complex result.
float fft[2048]; // fft data buffer BASS_ChannelGetData(channel, fft, BASS_DATA_FFT1024 | BASS_DATA_FFT_COMPLEX); for (int a = 0; a < 1024; a++) printf("%d: (%f, %f)\n", a, fft[a * 2], fft[a * 2 + 1]);