コード例 #1
0
 public void Append(Stream InputRiffStream, double offset, double length,
                    double ovr, List <KeyValuePair <double, double> > KV, double DropTime = 0)
 {
     if (!_NoShowText)
     {
         Console.WriteLine("Ask For Overlap time:{0}", ovr);
     }
     FillOvr(ovr);
     if (!_NoShowText)
     {
         Console.WriteLine("Wav Appending");
     }
     WavAppender.AppendWork(bufferstream, InputRiffStream, offset, length,
                            ovr, KV, DropTime);
 }
コード例 #2
0
        public void StartRending(System.IO.DirectoryInfo baseTempDir, List <VocalUtau.Calculators.NoteListCalculator.NotePreRender> NList, string RendToWav = "")
        {
            _IsRending   = true;
            _ExitRending = false;
            if (RendingStateChange != null)
            {
                RendingStateChange(this);
            }

            string        ProcessIDStr = Process.GetCurrentProcess().Id.ToString();
            DirectoryInfo tempDir      = baseTempDir.CreateSubdirectory("temp");
            DirectoryInfo cacheDir     = baseTempDir.CreateSubdirectory("cache");

            string TrackFileName = tempDir.FullName + "\\Track_" + CacheSignal + ".wav";

            FileStream Fs;

            headSize = InitFile(out Fs, TrackFileName);
            Semaphore semaphore = new Semaphore(1, 1, "VocalUtau.WavTool." + ProcessIDStr + ".Track_" + CacheSignal);

            ResamplerCacheDic.Clear();
            Task t = Task.Factory.StartNew(() =>
            {
                DoResampler(cacheDir, NList);
            });

            for (int i = 0; i < NList.Count; i++)
            {
                while (!ResamplerCacheDic.ContainsKey(i))
                {
                    if (_ExitRending)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                if (_ExitRending)
                {
                    break;
                }
                string MidFileName = ResamplerCacheDic[i];
                string wavStr      = String.Join(" ", NList[i].WavtoolArgList);

                double delay = 0;
                if (NList[i].passTime > 0)
                {
                    delay = NList[i].passTime;
                }
                VocalUtau.WavTools.Model.Args.ArgsStruct parg = VocalUtau.WavTools.Model.Args.ArgsParser.parseArgs(NList[i].WavtoolArgList, false);
                Console.WriteLine("WaveAppending[" + i.ToString() + "/" + (NList.Count - 1).ToString() + "]:" + NList[i].Note + (NList[i].Note == "{R}"?"":"  -  " + NList[i].OtoAtom.PhonemeSymbol));


                semaphore.WaitOne();
                try
                {
                    WavAppender.AppendWork(Fs, MidFileName, parg.Offset, parg.Length, parg.Ovr, parg.PV, delay);
                }
                catch {; }
                Fs.Flush();
                semaphore.Release();
            }
            _IsRending = false;
            long total = Fs.Length;

            byte[] head = IOHelper.GenerateHead((int)(total - headSize));
            Fs.Seek(0, SeekOrigin.Begin);
            Fs.Write(head, 0, head.Length);
            Fs.Flush();
            Fs.Close();
            t.Wait();
            _ExitRending = false;
            if (RendingStateChange != null)
            {
                RendingStateChange(this);
            }
            if (RendToWav != "")
            {
                File.Copy(TrackFileName, RendToWav, true);
                try
                {
                    File.Delete(TrackFileName);
                }
                catch {; }
            }
        }