Beispiel #1
0
 public void LoadSinger(string RealFolder)
 {
     if (!SingerIndexerCache.ContainsKey(RealFolder))
     {
         VocalIndexObject vio = VocalIndexObject.Deseralize(RealFolder);
         SingerIndexerCache.Add(RealFolder, vio);
     }
 }
Beispiel #2
0
        public VocalIndexObject GetVocalIndexObject(PartsObject parts)
        {
            //VocalUtau.Program.GlobalPackage
            string           singerGUID = parts.SingerGUID;
            string           folder     = SingerFinder.getSingerDir(singerGUID, ProjectBeeper.IntPtr);
            VocalIndexObject vio        = Indexer.getIndex(folder);

            return(vio);
        }
Beispiel #3
0
        public SplitDictionary GetPhonemesDictionary(PartsObject parts)
        {
            //VocalUtau.Program.GlobalPackage
            string           singerGUID = parts.SingerGUID;
            string           folder     = SingerFinder.getSingerDir(singerGUID, ProjectBeeper.IntPtr);
            VocalIndexObject vio        = Indexer.getIndex(folder);

            return(vio.SplitDictionary);
        }
        public void UpdateGlobalSingerList()
        {
            if (!System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\voicedb"))
            {
                System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\voicedb");
            }
            string          voicedir = AppDomain.CurrentDomain.BaseDirectory + "\\voicedb";
            List <FileInfo> flist    = PathUtils.GetFirstFiles(new System.IO.DirectoryInfo(voicedir), new string[] { "voicedbi.dat", "character.txt" }, Program.GlobalPackage.Configures.VocalDbSearchDeep);

            Object locker = new Object();

            Parallel.For(0, flist.Count, (i) => {
                bool Haved = false;
                foreach (SingerObject s in Program.GlobalPackage.Configures.GlobalSingerList)
                {
                    if (s.getRealSingerFolder() == flist[i].Directory.FullName)
                    {
                        Haved = true;
                        break;
                    }
                }
                if (!Haved)
                {
                    VocalIndexObject vio = VocalIndexObject.Deseralize(flist[i].Directory.FullName);
                    SingerObject nso     = new SingerObject();
                    nso.VocalName        = vio.CharacertData.Dbname;
                    nso.SingerFolder     = PathUtils.RelativePath(AppDomain.CurrentDomain.BaseDirectory, PathUtils.AbsolutePath(voicedir, flist[i].Directory.FullName));
                    nso.Avatar           = vio.CharacertData.Avatar;
                    nso.PartResampler    = "resampler.exe";
                    lock (locker)
                    {
                        _Indexer.AddIndexer(flist[i].Directory.FullName, vio);
                        if (vio.GUID != "")
                        {
                            nso.GUID = vio.GUID;
                        }
                        if (Program.GlobalPackage.Configures.GlobalSingerList.IndexOf(nso) == -1)
                        {
                            Program.GlobalPackage.Configures.GlobalSingerList.Add(nso);
                        }
                        else
                        {
                            Program.GlobalPackage.Configures.GlobalSingerList[Program.GlobalPackage.Configures.GlobalSingerList.IndexOf(nso)] = nso;
                        }
                    }
                }
            });
        }
 public void InitSingers(List <SingerObject> SingerList = null)
 {
     if (SingerList == null)
     {
         SingerList = Program.GlobalPackage.Configures.GlobalSingerList;
     }
     foreach (SingerObject so in SingerList)
     {
         if (so == null)
         {
             continue;
         }
         string RFolder = so.getRealSingerFolder();
         _Indexer.LoadSinger(RFolder);
         VocalIndexObject vio = _Indexer.getIndex(RFolder);
         if (vio != null)
         {
             if (vio.GUID != "")
             {
                 so.GUID = vio.GUID;
             }
         }
     }
 }
Beispiel #6
0
        public void FillPartsNotes(PartsObject parts, long StartTick)
        {
            if (StartTick < 0)
            {
                return;
            }
            if (parts.TickLength < StartTick)
            {
                return;
            }
            double           partsTempo = parts.Tempo;
            int              firstIndex = parts.NoteCompiler.FindTickIn(StartTick, 0, parts.NoteList.Count);
            VocalIndexObject vio        = SingerDataFinder.GetVocalIndexObject(parts);
            string           fio        = SingerDataFinder.GetSingerFolder(parts);
            SingerObject     sobject    = SingerDataFinder.GetSingerObject(parts);

            if (vio == null)
            {
                return;
            }
            Object locker = new Object();

            //完成初步演算
            Parallel.For(firstIndex < 0 ? 0 : firstIndex, parts.NoteList.Count, (i) => {
                if (parts.NoteList[i].Tick + parts.NoteList[i].Length > StartTick)
                {
                    NoteObject curNote       = parts.NoteList[i];
                    List <NotePreRender> NPR = new List <NotePreRender>();
                    List <long> NPT          = PhonemeSplitTools.SplitedTickList(curNote.Length, curNote.PhonemeAtoms);
                    long TotalTick           = curNote.Tick;
                    for (int j = 0; j < curNote.PhonemeAtoms.Count; j++)
                    {
                        NotePreRender pra     = new NotePreRender();
                        pra.Tempo             = parts.Tempo;
                        pra.partStartTime     = parts.StartTime;
                        pra.ConsonantVelocity = (int)defDouble(curNote.PhonemeAtoms[j].Velocity, 100);
                        pra.Tick       = TotalTick;
                        pra.Length     = NPT[j];
                        pra.TimeLen    = MidiMathUtils.Tick2Time(pra.Length, parts.Tempo) * 1000;
                        TotalTick     += pra.Length;
                        pra.Note       = GetNote(curNote.PitchValue.NoteNumber);
                        pra.StartPoint = defDouble(curNote.PhonemeAtoms[j].StartPoint, 0);
                        string defflag = "";
                        string resamp  = "";
                        try
                        {
                            defflag = sobject.Flags;
                        }catch {; }
                        try
                        {
                            resamp = sobject.getRealResamplerPath();
                        }
                        catch {; }
                        pra.Flags     = curNote.PhonemeAtoms[j].getFlags(parts.getFlags(defflag));
                        pra.Resampler = parts.getResampler(resamp);

                        pra.VolumePercentInt = curNote.PhonemeAtoms[j].VolumePercentInt;

                        SoundAtom baa = new SoundAtom();
                        uint nn       = curNote.PitchValue.NoteNumber;
                        string pref   = "";
                        string suff   = "";
                        if (vio.PrefixAtomList.PreFix.ContainsKey(nn))
                        {
                            pref = vio.PrefixAtomList.PreFix[nn];
                        }
                        if (vio.PrefixAtomList.SufFix.ContainsKey(nn))
                        {
                            suff = vio.PrefixAtomList.SufFix[nn];
                        }
                        baa.PhonemeSymbol = pref + curNote.PhonemeAtoms[j].PhonemeAtom + suff;
                        int vid           = vio.SndAtomList.IndexOf(baa);
                        if (vid == -1 && pref != "" && suff != "")
                        {
                            baa.PhonemeSymbol = curNote.PhonemeAtoms[j].PhonemeAtom;
                            vid = vio.SndAtomList.IndexOf(baa);
                        }
                        if (vid > -1)
                        {
                            pra.OtoAtom = (SoundAtom)vio.SndAtomList[vid].Clone();
                            pra.OtoAtom.PreutterOverlapsArgs.PreUtterance = defDouble(curNote.PhonemeAtoms[j].PreUtterance, pra.OtoAtom.PreutterOverlapsArgs.PreUtterance);
                            pra.OtoAtom.PreutterOverlapsArgs.OverlapMs    = defDouble(curNote.PhonemeAtoms[j].Overlap, pra.OtoAtom.PreutterOverlapsArgs.OverlapMs);
                            pra.RealPreUtterOverArgs.PreUtterance         = pra.OtoAtom.PreutterOverlapsArgs.PreUtterance;
                            pra.RealPreUtterOverArgs.OverlapMs            = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs;
                            pra.OtoAtom.WavFile = PathUtils.AbsolutePath(fio, pra.OtoAtom.WavFile);
                            pra.FadeInLengthMs  = curNote.PhonemeAtoms[j].FadeInLengthMs;
                            pra.FadeOutLengthMs = curNote.PhonemeAtoms[j].FadeOutLengthMs;
                            if (j > 0)
                            {
                                pra.FadeInLengthMs = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs;
                                if (pra.Tick - NPR[j - 1].Tick - NPR[j - 1].Length < 2)
                                {
                                    NPR[j - 1].FadeOutLengthMs = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs;
                                }
                            }
                            pra.Intensity  = defDouble(curNote.PhonemeAtoms[j].Intensity, 100);
                            pra.Moduration = defDouble(curNote.PhonemeAtoms[j].Modulation, 0);
                            //pra.StartTime = MidiMathUtils.Tick2Time(pra.Tick, pra.Tempo);
                            pra.StartTimeAttend = -pra.OtoAtom.PreutterOverlapsArgs.OverlapMs / 1000;
                            pra.StartTick       = MidiMathUtils.Time2Tick(pra.StartTime, pra.Tempo);
                            if (StartTick - pra.Tick > pra.Length)
                            {
                                pra.passTime = double.MaxValue;
                            }
                            else if (StartTick - pra.Tick > 0)
                            {
                                pra.passTime = MidiMathUtils.Tick2Time(StartTick - pra.Tick, pra.Tempo) * 1000;
                            }
                            else
                            {
                                pra.passTime = 0;
                            }

                            if (pra.StartTick < 0)
                            {
                                pra.StartTick = 0;
                            }
                            List <int> PointVS = new List <int>();
                            SortedDictionary <double, long> EnvVs = new SortedDictionary <double, long>();
                            long lastDYNValue = -100;
                            for (long k = pra.StartTick; k <= pra.StartTick + pra.Length + 50; k = k + 5)
                            {
                                PointVS.Add((int)(parts.PitchCompiler.getRealPitch(k) - curNote.PitchValue.NoteNumber) * 100);
                                long dyn = (long)(parts.DynCompiler.getDynValue(k) + parts.DynBaseValue);
                                if (dyn != lastDYNValue)
                                {
                                    double TimeMs = (MidiMathUtils.Tick2Time(k - pra.StartTick, parts.Tempo) * 1000);
                                    if (!EnvVs.ContainsKey(TimeMs))
                                    {
                                        EnvVs.Add(TimeMs, dyn);
                                    }
                                }
                            }
                            pra.EnvlopePoints = EnvVs;
                            pra.PitchString   = PitchEncoderUtils.Encode(PointVS);
                            NPR.Add(pra);
                        }
                        else
                        {
                            pra.OtoAtom = new SoundAtom();
                            pra.OtoAtom.PhonemeSymbol = "{R}";
                            pra.Note = "{R}";
                            //pra.StartTime = MidiMathUtils.Tick2Time(pra.Tick, pra.Tempo);
                            if (StartTick - pra.Tick > pra.Length)
                            {
                                pra.passTime = double.MaxValue;
                            }
                            else if (StartTick - pra.Tick > 0)
                            {
                                pra.passTime = MidiMathUtils.Tick2Time(StartTick - pra.Tick, pra.Tempo) * 1000;
                            }
                            else
                            {
                                pra.passTime = 0;
                            }

                            if (pra.StartTick < 0)
                            {
                                pra.StartTick = 0;
                            }
                            lock (locker)
                            {
                                NPR.Add(pra);
                            }
                        }
                    }
                    lock (locker)
                    {
                        _NotePreRenderList.AddRange(NPR.ToArray());
                    }
                }
            });
            _NotePreRenderList.Sort();
            int TotC = _NotePreRenderList.Count;

            Parallel.For(0, TotC, (i) =>
            {
                NotePreRender Cur = _NotePreRenderList[i];
                NotePreRender Pre = null;
                if (i > 0)
                {
                    //不是第一个
                    Pre      = _NotePreRenderList[i - 1];
                    long dbp = Cur.Tick - Pre.Tick - Pre.Length;
                    if (dbp > 0)
                    {
                        long totalp = dbp;
                        while (totalp > 0)
                        {
                            NotePreRender npr         = new NotePreRender();
                            npr.ConsonantVelocity     = 100;
                            npr.OtoAtom               = new SoundAtom();
                            npr.OtoAtom.PhonemeSymbol = "{R}";
                            npr.Tick    = Pre.Tick + Pre.Length;
                            npr.Length  = totalp > 480 ? 480 : totalp;
                            totalp     -= 480;
                            npr.Tempo   = parts.Tempo;
                            npr.Note    = "{R}";
                            npr.TimeLen = MidiMathUtils.Tick2Time(npr.Length, parts.Tempo) * 1000;
                            lock (locker)
                            {
                                _NotePreRenderList.Add(npr);
                            }
                        }
                    }
                }
                else
                {
                    long dbp = Cur.Tick - StartTick;
                    if (dbp > 0)
                    {
                        long totalp = dbp;
                        while (totalp > 0)
                        {
                            NotePreRender npr         = new NotePreRender();
                            npr.ConsonantVelocity     = 100;
                            npr.OtoAtom               = new SoundAtom();
                            npr.OtoAtom.PhonemeSymbol = "{R}";
                            npr.Tick    = dbp - totalp;
                            npr.Tempo   = parts.Tempo;
                            npr.Length  = totalp > 480 ? 480 : totalp;
                            totalp     -= 480;
                            npr.Note    = "{R}";
                            npr.TimeLen = MidiMathUtils.Tick2Time(npr.Length, parts.Tempo) * 1000;
                            lock (locker)
                            {
                                _NotePreRenderList.Add(npr);
                            }
                        }
                    }
                }
            });
            _NotePreRenderList.Sort();

            Parallel.For(0, _NotePreRenderList.Count, (i) =>
            {
                NotePreRender Nxt = null;
                if (i + 1 < _NotePreRenderList.Count)
                {
                    Nxt = _NotePreRenderList[i + 1];
                }

                /*
                 * 修正PreOverlap
                 */
                if (Nxt != null)
                {
                    double PRE       = Nxt.RealPreUtterOverArgs.PreUtterance;
                    double OVL       = Nxt.RealPreUtterOverArgs.OverlapMs;
                    double KickFront = PRE - OVL;
                    double halfNote  = _NotePreRenderList[i].TimeLen / 2;
                    if (_NotePreRenderList[i].Note == "{R}")
                    {
                        halfNote = _NotePreRenderList[i].TimeLen;
                    }
                    if (halfNote < KickFront)
                    {
                        //NEED FIX
                        double ovl = OVL / (PRE - OVL) * halfNote;
                        double pre = PRE / (PRE - OVL) * halfNote;
                        if (Nxt.FadeInLengthMs == OVL && _NotePreRenderList[i].FadeOutLengthMs == OVL)
                        {
                            Nxt.FadeInLengthMs = ovl;
                            _NotePreRenderList[i].FadeOutLengthMs = ovl;
                        }
                        Nxt.RealPreUtterOverArgs.OverlapMs    = ovl;
                        Nxt.RealPreUtterOverArgs.PreUtterance = pre;
                        Nxt.StartPoint = PRE - pre;
                        //DEG
                        Nxt.StartTimeAttend = -Nxt.RealPreUtterOverArgs.OverlapMs / 1000;
                    }
                }

                /*
                 * 修正结束
                 */
                if (_NotePreRenderList[i].FadeInLengthMs < _NotePreRenderList[i].RealPreUtterOverArgs.OverlapMs)
                {
                    _NotePreRenderList[i].FadeInLengthMs = _NotePreRenderList[i].RealPreUtterOverArgs.OverlapMs;
                }
                if (Nxt != null)
                {
                    if (_NotePreRenderList[i].FadeOutLengthMs < Nxt.RealPreUtterOverArgs.OverlapMs)
                    {
                        _NotePreRenderList[i].FadeOutLengthMs = Nxt.RealPreUtterOverArgs.OverlapMs;
                    }
                }
                UtauRendCommanderUtils.ResamplerArgs ra = _NotePreRenderList[i].Note == "{R}"?null:NPR2ResamplerArgs(_NotePreRenderList[i], Nxt, "{RESAMPLEROUTPUT}");
                string[] ResList = ra == null ? new string[0] : UtauRendCommanderUtils.GetResamplerArg(ra);
                UtauRendCommanderUtils.WavtoolArgs wa = NPR2WavtoolArgs(_NotePreRenderList[i], Nxt, "{RESAMPLEROUTPUT}", "{WAVOUTPUT}");
                string[] WavList = wa == null ? new string[0] : UtauRendCommanderUtils.GetWavtoolArgs(wa);
                lock (locker)
                {
                    // List<string> LSL = new List<string>();
                    // for (int j = 0; j <= Math.Min(12, WavList.Length - 1); j++) LSL.Add(WavList[j]);
                    _NotePreRenderList[i].ResamplerArg     = ra;
                    _NotePreRenderList[i].ResamplerArgList = ResList;
                    _NotePreRenderList[i].WavtoolArgs      = wa;
                    _NotePreRenderList[i].WavtoolArgList   = WavList;// LSL.ToArray();// WavList;
                }
            });
        }
Beispiel #7
0
 public void AddIndexer(string Path, VocalIndexObject Index)
 {
     SingerIndexerCache.Add(Path, Index);
 }