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); } }
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)); }
internal void Disconnect() { if (waveOutWindow != null) { waveOutWindow.Close(); waveOutWindow = null; } if (waveOutWindowNative != null) { waveOutWindowNative.ReleaseHandle(); waveOutWindowNative = null; } }