示例#1
0
 /**
  * Dispatch the filtered sample to all registered listeners
  */
 private void send(float sample)
 {
     if (mListener != null)
     {
         mListener.receive(sample);
     }
 }
示例#2
0
        public void receive(float sample)
        {
            if (mListener != null)
            {
                mListener.receive(sample);
            }

            foreach (TapListener <float> listener in mListeners)
            {
                listener.receive(sample);
            }
        }
示例#3
0
        /**
         * Calculate the filtered value by applying the coefficients against
         * the complex samples in mBuffer
         */
        public void receive(float newSample)
        {
            //Add the new sample to the buffer
            mBuffer[mBufferPointer] = newSample;

            //Increment & Adjust the buffer pointer for circular wrap around
            mBufferPointer++;

            if (mBufferPointer >= mBufferSize)
            {
                mBufferPointer = 0;
            }

            //Toggle the flag every time, so that we can calculate and dispatch a
            //sample every other time, when the flag is true (ie decimate by 2)
            mDispatchFlag = !mDispatchFlag;

            //Calculate a filtered sample when the flag is true
            if (mDispatchFlag)
            {
                //Convolution - multiply filter coefficients by the circular buffer
                //samples to calculate a new filtered value
                double accumulator = 0;

                //Start with the center tap value
                accumulator += mCoefficients[mCenterCoefficient] * mBuffer[mIndexMap[mBufferPointer][mCenterCoefficientMapIndex]];

                //For the remaining coefficients, add the symmetric samples, oldest and newest
                //first, then multiply by the single coefficient
                for (int x = 0; x < mCenterCoefficientMapIndex; x += 2)
                {
                    accumulator += mCoefficients[x] *
                                   (mBuffer[mIndexMap[mBufferPointer][x]] +
                                    mBuffer[mIndexMap[mBufferPointer][x + 1]]);
                }

                //We're almost finished ... apply gain, cast the doubles to shorts and
                //send it on it's merry way
                if (mListener != null)
                {
                    mListener.receive((float)(accumulator * mGain));
                }
            }
        }