public static double[] ETCToPTC(double[][] Octave_ETC, double CutOffTime, int sample_frequency_in, int sample_frequency_out, double Rho_C) { int length = 4096; double[] IR = new double[(int)Math.Floor(sample_frequency_out * CutOffTime) + (int)length]; double BW = (double)sample_frequency_out / (double)sample_frequency_in; //Convert to Pressure & Interpolate full resolution IR int ct = 0; System.Threading.Semaphore S = new System.Threading.Semaphore(0, 1); S.Release(1); double[] time = new double[(int)Math.Floor(sample_frequency_out * CutOffTime) + (int)length]; double dt = 1f/(float)sample_frequency_out; for (int i = 0; i < time.Length; i++) { time[i] = i * dt; } int proc = UI.PachydermAc_PlugIn.Instance.ProcessorSpec(); double[][] output = new double[proc][]; double[][] samplep = new double[proc][]; System.Threading.Thread[] T = new System.Threading.Thread[proc]; int[] to = new int[proc]; int[] from = new int[proc]; System.Threading.CountdownEvent CDE = new System.Threading.CountdownEvent(Octave_ETC[0].Length); for (int p = 0; p < proc; p++) { output[p] = new double[length]; samplep[p] = new double[length * 2]; to[p] = p * Octave_ETC[0].Length / proc; from[p] = (p + 1) * Octave_ETC[0].Length / proc; T[p] = new System.Threading.Thread((thread) => { int thr = (int)thread; for (int t = to[thr]; t < from[thr]; t++) { ct++; double[] pr = new double[8]; for (int oct = 0; oct < 8; oct++) pr[oct] = Math.Sqrt(Octave_ETC[oct][t] * Rho_C); double sum = 0; foreach (double d in pr) sum += d; if (sum > 0) { output[thr] = Filter.Signal(pr, sample_frequency_out, 4096, thr); //Audio.Pach_SP.Raised_Cosine_Window(ref output[thr]); for (int k = 0; k < length; k++) { IR[(int)Math.Floor(t * BW) + k] += output[thr][k]; } } CDE.Signal(); } }); T[p].Start(p); } ProgressBox VB = new ProgressBox("Signal Production Progress"); VB.Show(); do { if (CDE.IsSet) { break; } VB.Populate((int)(100 * (1f - ((float)CDE.CurrentCount / (float)IR.Length)))); System.Threading.Thread.Sleep(500); } while (true); //CDE.Wait(); VB.Close(); return IR; }
void Worker_Completed(object sender, RunWorkerCompletedEventArgs e) { // hide the progress box progressBox.Close(); }