Esempio n. 1
0
        public static double[] ApplyDelay(double[] samples, WaveFormat fmt, int delayTime, DelayUnit delayUnit = DelayUnit.Milliseconds)
        {
            double[] result           = null;
            int      samplesPerSecond = fmt.SampleRate;
            long     arraySize        = samples.Length;

            switch (delayUnit)
            {
            case DelayUnit.Seconds:
                arraySize += delayTime * samplesPerSecond;
                break;

            case DelayUnit.Milliseconds:
                int seconds = delayTime / 1000;
                int millis  = delayTime % 1000;
                arraySize += seconds * samplesPerSecond;
                arraySize += (long)((millis / 1000.0) * samplesPerSecond);
                break;
            }

            result = new double[arraySize];
            Array.Copy(samples, result, samples.Length);

            int start     = 0;
            int beginning = 0;

            switch (delayUnit)
            {
            case DelayUnit.Milliseconds:
                start = (int)((delayTime / 1000.0) * samplesPerSecond);
                break;

            case DelayUnit.Seconds:
                start = delayTime * samplesPerSecond;
                break;
            }

            for (int i = start; i < result.Length; ++i)
            {
                try {
                    result[i] = MathUtils.Clamp(result[i] + samples[beginning++], -1.0, 1.0);
                } catch (IndexOutOfRangeException) {
                    Console.WriteLine("Caught exception.");
                }
            }

            return(result);
        }
Esempio n. 2
0
 public static double[] ApplyEcho(double[] samples, WaveFormat fmt, int delayBetweenRepeats, int repeats = 1, DelayUnit delayUnit = DelayUnit.Milliseconds)
 {
     throw new NotImplementedException();
 }