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; }
public void TagCache() { if (HiyobiTags.Tags == null) { HiyobiTags.LoadTags(); } try { List <Hitomi.HTag> tags = HiyobiTags.Tags; Dispatcher patcher = Global.dispatcher; ProgressBox progressBox = null; patcher.Invoke(() => { progressBox = new ProgressBox(); progressBox.Title = "태그 캐시 다운로드"; progressBox.Show(); progressBox.ProgressBar.Maximum = tags.Count; }); for (int i = 0; i < tags.Count; i++) { Hitomi.HTag tag = tags[i]; Thread th = new Thread(new ThreadStart(async() => { try { string dir = Path.Combine(rootDir, tag.type.ToString()); string file = Path.Combine(dir, tag.tag + ".json"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (File.Exists(file)) { //patcher.Invoke(() => progressBox.ProgressBar.Value++); return; } InternetP parser = new InternetP(); int[] ids = parser.ByteArrayToIntArrayBig(await parser.LoadNozomiTag(tag.type.ToString(), tag.tag, false, 0, 9999)); JArray arr = JArray.FromObject(ids); File.WriteAllText(file, arr.ToString()); Console.WriteLine("{0}/{1}: {2}", i, tags.Count, tag.full); } catch (IOException) { Console.WriteLine("Faild {0}/{1}: {2}", i, tags.Count, tag.full); } catch (Exception ex) { Console.WriteLine("Error {0} : {1}", tag.full, ex.Message); } finally { patcher.Invoke(() => { progressBox.ProgressBar.Value++; if (progressBox.ProgressBar.Value == progressBox.ProgressBar.Maximum) { progressBox.Close(); MessageBox.Show("캐시 다운로드가 끝났습니다."); } }); } })); th.Start(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }