コード例 #1
0
        /// <summary>
        /// Flushes any pending data and closes output file. If writing to an OutputStream, the stream is not
        /// </summary>
        /// <returns>true is success</returns>
        public bool Finish()
        {
            if (!Started)
            {
                return(false);
            }
            bool ok = true;

            Started = false;
            try
            {
                Fs.WriteByte(0x3b); // gif trailer
                Fs.Flush();
                if (closeStream)
                {
                    Fs.Close();
                }
            }
            catch (IOException e)
            {
                ok = false;
            }

            // reset for subsequent use
            transIndex    = 0;
            Fs            = null;
            image         = null;
            pixels        = null;
            indexedPixels = null;
            colorTab      = null;
            closeStream   = false;
            firstFrame    = true;

            return(ok);
        }
コード例 #2
0
        public void StartRending(System.IO.DirectoryInfo baseTempDir, List <VocalUtau.Calculators.BarkerCalculator.BgmPreRender> BList, 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 + "\\Bgm_" + CacheSignal + ".wav";

            FileStream Fs;

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

            for (int i = 0; i < BList.Count; i++)
            {
                if (BList[i].DelayTime > 0)
                {
                    int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].DelayTime);
                    ByteTime -= ByteTime % 2;
                    byte[] byteL = new byte[ByteTime];
                    Array.Clear(byteL, 0, ByteTime);
                    Fs.Write(byteL, 0, ByteTime);
                }
                semaphore.WaitOne();
                try
                {
                    int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].PassTime);
                    ByteTime -= ByteTime % 2;
                    using (NAudio.Wave.AudioFileReader reader = new NAudio.Wave.AudioFileReader(BList[i].FilePath))
                    {
                        int JumpLoops = ByteTime / 2;
                        using (NAudio.Wave.Wave32To16Stream w16 = new NAudio.Wave.Wave32To16Stream(reader))
                        {
                            using (NAudio.Wave.WaveStream wfmt = new NAudio.Wave.BlockAlignReductionStream(w16))
                            {
                                using (NAudio.Wave.WaveStream wout = new NAudio.Wave.WaveFormatConversionStream(IOHelper.NormalPcmMono16_Format, wfmt))
                                {
                                    while (wout.Position < wout.Length)
                                    {
                                        if (_ExitRending)
                                        {
                                            break;
                                        }
                                        byte[] by = new byte[2];
                                        int    rd = wout.Read(by, 0, 2);
                                        if (JumpLoops > 0)
                                        {
                                            JumpLoops--;
                                        }
                                        else
                                        {
                                            Fs.Write(by, 0, 2);
                                        }

                                        /*  for (int w = 1; w < w16.WaveFormat.Channels; w++)
                                         * {
                                         *    int rdr = w16.Read(by, 0, 2);
                                         * }*/
                                    }
                                }
                            }
                        }
                    }
                }
                catch {; }
                Fs.Flush();
                semaphore.Release();
                if (_ExitRending)
                {
                    break;
                }
            }
            _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();
            _ExitRending = false;
            if (RendingStateChange != null)
            {
                RendingStateChange(this);
            }
            if (RendToWav != "")
            {
                File.Copy(TrackFileName, RendToWav, true);
                try
                {
                    File.Delete(TrackFileName);
                }
                catch {; }
            }
        }
コード例 #3
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 {; }
            }
        }