Пример #1
0
 internal void Connect(WaveInterop.WaveCallback callback)
 {
     if (Strategy == WaveCallbackStrategy.NewWindow)
     {
         waveOutWindow = new WaveWindow(callback);
         waveOutWindow.CreateControl();
         this.Handle = waveOutWindow.Handle;
     }
     else if (Strategy == WaveCallbackStrategy.ExistingWindow)
     {
         waveOutWindowNative = new WaveWindowNative(callback);
         waveOutWindowNative.AssignHandle(this.Handle);
     }
 }
Пример #2
0
        public static IWave GetFilterWave(IFilter filterType, decimal sampleRate, WindowDelegate windowFunction)
        {
            WaveWindow window = new WaveWindow(windowFunction, filterType.Length);
            double     k      = filterType.GetKCoefficient(sampleRate, filterType.CutoffFrequency);

            double[] values = new double[filterType.Length];

            int    halfFilterLength = (filterType.Length - 1) / 2;
            double twoPi            = 2 * Math.PI;

            for (int i = 0; i < filterType.Length; i++)
            {
                if (i == halfFilterLength)
                {
                    values[i] = 2.0 / k;
                }
                else
                {
                    values[i] = Math.Sin(twoPi * (i - halfFilterLength) / k) / (Math.PI * (i - halfFilterLength));
                }
                values[i] *= filterType.GetValue(i - halfFilterLength) * window[i];
            }
            return(new Wave(values, 1 / sampleRate));
        }
Пример #3
0
 internal void Disconnect()
 {
     if (waveOutWindow != null)
     {
         waveOutWindow.Close();
         waveOutWindow = null;
     }
     if (waveOutWindowNative != null)
     {
         waveOutWindowNative.ReleaseHandle();
         waveOutWindowNative = null;
     }
 }