Author Topic: Question about changing sample rate  (Read 293 times)

JemmyLoveJenny

  • Guest
Question about changing sample rate
« on: 20 Oct '18 - 17:29 »
BASS_ChannelGetData calculates the FFT data of the channel
One factor that affects the result is the sample rate, however, I didn't find where I can set the sample rate.
It seems that Bass library use the sample rate of the file by default, but I want to set the sample rate of FFT by myself.
How can I achieve that? Thank you.

JemmyLoveJenny

  • Guest
Re: Question about changing sample rate
« Reply #1 on: 20 Oct '18 - 17:36 »
And I've tried BASS_ChannelSetAttribute with BASS_ATTRIB_FREQ
This doesn't seem to work! It only affects the playback of the channel but not the decoding channel

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: Question about changing sample rate
« Reply #2 on: 22 Oct '18 - 15:37 »
To minimize latency, the BASS_ATTRIB_FREQ setting (BASS_ATTRIB_PAN/VOL too) isn't applied when when the sample data is decoded but rather when the final mix is generated for the output device. BASS_ChannelGetData deals with the decoded data. But with FFT data, it's actually quite simple to adjust for the BASS_ATTRIB_FREQ setting; you can use that setting instead of the original rate in your FFT bin frequency calculations, like this:

Code: [Select]
float freq;
BASS_ChannelGetAttribute(handle, BASS_ATTRIB_FREQ, &freq);
float binfreq = freq * bin / fftsize;

JemmyLoveJenny

  • Guest
Re: Question about changing sample rate
« Reply #3 on: 3 Nov '18 - 09:12 »
To minimize latency, the BASS_ATTRIB_FREQ setting (BASS_ATTRIB_PAN/VOL too) isn't applied when when the sample data is decoded but rather when the final mix is generated for the output device. BASS_ChannelGetData deals with the decoded data. But with FFT data, it's actually quite simple to adjust for the BASS_ATTRIB_FREQ setting; you can use that setting instead of the original rate in your FFT bin frequency calculations, like this:

Code: [Select]
float freq;
BASS_ChannelGetAttribute(handle, BASS_ATTRIB_FREQ, &freq);
float binfreq = freq * bin / fftsize;
Thank you very much! It works!
However, it seems the interval/accurancy (the spectrum's x coord interval) of the FFT Data differs on the music files's sample rate. How can I have the X coord interval be the same? If I use higher fft size, the FFT calculation may be much slower...and it seems impossible to only calculate FFT data of certain frequency range?