GAudio.GATMaths.ClampedResampledLength C# (CSharp) Méthode

ClampedResampledLength() public static méthode

public static ClampedResampledLength ( int sourceLength, int targetLength, double resamplingFactor ) : int
sourceLength int
targetLength int
resamplingFactor double
Résultat int
        public static int ClampedResampledLength( int sourceLength, int targetLength, double resamplingFactor )
        {
            int neededSamples = ( int ) ( targetLength * resamplingFactor );
            if( sourceLength < neededSamples )
            {
                targetLength = ( int ) ( sourceLength / resamplingFactor );
            }

            return targetLength;
        }

Usage Example

Exemple #1
0
        protected void FillWithResampledData(GATData sourceData, GATData targetData, int fromIndex, int targetLength, double pitch)
        {
            //check that we have enough samples to fulfill the request:
            int appliedLength = GATMaths.ClampedResampledLength(sourceData.Count - fromIndex, targetLength, pitch);

            if (appliedLength < 0)
            {
                                #if GAT_DEBUG
                Debug.LogWarning("requested offset is out of bounds.");
                                #endif
                return;
            }

            sourceData.ResampleCopyTo(fromIndex, targetData, appliedLength, pitch);

            //if we did not have enough samples, clear the rest:
            if (appliedLength < targetLength)
            {
                targetData.Clear(appliedLength, targetData.Count - appliedLength);
            }
        }