GAudio.GATData.ResampleCopyFrom C# (CSharp) Method

ResampleCopyFrom() public method

Performs a resampled copy from an array to the GATData instance it is called on. The resampling algorithm performs naive linear interpolation.
public ResampleCopyFrom ( float sourceArray, double trueInterpolatedIndex, int targetLength, int targetOffset, double resamplingFactor ) : double
sourceArray float
trueInterpolatedIndex double
targetLength int
targetOffset int
resamplingFactor double
return double
        public double ResampleCopyFrom( float[] sourceArray, double trueInterpolatedIndex, int targetLength, int targetOffset, double resamplingFactor )
        {
            int sourceIndex;
            int destinationIndex = _offset + targetOffset;
            targetLength += destinationIndex;

            float sourceValue;

            double interpolation;

            while( destinationIndex < targetLength )
            {
                sourceIndex = ( int )trueInterpolatedIndex;
                interpolation = trueInterpolatedIndex - ( double )sourceIndex;
                sourceValue = sourceArray[ sourceIndex ];

                _parentArray[ destinationIndex ] = sourceValue + ( sourceArray[ sourceIndex + 1 ] - sourceValue ) * ( float )interpolation;

                destinationIndex++;
                trueInterpolatedIndex += resamplingFactor;
            }

            return trueInterpolatedIndex;
        }

Usage Example

Esempio n. 1
0
        public int GetResampledData(GATData target, int targetLength, int offsetInTarget, double pitch)
        {
            double dLastIndex = _nextIndex + pitch * (targetLength - 1);
            int    iLastIndex = ( int )dLastIndex;;
            int    sign       = System.Math.Sign(pitch);

            if (dLastIndex - ( double )iLastIndex > 0d)
            {
                iLastIndex += sign;
            }

            if (iLastIndex >= _data.Count - 1)
            {
                targetLength = ( int )((( double )(_data.Count - 1) - _nextIndex) / pitch);
                target.ResampleCopyFrom(_data.ParentArray, _nextIndex + ( double )_data.MemOffset, targetLength, offsetInTarget, pitch);

                return(targetLength);
            }
            else if (iLastIndex < 0)
            {
                targetLength = -( int )((_nextIndex - 1d) / pitch) + 1;

                target.ResampleCopyFrom(_data.ParentArray, _nextIndex + ( double )_data.MemOffset, targetLength, offsetInTarget, pitch);

                return(targetLength);
            }
            else
            {
                target.ResampleCopyFrom(_data.ParentArray, _nextIndex + ( double )_data.MemOffset, targetLength, offsetInTarget, pitch);
                _nextIndex = dLastIndex + pitch;
                return(targetLength);
            }
        }
All Usage Examples Of GAudio.GATData::ResampleCopyFrom