Ejemplo n.º 1
0
        static void Main()
        {
            //1.LearnTask
            //var taskTop = new Task(() =>
            //{
            //    Thread.Sleep(500);
            //    Console.WriteLine("任务taskTop运行在线程“{0}”上",
            //        Thread.CurrentThread.ManagedThreadId);
            //});
            //var taskMiddle = new Task(() =>
            //{
            //    Thread.Sleep(500);
            //    Console.WriteLine("任务taskMiddle运行在线程“{0}”上",
            //        Thread.CurrentThread.ManagedThreadId);
            //});
            //var taskBottom = new Task(() =>
            //{
            //    Thread.Sleep(500);
            //    Console.WriteLine("任务taskBottom运行在线程“{0}”上",
            //        Thread.CurrentThread.ManagedThreadId);
            //});
            //taskTop.Start();
            //taskMiddle.Start();
            //taskBottom.Start();
            //Task.WaitAll(new Task[] { taskTop, taskMiddle, taskBottom });

            //2. Compare Parllel to Task
            //ParallelDemo p = new ParallelDemo();

            //p.ParallelDemoRun();
            //3. Compare Parllel with For
            ParallelMethod p = new ParallelMethod();
            p.Method();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        private List<ParallelParameter> GenerateExpandFeatureCommands()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();
            foreach (string sid in FileMap.Map.Keys)
            {
                string basicFeaFile = FileMap.BuildPath(MergedFeaDir, sid, FileExtensions.Text);
                if (!File.Exists(basicFeaFile))
                {
                    Logger.LogLine("Fail to merge features for sentence {0}", sid);
                    continue;
                }

                string expandFeaFile = FileMap.BuildPath(ExpandFeaDir, sid, FileExtensions.Text);
                Helper.EnsureFolderExistForFile(expandFeaFile);

                string[] argument = { basicFeaFile, expandFeaFile, Dimension.ToString() };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = ExpandFeaturesOneFile,
                    Description = Helper.NeutralFormat("Get merged features for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }
Ejemplo n.º 3
0
        private List<ParallelParameter> GenerateFormatFeatureCommands()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();
            foreach (string sid in FileMap.Map.Keys)
            {
                string f0File = FileMap.BuildPath(F0Dir, sid, FileExtensions.F0File);
                if (!File.Exists(f0File))
                {
                    Logger.LogLine("Fail to get f0 file for sentence {0}", sid);
                    continue;
                }

                string expandFeaFile = FileMap.BuildPath(ExpandFeaDir, sid, FileExtensions.Text);
                if (!File.Exists(expandFeaFile))
                {
                    Logger.LogLine("Fail to get expanded feature file for sentence {0}", sid);
                    continue;
                }

                string svmFeaFile = FileMap.BuildPath(SvmFeaDir, sid, FileExtensions.Text);
                Helper.EnsureFolderExistForFile(svmFeaFile);

                string[] argument = { f0File, expandFeaFile, svmFeaFile };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = FormatFeaturesOneFile,
                    Description = Helper.NeutralFormat("Get format features for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }
Ejemplo n.º 4
0
        private List<ParallelParameter> GenerateMergeFeatureCommands()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();
            foreach (string sid in FileMap.Map.Keys)
            {
                string relatedfeaFile = FileMap.BuildPath(RealtedFeaDir, sid, FileExtensions.Text);
                if (!File.Exists(relatedfeaFile))
                {
                    Logger.LogLine("Fail to get related features for sentence {0}", sid);
                    continue;
                }

                string residualFile = FileMap.BuildPath(ResidualDir, sid, FileExtensions.Text);
                if (!File.Exists(residualFile))
                {
                    Logger.LogLine("Fail to get lpc residual features for sentence {0}", sid);
                    continue;
                }

                string nccfFile = FileMap.BuildPath(NccfDir, sid, FileExtensions.F0File);
                if (!File.Exists(nccfFile))
                {
                    Logger.LogLine("Fail to get nccf features for sentence {0}", sid);
                    continue;
                }

                string mergedFeaFile = FileMap.BuildPath(MergedFeaDir, sid, FileExtensions.Text);
                Helper.EnsureFolderExistForFile(mergedFeaFile);

                string[] argument = { relatedfeaFile, residualFile, nccfFile, mergedFeaFile };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = MergeFeaturesOneFile,
                    Description = Helper.NeutralFormat("Get merged features for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }
Ejemplo n.º 5
0
        private List<ParallelParameter> GenerateExtractLpcResidualErrorCommands()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();

            // extract direct features from wave
            foreach (string sid in FileMap.Map.Keys)
            {
                // process one wave file
                string waveFile = FileMap.BuildPath(WaveDir, sid, FileExtensions.Waveform);
                string lpcFile = FileMap.BuildPath(LPCDir, sid, FileExtensions.LpcFile);
                if (!File.Exists(lpcFile))
                {
                    Logger.LogLine("Fail to get lpc for sentence {0}", sid);
                    continue;
                }

                string errorFile = FileMap.BuildPath(ResidualDir, sid, FileExtensions.Text);
                Helper.EnsureFolderExistForFile(errorFile);

                string[] argument = { waveFile, lpcFile, errorFile, FrameShift.ToString(), FrameLength.ToString() };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = ExtractLpcResidualErrorOneFile,
                    Description = Helper.NeutralFormat("Get lpc for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }
Ejemplo n.º 6
0
        private List<ParallelParameter> GenerateExtractRelatedFeaturesCommands()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();
            foreach (string sid in FileMap.Map.Keys)
            {
                // process one wave file.
                string waveFile = FileMap.BuildPath(WaveDir, sid, FileExtensions.Waveform);
                string relatedfeaFile = FileMap.BuildPath(RealtedFeaDir, sid, FileExtensions.Text);
                Helper.EnsureFolderExistForFile(relatedfeaFile);

                string[] argument = { waveFile, relatedfeaFile, FrameShift.ToString(), FrameLength.ToString() };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = ExtractRelatedFeaturesOneFile,
                    Description = Helper.NeutralFormat("Get related features for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }
Ejemplo n.º 7
0
        private void SplitF0NccfFileIntoSpearatedFile()
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();

            // split f0 and nccf.
            foreach (string sid in FileMap.Map.Keys)
            {
                // process one f0_nccf file.
                string f0NccfFile = FileMap.BuildPath(F0NccfDir, sid, FileExtensions.F0File);
                if (!File.Exists(f0NccfFile))
                {
                    Logger.LogLine("Fail to get f0_nccf for sentence {0}", sid);
                    continue;
                }

                // output file.
                string nccfFile = FileMap.BuildPath(NccfDir, sid, FileExtensions.F0File);
                Helper.EnsureFolderExistForFile(nccfFile);

                string f0File = FileMap.BuildPath(F0Dir, sid, FileExtensions.F0File);
                Helper.EnsureFolderExistForFile(f0File);

                // parallel computing.
                string[] argument = { f0NccfFile, nccfFile, f0File };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = ExtractF0NccfOneFile,
                    Description = Helper.NeutralFormat("Get f0 and nccf of sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            FlowHandler.ParallelComputing(parallelCommands);
        }
Ejemplo n.º 8
0
        private List<ParallelParameter> GenerateSmoothF0Commands(string if0Dir, string uvDir)
        {
            List<ParallelParameter> parallelCommands = new List<ParallelParameter>();
            foreach (string sid in FileMap.Map.Keys)
            {
                // check input file
                string f0File = FileMap.BuildPath(if0Dir, sid, FileExtensions.F0File);
                if (!File.Exists(f0File))
                {
                    Logger.LogLine("Fail to get f0 file for sentence {0}", sid);
                    continue;
                }

                string uvFile = FileMap.BuildPath(uvDir, sid, FileExtensions.Text);
                if (!File.Exists(uvFile))
                {
                    Logger.LogLine("Fail to get uv file for sentence {0}", sid);
                    continue;
                }

                // smooth one sentence's f0
                string smoothedF0File = FileMap.BuildPath(SmoothedF0Dir, sid, FileExtensions.F0File);
                Helper.EnsureFolderExistForFile(smoothedF0File);
                string[] argument = { f0File, uvFile, smoothedF0File, MinF0Value.ToString(), MaxF0Value.ToString() };
                ParallelMethod<string[]> method = new ParallelMethod<string[]>
                {
                    Argument = argument,
                    CallBackMethod = SmoothOneF0File,
                    Description = Helper.NeutralFormat("Get smoothed f0 for sentence \"{0}\"", sid),
                    Logger = Logger,
                };

                parallelCommands.Add(method);
            }

            return parallelCommands;
        }