コード例 #1
0
        public static string[] GetResamplerArg(ResamplerArgs Args)
        {
            if (Args.InputWavfile.IndexOf("shi_shi_shi.wav") > 0)
            {
                double dr = 0;
                dr = 1;
            }


            //子音伸缩率
            int vel = Args.ConsonantVelocity; //Vel子音速度

            if (vel > 1000)
            {
                vel = 1000;
            }
            if (vel < 0)
            {
                vel = 0;
            }
            double velj = Math.Pow(2, (1 - ((int)vel / 100)));
            double FixedConsonantLengthMs = Args.FixedConsonantLengthMs * velj;
            double SoundStartMs           = Args.SoundStartMs * velj;


            double TickDebetMs             = UtauToolUtils.Global_GenerateGlobalPlusTimeMs(Args.ThisPreutterOverlapsArgs, Args.NextPreutterOverlapsArgs);
            double FixedMillisecLengthBase = MidiMathUtils.Tick2Time((long)(Args.TickLength), Args.Tempo) * 1000 + Args.ThisPreutterOverlapsArgs.PreUtterance - Args.NextRealPreutterOverlapsArgs.PreUtterance + Args.NextRealPreutterOverlapsArgs.OverlapMs;
            //   double FixedMillisecLength = UtauToolUtils.Resampler_SortNear50((int)FixedMillisecLengthBase);//Fixed.Resampler_SortNear50((int)(MidiMathUtils.Tick2Time((long)(Args.TickLength), Args.Tempo) * 1000 + (TickDebetMs < 0 ? 0 : TickDebetMs)));
            double FixedMillisecLength2 = UtauToolUtils.Resampler_SortNear50((int)(FixedMillisecLengthBase + SoundStartMs));

            string[] resampler_arg_suffix = new string[] {
                "\"" + Args.InputWavfile + "\"",
                "\"" + Args.OutputFile + "\"",
                "" + Args.Note + "",
                vel.ToString(),                                 //<==VEL
                "\"" + Args.Flags + "\"",
                (SoundStartMs).ToString("0.0###") + "",         //Args.SoundStartMs
                FixedMillisecLength2.ToString() + "",           //FixedMillisecLength
                FixedConsonantLengthMs.ToString("0.0###") + "", //Args.FixedConsonantLengthMs
                Args.FixedReleasingLengthMs.ToString("0.0###") + "",
                Args.Intensity.ToString() + "",
                Args.Moduration.ToString() + "",
                "!" + Args.Tempo.ToString() + "",
                Args.PitchString
            };
            return(resampler_arg_suffix);
        }
コード例 #2
0
        public static string[] GetWavtoolArgs(WavtoolArgs Args)
        {
            if (Args.InputWavfile == "{R}")
            {
                return(GetWavtoolArgs_SleepR(Args));
            }
            double PreUttrOverlapsMs = UtauToolUtils.Global_GenerateGlobalPlusTimeMs(Args.ThisPreutterOverlapsArgs, Args.NextPreutterOverlapsArgs);
            long   TotalLength       = (long)Math.Ceiling(MidiMathUtils.Tick2Time((long)Args.TickLength, Args.Tempo) * 1000 + PreUttrOverlapsMs);
            double EnvStart          = Args.FadeInLengthMs;
            double EnvEnd            = TotalLength - Args.FadeOutLengthMs;
            SortedDictionary <double, long> TargetEnvlope = new SortedDictionary <double, long>();
            double vpcp = (double)Args.VolumePercentInt / 100.0;

            if (TotalLength == 0)
            {
                TargetEnvlope.Add(Args.FadeInLengthMs, 100);
                TargetEnvlope.Add(TotalLength - Args.FadeOutLengthMs, 100);
            }
            else
            {
                TargetEnvlope.Add(0, 0);
                TargetEnvlope.Add(TotalLength, 0);
                long LastVol = 100;
                foreach (KeyValuePair <double, long> sortEnv in Args.EnvlopePoints)
                {
                    if (sortEnv.Key == EnvStart)
                    {
                        if (!TargetEnvlope.ContainsKey(sortEnv.Key))
                        {
                            TargetEnvlope.Add(sortEnv.Key, (long)(sortEnv.Value * vpcp));
                        }
                    }
                    else if (sortEnv.Key > EnvStart && sortEnv.Key <= EnvEnd)
                    {
                        if (!TargetEnvlope.ContainsKey(EnvStart))
                        {
                            TargetEnvlope.Add(EnvStart, (long)(LastVol * vpcp));
                        }
                        if (!TargetEnvlope.ContainsKey(sortEnv.Key))
                        {
                            TargetEnvlope.Add(sortEnv.Key, (long)(sortEnv.Value * vpcp));
                        }
                    }
                    else if (sortEnv.Key > EnvEnd)
                    {
                        break;
                    }
                    LastVol = sortEnv.Value;
                }
                if (!TargetEnvlope.ContainsKey(EnvStart))
                {
                    if (Args.EnvlopePoints.Count == 0 || TargetEnvlope.Count == 0)
                    {
                        if (!TargetEnvlope.ContainsKey(EnvStart))
                        {
                            TargetEnvlope.Add(EnvStart, (long)(LastVol * vpcp));
                        }
                    }
                    else
                    {
                        if (!TargetEnvlope.ContainsKey(EnvStart))
                        {
                            TargetEnvlope.Add(EnvStart, TargetEnvlope[TargetEnvlope.Keys.ToArray()[0]]);
                        }
                    }
                }
                if (!TargetEnvlope.ContainsKey(EnvEnd))
                {
                    if (!TargetEnvlope.ContainsKey(EnvEnd))
                    {
                        TargetEnvlope.Add(EnvEnd, (long)(LastVol * vpcp));
                    }
                }
            }
            string        P2 = Math.Round(Args.FadeInLengthMs, 1).ToString();
            string        P3 = Math.Round(Args.FadeOutLengthMs, 1).ToString();
            string        V2 = (TargetEnvlope[Args.FadeInLengthMs] * vpcp).ToString();
            string        V3 = (TargetEnvlope[TotalLength - Args.FadeOutLengthMs] * vpcp).ToString();
            List <string> wavtool_arg_suffix = new List <string> {
                "\"" + Args.OutputWavfile + "\"",
                "\"" + Args.InputWavfile + "\"",
                "" + Math.Round(Args.StartPointMs, 3).ToString() + "",
                "" + Args.TickLength.ToString() + "@" + Args.Tempo.ToString() + (PreUttrOverlapsMs >= 0?"+":"-") + Math.Round(Math.Abs(PreUttrOverlapsMs), 3).ToString("########.0##"),
                //P1,P2,P3
                "0",
                P2,
                P3,
                //V1,V2,V3,V4
                "0", V2, V3, "0",
                Math.Round(Args.ThisPreutterOverlapsArgs.OverlapMs, 3).ToString(),
                //P4
                "0"
            };
            double lastMs = Args.FadeInLengthMs;

            foreach (KeyValuePair <double, long> sortEnv in TargetEnvlope)
            {
                if (sortEnv.Key >= EnvEnd)
                {
                    break;
                }
                if (sortEnv.Key <= EnvStart)
                {
                    lastMs = sortEnv.Key;
                    continue;
                }
                double dert = sortEnv.Key - lastMs;
                lastMs = sortEnv.Key;
                wavtool_arg_suffix.Add(Math.Round(dert, 1).ToString());
                wavtool_arg_suffix.Add(((long)(sortEnv.Value * vpcp)).ToString());
            }

            return(wavtool_arg_suffix.ToArray());
        }