Example #1
0
        /// <summary>
        /// Calculates the Fast Fourier Transform and stores the result in the <paramref name="fftResultBuffer"/>.
        /// </summary>
        /// <param name="fftResultBuffer">The output buffer.</param>
        /// <returns>Returns a value which indicates whether the Fast Fourier Transform got calculated. If there have not been added any new samples since the last transform, the FFT won't be calculated. True means that the Fast Fourier Transform got calculated.</returns>
        public virtual bool GetFftData(Complex[] fftResultBuffer)
        {
            if (fftResultBuffer == null)
            {
                throw new ArgumentNullException("fftResultBuffer");
            }

            var input = fftResultBuffer;

            //copy from block [offset - end] to input buffer
            Array.Copy(_storedSamples, _currentSampleOffset, input, 0, _storedSamples.Length - _currentSampleOffset);
            //copy from block [0 - offset] to input buffer
            Array.Copy(_storedSamples, 0, input, _storedSamples.Length - _currentSampleOffset, _currentSampleOffset);

            for (int i = 0; i < input.Length; i++)
            {
                input[i].Real *= WindowFunction(i, input.Length);
            }

            FastFourierTransformation.Fft(input, _fftSizeExponent);
            var result = _newDataAvailable;

            _newDataAvailable = false;

            return(result);
        }
Example #2
0
 protected virtual void RaiseFFTCalculated(Complex[] complex)
 {
     FastFourierTransformation.FFT1(complex, (int)Math.Log(_bandCount, 2.0), FFTMode.Forward);
     if (FFTCalculated != null)
     {
         FFTCalculated(this, new FFTCalculatedEventArgs(complex));
     }
 }
Example #3
0
        /// <summary>
        /// Calculates the Fast Fourier Transform and stores the result in the <paramref name="fftResultBuffer"/>.
        /// </summary>
        /// <param name="fftResultBuffer">The output buffer.</param>
        /// <returns>Returns a value which indicates whether the Fast Fourier Transform got calculated. If there have not been added any new samples since the last transform, the FFT won't be calculated. True means that the Fast Fourier Transform got calculated.</returns>
        public virtual bool GetFftData(Complex[] fftResultBuffer)
        {
            if (fftResultBuffer == null)
            {
                throw new ArgumentNullException("fftResultBuffer");
            }

            var input = fftResultBuffer;

            Array.Copy(_storedSamples, input, _storedSamples.Length);

            FastFourierTransformation.Fft(input, _fftSizeExponent);
            var result = _newDataAvailable;

            _newDataAvailable = false;

            return(result);
        }
Example #4
0
        /// <summary>
        /// Calculates the Fast Fourier Transform and stores the result in the <paramref name="fftResultBuffer"/>.
        /// </summary>
        /// <param name="fftResultBuffer">The output buffer.</param>
        /// <returns>Returns a value which indicates whether the Fast Fourier Transform got calculated. If there have not been added any new samples since the last transform, the FFT won't be calculated. True means that the Fast Fourier Transform got calculated.</returns>
        public virtual bool GetFftData(Complex[] fftResultBuffer)
        {
            if (fftResultBuffer == null)
            {
                throw new ArgumentNullException("fftResultBuffer");
            }

            if (fftResultBuffer.Length < (int)_fftSize)
            {
                throw new ArgumentException("Length of array must be at least as long as the specified fft size.", "fftResultBuffer");
            }

            var  input = fftResultBuffer;
            bool result;

            lock (_lockObject)
            {
                //copy from block [offset - end] to input buffer
                Array.Copy(_storedSamples, _currentSampleOffset, input, 0,
                           _storedSamples.Length - _currentSampleOffset);
                //copy from block [0 - offset] to input buffer
                Array.Copy(_storedSamples, 0, input, _storedSamples.Length - _currentSampleOffset,
                           _currentSampleOffset);

                for (int i = 0; i < input.Length; i++)
                {
                    input[i].Real *= WindowFunction(i, input.Length);
                }

                result            = _newDataAvailable;
                _newDataAvailable = false;
            }

            FastFourierTransformation.Fft(input, _fftSizeExponent);

            return(result);
        }
Example #5
0
        public override unsafe int Read(byte[] buffer, int offset, int count)
        {
            int read = base.Read(buffer, offset, count);

            fixed(byte *pbuffer = buffer)
            {
                byte *ppbuffer = pbuffer;

                for (int i = 0; i < read / WaveFormat.BytesPerSample; i += WaveFormat.Channels)
                {
                    ppbuffer = pbuffer + (i + 1) * WaveFormat.BytesPerSample;
                    float sample = ConvertToSample(ppbuffer, WaveFormat.BitsPerSample, false, true);

                    Complex[_iteratorOffset++].Real = (float)(sample * FastFourierTransformation.HammingWindow(_iteratorOffset - 1, _bandCount));
                    if (_iteratorOffset >= BandCount)
                    {
                        RaiseFFTCalculated(Complex);
                        Reset();
                    }
                }
            }

            return(read);
        }