Author Topic: Performing an FTT on a certain file chunk  (Read 2918 times)

zydu

  • Posts: 14
Performing an FTT on a certain file chunk
« on: 30 Mar '08 - 13:09 »
Hello

I am trying to go throught a .WAV file analyze it part by part (get an FTT) without having to wait for it to play. .How can I finish this task?

So far I wrote this code :

int sample = Bass.BASS_SampleLoad(_fileName, 0, 0, 1, BASSSample.BASS_SAMPLE_MONO);
if (sample != 0)
             {
                    int channel = Bass.BASS_SampleGetChannel(sample, false);
                    Bass.BASS_ChannelSetPosition(channel, 15.20f);
                    //Bass.BASS_ChannelPlay(channel, false);    //playing from a certain position works perfectly
                    int fourier = Bass.BASS_ChannelGetData(channel, ref bufor[0], (int)BASSData.BASS_DATA_FFT4096)
                   
                }

Last line doesn't copy anything new to the "bufor". Can I use BASS_ChannelGetData function here? Please help.

Regards

Mike

chinajuanbob

  • Posts: 22
Re: Performing an FTT on a certain file chunk
« Reply #1 on: 30 Mar '08 - 14:13 »
Un4seen.Bass.Bass.BASS_ChannelGetData(stream, ref buffer, (int)BASSData.BASS_DATA_FFT4096 ) ?

zydu

  • Posts: 14
Re: Performing an FTT on a certain file chunk
« Reply #2 on: 30 Mar '08 - 14:28 »
Un4seen.Bass.Bass.BASS_ChannelGetData(stream, ref buffer, (int)BASSData.BASS_DATA_FFT4096 ) ?

Don't know exactly what you mean but line :

int wynik = Bass.BASS_ChannelGetData(channel, ref bufor[0], (int)BASSData.BASS_DATA_FFT4096);

normally works when placed in a callback function when workin with recording stream. It doesn't work here maybe because it is a sample - I don't really know.

Maybe my question should be "can I only perform FTT inside callback function, in real time when a sound is being played/recorded". What I am trying to do is use some advanced algorithms for note detection which probably cannot be finished in small amounts of time (between two subseqent calls of to the callback function). Also I need to be able to get FTT of chunks of VARIOUS length, starting at different positions.

Regards

Mike

Ian @ un4seen

  • Administrator
  • Posts: 21372
Re: Performing an FTT on a certain file chunk
« Reply #3 on: 30 Mar '08 - 17:16 »
I'm afraid BASS_ChannelGetData can't be used on samples. It sounds like what you want is a decoding channel. For example, something like this...

Code: [Select]
HSTREAM channel=BASS_StreamCreateFile(FALSE, filename, 0, 0, BASS_SAMPLE_MONO|BASS_STREAM_DECODE); // create decoding channel

BASS_ChannelSetPosition(channel, BASS_ChannelSeconds2Bytes(channel, 15.20f)); // seek to 15.2s
BASS_ChannelGetData(channel, fftbuf, BASS_DATA_FFT4096); // perform FFT at that position

zydu

  • Posts: 14
Re: Performing an FTT on a certain file chunk
« Reply #4 on: 1 Apr '08 - 17:16 »
This is exactly what I need. Thanks a lot.

Still I got some questions :

1. I work with 16bit,44kHz, Mono stream. When I request an X-point FFT,  4*X bytes are read from the stream, can I use more bytes from the stream to get better results ? (lets say I know theres a note starting at 1.0s and finishing at 1.5s and I would like to take all the bytes in this range into consideration).

2. If I move to a certain position in a stream and call BASS_ChannelGetLevel(stream) function, on how many samples will the result be based?

Regards

Mike

Ian @ un4seen

  • Administrator
  • Posts: 21372
Re: Performing an FTT on a certain file chunk
« Reply #5 on: 2 Apr '08 - 17:01 »
1. I work with 16bit,44kHz, Mono stream. When I request an X-point FFT,  4*X bytes are read from the stream, can I use more bytes from the stream to get better results ? (lets say I know theres a note starting at 1.0s and finishing at 1.5s and I would like to take all the bytes in this range into consideration).

A single BASS_ChannelGetData call will only take as much data as it needs to perform the FFT, but if you want to include a larger span of data, you could use multiple calls and combine the results of them, eg. take the peaks.

2. If I move to a certain position in a stream and call BASS_ChannelGetLevel(stream) function, on how many samples will the result be based?

BASS_ChannelGetLevel will use 20ms worth of data.