void hannWindowToolStripMenuItemClick(object sender, EventArgs e) { window = RaisedCosineWindow.Hann(2048); reset(); hannWindowToolStripMenuItem.Checked = true; }
public PitchShifterWithPhaseVocoder(int windowLength) { if (windowLength % 2 != 0) { throw new ArgumentException(); } this._windowLength = windowLength; this._window = RaisedCosineWindow.Hann(windowLength); this._fftBuffer = new Complex[windowLength]; this._magnitudeSpectrum = new double[windowLength]; this._phaseSpectrum = new double[windowLength]; this._modifiedMagnitudeSpectrum = new double[windowLength]; var omega = new double[windowLength]; for (var i = 0; i < omega.Length; i++) { omega[i] = 2.0 * Math.PI * (windowLength / 2.0) * i / windowLength; } this._omega = omega; this._lastPhase = new double[windowLength]; this._targetPhase = new double[windowLength]; this._inputBuffer = new float[windowLength / 2]; this._vocoderInputBuffer = new float[windowLength]; this._vocoderOutputBuffer = new float[windowLength]; this._nextOutputBuffer = new float[windowLength]; }
public Form1() { InitializeComponent(); redis = ConnectionMultiplexer.Connect("localhost,abortConnect=false"); deviceList = new Dictionary <string, ACT12x>(); for (int x = 0; x < checkedListBoxChannel.Items.Count; x++) { this.checkedListBoxChannel.SetItemChecked(x, false); } dataQueue = new ConcurrentQueue <DataValue>(); backgroundWorkerSaveData = new BackgroundWorker(); signalBuffer = new float[WindowSize]; backgroundWorkerSaveData.WorkerSupportsCancellation = true; backgroundWorkerSaveData.DoWork += BackgroundWorkerSaveData_DoWork; window = RaisedCosineWindow.Hann(WindowSize); LoadDevices(); vact = null; saveDataSuccess = false; isStarted = false; ToolStripMenuItemStart.Enabled = true; ToolStripMenuItemStop.Enabled = false; }
public VibrationACT12x(string id, string ip, int port, Chart chart, string deviceType, string path, string database, TextBox tb) { dataQueue = new ConcurrentQueue <float[]>(); uiQueue = new ConcurrentQueue <float[]>(); backgroundWorkerProcessData = new BackgroundWorker(); backgroundWorkerReceiveData = new BackgroundWorker(); backgroundWorkerUpdateUI = new BackgroundWorker(); backgroundWorkerProcessData.WorkerSupportsCancellation = true; backgroundWorkerProcessData.DoWork += BackgroundWorkerProcessData_DoWork; backgroundWorkerUpdateUI.WorkerSupportsCancellation = true; backgroundWorkerUpdateUI.DoWork += BackgroundWorkerUpdateUI_DoWork; backgroundWorkerReceiveData.WorkerSupportsCancellation = true; backgroundWorkerReceiveData.DoWork += BackgroundWorkerReceiveData_DoWork; window = RaisedCosineWindow.Hann(WindowSize); this.ip = ip; this.deviceId = id; this.deviceType = deviceType; this.udpPort = port; this.chart1 = chart; this.textBoxLog = tb; this.basePath = path; this.database = database; this.isUpdateChart = false; this.vibrateChannels = new Dictionary <int, string>(); LoadChannels(); }
public void RectangularWindowTest() { int length = 3; testWindow(length, RaisedCosineWindow.Rectangular(length)); testWindow(length, new RectangularWindow(length)); }
public MfccAccord(int sampleRate, int sampleCount, double lowerHz, double upperHz, int filterCount) { this.SampleRate = sampleRate; this.SampleCount = sampleCount; this.LowerHz = lowerHz; this.UpperHz = upperHz; this.FilterCount = filterCount; // 事前に計算しておけるもの this._windowFunc = RaisedCosineWindow.Hamming(sampleCount); this._melFilterbank = CreateMelFilterbank(sampleRate, sampleCount, lowerHz, upperHz, filterCount); }
public ACT1228CableForceV4(string id, string ip, string localIP, int port, Chart chart, string deviceType, string path, string database, TextBox tb, double threshold, ConnectionMultiplexer redis) { this.Tag = ip + " : "; dataQueue = new ConcurrentQueue <float[]>(); uiQueue = new ConcurrentQueue <float[]>(); rawQueue = new ConcurrentQueue <string>(); this.redis = redis; Threshold = threshold; backgroundWorkerProcessData = new BackgroundWorker(); backgroundWorkerReceiveData = new BackgroundWorker(); backgroundWorkerUpdateUI = new BackgroundWorker(); backgroundWorkerSaveRawData = new BackgroundWorker(); backgroundWorkerProcessData.WorkerSupportsCancellation = true; backgroundWorkerProcessData.DoWork += BackgroundWorkerProcessData_DoWork; backgroundWorkerUpdateUI.WorkerSupportsCancellation = true; backgroundWorkerUpdateUI.DoWork += BackgroundWorkerUpdateUI_DoWork; backgroundWorkerReceiveData.WorkerSupportsCancellation = true; backgroundWorkerReceiveData.DoWork += BackgroundWorkerReceiveData_DoWork; backgroundWorkerSaveRawData.WorkerSupportsCancellation = true; backgroundWorkerSaveRawData.DoWork += backgroundWorkerSaveRawData_DoWork; hourTimer = new System.Timers.Timer(1000 * 60 * 60 * 1); hourTimer.Elapsed += new System.Timers.ElapsedEventHandler(HourTimer_TimesUp); hourTimer.AutoReset = true; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true) minuteTimer = new System.Timers.Timer(1000 * 60 * 5); minuteTimer.Elapsed += new System.Timers.ElapsedEventHandler(MinuteTimer_TimesUp); minuteTimer.AutoReset = false; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true) window = RaisedCosineWindow.Hann(WindowSize); this.ip = ip; this.localIP = localIP; this.deviceId = id; this.deviceType = deviceType; this.udpPort = port; this.chart1 = chart; this.textBoxLog = tb; this.basePath = path; this.database = database; this.isUpdateChart = false; this.vibrateChannels = new Dictionary <int, VibrateChannel>(); db = redis.GetDatabase(); LoadChannels(); }
public void ComplexSignalConstructor() { UnmanagedMemoryStream sourceStream = Properties.Resources.Grand_Piano___Fazioli___major_A_middle; MemoryStream destinationStream = new MemoryStream(); // Create a decoder for the source stream WaveDecoder sourceDecoder = new WaveDecoder(sourceStream); // Decode the signal in the source stream Signal sourceSignal = sourceDecoder.Decode(); int length = (int)Math.Pow(2, 12); RaisedCosineWindow window = RaisedCosineWindow.Hamming(length); Assert.AreEqual(length, window.Length); Signal[] windows = sourceSignal.Split(window, 1024); Assert.AreEqual(windows.Length, 172); foreach (var w in windows) { Assert.AreEqual(length, w.Length); } ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal); for (int i = 0; i < complex.Length - 1; i++) { ComplexSignal c = complex[i]; Assert.AreEqual(2, c.Channels); Assert.AreEqual(92, c.Duration); Assert.AreEqual(4096, c.Length); Assert.AreEqual(SampleFormat.Format128BitComplex, c.SampleFormat); Assert.AreEqual(44100, c.SampleRate); Assert.AreEqual(ComplexSignalStatus.Normal, c.Status); } complex.ForwardFourierTransform(); for (int i = 0; i < complex.Length - 1; i++) { ComplexSignal c = complex[i]; Assert.AreEqual(ComplexSignalStatus.FourierTransformed, c.Status); } }
public void ComplexSignalConstructor() { var sourceStream = SignalTest.GetSignal("a.wav"); MemoryStream destinationStream = new MemoryStream(); // Create a decoder for the source stream WaveDecoder sourceDecoder = new WaveDecoder(sourceStream); // Decode the signal in the source stream Signal sourceSignal = sourceDecoder.Decode(); int length = (int)Math.Pow(2, 12); RaisedCosineWindow window = RaisedCosineWindow.Hamming(length); Assert.AreEqual(length, window.Length); Signal[] windows = sourceSignal.Split(window, 1024); Assert.AreEqual(windows.Length, 172); foreach (var w in windows) { Assert.AreEqual(length, w.Length); } ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal); for (int i = 0; i < complex.Length - 1; i++) { ComplexSignal c = complex[i]; Assert.AreEqual(2, c.Channels); Assert.AreEqual(93, c.Duration.TotalMilliseconds); Assert.AreEqual(4096, c.Length); Assert.AreEqual(SampleFormat.Format128BitComplex, c.SampleFormat); Assert.AreEqual(44100, c.SampleRate); Assert.AreEqual(ComplexSignalStatus.Normal, c.Status); } complex.ForwardFourierTransform(); for (int i = 0; i < complex.Length - 1; i++) { ComplexSignal c = complex[i]; Assert.AreEqual(ComplexSignalStatus.FourierTransformed, c.Status); } }
public PitchShifterWithStft(int windowLength) { if (windowLength % 2 != 0) { throw new ArgumentException(); } this._windowLength = windowLength; this._window = RaisedCosineWindow.Hann(windowLength); this._fftBuffer = new Complex[windowLength]; this._modifiedSpectrum = new Complex[windowLength]; this._inputBuffer = new float[windowLength / 2]; this._fftInputBuffer = new float[windowLength]; this._fftOutputBuffer = new float[windowLength]; this._nextOutputBuffer = new float[windowLength]; }
public void SetDirectoryPaths(string folderPath) { audioFileName = Directory.GetFiles(folderPath, "*.wav").Select(Path.GetFileName).OrderBy(r => r.Length).ToArray(); for (int i = 0; i < audioFileName.Length; i++) { string fileName = audioFileName[i]; WaveDecoder sourceWD = new WaveDecoder(fileName); Signal sourceS = sourceWD.Decode(); RaisedCosineWindow window = RaisedCosineWindow.Hamming(1024); Signal[] windows = sourceS.Split(window, 512); ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal); complex.ForwardFourierTransform(); } }
void Button1Click(object sender, EventArgs e) { AudioDeviceInfo info = comboBox1.SelectedItem as AudioDeviceInfo; if (info == null) { MessageBox.Show("No audio devices available."); return; } source = new AudioCaptureDevice(info.Guid); source.DesiredFrameSize = 2048; source.SampleRate = 22050; source.NewFrame += source_NewFrame; source.AudioSourceError += source_AudioSourceError; window = RaisedCosineWindow.Hamming(source.DesiredFrameSize); source.Start(); }
public Form1() { InitializeComponent(); deviceList = new Dictionary <string, VibrationACT12x>(); for (int x = 0; x < checkedListBoxChannel.Items.Count; x++) { this.checkedListBoxChannel.SetItemChecked(x, false); } dataQueue = new ConcurrentQueue <float[]>(); uiQueue = new ConcurrentQueue <float[]>(); backgroundWorkerProcessData = new BackgroundWorker(); backgroundWorkerReceiveData = new BackgroundWorker(); backgroundWorkerUpdateUI = new BackgroundWorker(); signalBuffer = new float[WindowSize]; backgroundWorkerProcessData.WorkerSupportsCancellation = true; backgroundWorkerProcessData.DoWork += BackgroundWorkerProcessData_DoWork; backgroundWorkerUpdateUI.WorkerSupportsCancellation = true; backgroundWorkerUpdateUI.DoWork += BackgroundWorkerUpdateUI_DoWork; backgroundWorkerReceiveData.WorkerSupportsCancellation = true; backgroundWorkerReceiveData.DoWork += BackgroundWorkerReceiveData_DoWork; window = RaisedCosineWindow.Hann(WindowSize); LoadDevices(); vact = null; //Set series chart type //chart1.Series["Series1"].ChartType = SeriesChartType.Line; //chart2.Series["Series1"].ChartType = SeriesChartType.Line; //chart1.Series["Series1"].IsValueShownAsLabel = true; }
/// <summary> /// Splits a signal using a window /// </summary> /// /// <param name="signal">The signal to be splitted into windows.</param> /// <param name="step">The step size, in number of frames.</param> /// <param name="windowSize">The size of the window (in frames) when splitting the signal.</param> /// public static Signal[] Split(this Signal signal, int windowSize, int step) { return(signal.Split(RaisedCosineWindow.Rectangular(windowSize), step)); }
/// <summary> /// Initializes a new instance of the <see cref="MFCC" /> class. /// </summary> /// /// <param name="filterCount">The filter count.</param> /// <param name="cepstrumCount">The cepstrum count.</param> /// <param name="lowerFrequency">The lower frequency.</param> /// <param name="upperFrequency">The upper frequency.</param> /// <param name="alpha">The alpha.</param> /// <param name="samplingRate">The sampling rate.</param> /// <param name="frameRate">The frame rate.</param> /// <param name="windowLength">Length of the window.</param> /// <param name="numberOfBins">The number of bins.</param> /// public MelFrequencyCepstrumCoefficient( int filterCount = 40, int cepstrumCount = 13, double lowerFrequency = 133.3333, double upperFrequency = 6855.4976, double alpha = 0.97, int samplingRate = 16000, int frameRate = 100, double windowLength = 0.0256, int numberOfBins = 512 ) { base.SupportedFormats.UnionWith(new[] { SampleFormat.Format32BitIeeeFloat }); m_lowerf = lowerFrequency; m_upperf = upperFrequency; m_nfft = numberOfBins; m_ncep = cepstrumCount; m_nfilt = filterCount; m_frate = frameRate; m_fshift = (float)samplingRate / frameRate; m_samplingRate = samplingRate; m_windowLength = windowLength; // Build Hamming window m_wlen = (int)(windowLength * samplingRate); m_win = RaisedCosineWindow.Hamming(m_wlen); // Prior sample for pre-emphasis m_prior = 0; m_alpha = alpha; // Build mel filter matrix m_filters = new double[numberOfBins / 2 + 1, filterCount]; float w_dfreq = (float)samplingRate / (float)numberOfBins; if (upperFrequency > samplingRate / 2) { throw new Exception("Upper frequency exceeds Nyquist"); } double w_melmax = mel(upperFrequency); double w_melmin = mel(lowerFrequency); double w_dmelbw = (w_melmax - w_melmin) / (filterCount + 1); // Filter edges, in Hz double[] w_filt_edge = new double[filterCount + 2]; for (double w_i = 0; w_i < filterCount + 2; w_i += 1.0) { w_filt_edge[(int)w_i] = w_melmin + w_dmelbw * w_i; } w_filt_edge = melinv(w_filt_edge); for (int w_whichfilt = 0; w_whichfilt < filterCount; w_whichfilt++) { // Filter triangles, in DFT points int w_leftfr = (int)System.Math.Round(w_filt_edge[w_whichfilt] / w_dfreq); int w_centerfr = (int)System.Math.Round(w_filt_edge[w_whichfilt + 1] / w_dfreq); int w_rightfr = (int)System.Math.Round(w_filt_edge[w_whichfilt + 2] / w_dfreq); // For some reason this is calculated in Hz, though I think it doesn't really matter double w_fwidth = (w_rightfr - w_leftfr) * w_dfreq; double w_height = 2.0 / w_fwidth; double w_leftslope = 0; if (w_centerfr != w_leftfr) { w_leftslope = w_height / (w_centerfr - w_leftfr); } int w_freq = w_leftfr + 1; while (w_freq < w_centerfr) { m_filters[w_freq, w_whichfilt] = (w_freq - w_leftfr) * w_leftslope; w_freq = w_freq + 1; } if (w_freq == w_centerfr) // This is always true { m_filters[w_freq, w_whichfilt] = w_height; w_freq = w_freq + 1; } double w_rightslope = 0; if (w_centerfr != w_rightfr) { w_rightslope = w_height / (w_centerfr - w_rightfr); } while (w_freq < w_rightfr) { m_filters[w_freq, w_whichfilt] = (w_freq - w_rightfr) * w_rightslope; w_freq = w_freq + 1; } } // Build DCT matrix m_s2dct = s2dctmat(filterCount, cepstrumCount, 1.0 / filterCount); m_dst = dctmat(filterCount, cepstrumCount, System.Math.PI / filterCount); }