Пример #1
0
 private static void OperatorInnitEmptyWave(WaveChunk waveL, WaveChunk waveR, out WaveChunk newWave, out uint minNSamples)
 {
     if (waveL._sampleRate != waveR._sampleRate)
     {
         throw new ArgumentException("Waves have different sampling rates");
     }
     newWave     = waveL.NumSamples > waveR.NumSamples ? new WaveChunk(waveL._sampleRate, waveL.NumSamples) : new WaveChunk(waveR._sampleRate, waveR.NumSamples);
     minNSamples = Math.Min(waveL.NumSamples, waveR.NumSamples);
 }
Пример #2
0
        private static void OperatorInnitCopyWave(WaveChunk waveL, WaveChunk waveR, out WaveChunk newWave, out WaveChunk smallerWave)
        {
            if (waveL._sampleRate != waveR._sampleRate)
            {
                throw new ArgumentException("Waves have different sampling rates");
            }

            newWave     = waveL.NumSamples > waveR.NumSamples ? new WaveChunk(waveL) : new WaveChunk(waveR);
            smallerWave = waveL.NumSamples > waveR.NumSamples ? waveR : waveL;
        }
Пример #3
0
        public static WaveChunk operator*(WaveChunk wave, float mult)
        {
            WaveChunk retWave = new WaveChunk(wave);

            for (uint i = 0; i < wave.NumSamples; i++)
            {
                retWave[i] *= mult;
            }

            return(retWave);
        }
Пример #4
0
        static private WaveChunk MakeSquareWave(WaveAttributes waveAttributes)
        {
            WaveChunk wave     = MakeSineWave(waveAttributes);
            uint      nSamples = wave.NumSamples;

            for (uint i = 0; i < nSamples; i++)
            {
                wave[i] = Math.Sign(wave[i]);
            }

            return(wave);
        }
Пример #5
0
        static public short[] Get16BitArray(WaveChunk wave)
        {
            ulong nSamples = wave.NumSamples;

            short[] arr = new short[nSamples];

            for (uint i = 0; i < nSamples; i++)
            {
                arr[i] = (short)(wave[i] * short.MaxValue);
            }

            return(arr);
        }
Пример #6
0
        static private WaveChunk MakeWhiteNoise(WaveAttributes waveAttr)
        {
            WaveChunk wave       = new WaveChunk(waveAttr.WaveSampleRate, waveAttr.Runtime);
            uint      numSamples = wave.NumSamples;

            Random random = new Random();

            for (uint i = 0; i < numSamples; i++)
            {
                wave[i] = (float)(2 * random.NextDouble() - 1);
            }

            return(wave);
        }
Пример #7
0
        static private WaveChunk MakeSineWave(WaveAttributes waveAttributes)
        {
            WaveChunk wave = new WaveChunk(waveAttributes.WaveSampleRate, waveAttributes.Runtime);

            uint numSamples = wave.NumSamples;

            double t = (Math.PI * 2 * waveAttributes.TargetFrequency) / (uint)waveAttributes.WaveSampleRate;

            for (uint i = 0; i < numSamples; i++)
            {
                wave[i] = (float)Math.Sin(t * i);
            }

            return(wave);
        }
Пример #8
0
        private static WaveChunk MakeTriangle(WaveAttributes waveAttr)
        {
            WaveChunk wave       = new WaveChunk(waveAttr.WaveSampleRate, waveAttr.Runtime);
            uint      numSamples = wave.NumSamples;

            float step = (float)(1 / (double)waveAttr.WaveSampleRate * 4 * waveAttr.TargetFrequency);

            wave[0] = 0.0f;
            for (uint i = 1; i < numSamples; i++)
            {
                var next = wave[i - 1] + step;
                if (Math.Abs(next) > 1.0f)
                {
                    step = -step;
                }

                wave[i] = wave[i - 1] + step;
            }
            return(wave);
        }
Пример #9
0
        private static WaveChunk MakeSawtooth(WaveAttributes waveAttr)
        {
            WaveChunk wave       = new WaveChunk(waveAttr.WaveSampleRate, waveAttr.Runtime);
            uint      numSamples = wave.NumSamples;

            var step = 1 / (double)waveAttr.WaveSampleRate * 2 * waveAttr.TargetFrequency;

            wave[0] = 0.0f;
            for (uint i = 1; i < numSamples; i++)
            {
                var next = wave[i - 1] + (float)step;
                if (next > 1.0f)
                {
                    wave[i] = -1.0f;
                }
                else
                {
                    wave[i] = next;
                }
            }
            return(wave);
        }
Пример #10
0
 public WaveChunk(WaveChunk wave) : this(wave._sampleRate, wave.NumSamples)
 {
     wave._data.CopyTo(this._data, 0u);
 }