21 May '13 - 01:51 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Record - Data and FFT at the same time - buffer length in Samples  (Read 456 times)
TeXoR
Posts: 4


« on: 22 Apr '12 - 07:46 »
Reply with quoteQuote

Hi,

I would like to record and get the samples and the FFT where the length of the samples and the FFT should be equal all the time.

The first thing I tried was using the callback function but assigning a specific interval in ms leads in callbacks with big differences in the length of the new data.

The second thing I tried was manually pulling the data in a separate thread without any callback function. It's nice to get as many samples as I want to (e.g. 512 Samples) but I only can get it as normal samples exclusive or FFT data.
I read something about the push stream but it seems to be to slow. After I put samples to the push stream, I cannot directly read all of them.

Does anybody know any solution?
Logged
gnag
Posts: 160


« Reply #1 on: 22 Apr '12 - 18:49 »
Reply with quoteQuote

One PCM Sample does NOT equal one FFT Bin/Value, so you cannot get the "same" amount of Samples, you also Request FFT in a fixed Size like 1024,2048 etc.

If you want to not "loose" Data and Process after receiving samples from the Microphone, you can try to look at the following Quotes from the Code which was created when I was facing a simular situation with the Help of Ian from Bass Forums.
It has one Push Stream where data gets pushed to from the Recording Callback.


     
int  fftneed = fft_size * chans * 2;
  private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
        {
            int got = Bass.BASS_StreamPutData(fftstream, buffer, length); // feed the recorded data to the push stream

            while (got >= fftneed)
            {
                // got enough data to process
                float[] fft = new float[fft_size / 2];
                Bass.BASS_ChannelGetData(fftstream, fft, fft_size_const);
                // process the FFT data here
                ProcessFFT(fft);
                got -= fftneed;
            }

            return true;
        }

//FFT Stream
int fftstream = Bass.BASS_StreamCreate(_sampleRate, chans, BASSFlag.BASS_STREAM_DECODE, BASSStreamProc.STREAMPROC_PUSH); // create a push stream with same format as recording
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines