示例#1
0
        public System.IO.Stream DoResampler(DriverModels.EngineInput Args)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            if (!_isLegalPlugin)
            {
                return(ms);
            }
            try
            {
                string tmpFile  = System.IO.Path.GetTempFileName();
                string ArgParam = string.Format(
                    "\"{0}\" \"{1}\" {2} {3} \"{4}\" {5} {6} {7} {8} {9} {10} !{11} {12}",
                    Args.inputWaveFile,
                    tmpFile,
                    Args.NoteString,
                    Args.Velocity,
                    Args.StrFlags,
                    Args.Offset,
                    Args.RequiredLength,
                    Args.Consonant,
                    Args.Cutoff,
                    Args.Volume,
                    Args.Modulation,
                    Args.Tempo,
                    Base64.Base64EncodeInt12(Args.pitchBend));

                var p = Process.Start(new ProcessStartInfo(ExePath, ArgParam)
                {
                    UseShellExecute = false, CreateNoWindow = true
                });
                p.WaitForExit();
                if (p != null)
                {
                    p.Close();
                    p.Dispose();
                    p = null;
                }
                if (System.IO.File.Exists(tmpFile))
                {
                    byte[] Dat = System.IO.File.ReadAllBytes(tmpFile);
                    ms = new MemoryStream(Dat);
                    try
                    {
                        System.IO.File.Delete(tmpFile);
                    }
                    catch {; }
                }
            }
            catch (Exception e) {; }
            return(ms);
        }
示例#2
0
 public string GetResamplerExeArgs()
 {
     // fresamp.exe <infile> <outfile> <tone> <velocity> <flags> <offset> <length_req>
     // <fixed_length> <endblank> <volume> <modulation> <pitch>
     return(FormattableString.Invariant($"{MusicMath.GetNoteString(NoteNum)} {Velocity:D} \"{StrFlags}\" {Oto.Offset} {RequiredLength:D} {Oto.Consonant} {Oto.Cutoff} {Volume:D} {Modulation:D} {Tempo} {Base64.Base64EncodeInt12(PitchData.ToArray())}"));
 }
示例#3
0
        public byte[] DoResampler(DriverModels.EngineInput Args)
        {
            byte[] data = new byte[0];
            if (!_isLegalPlugin)
            {
                return(data);
            }
            try {
                string tmpFile  = Path.GetTempFileName();
                string ArgParam = FormattableString.Invariant(
                    $"\"{Args.inputWaveFile}\" \"{tmpFile}\" {Args.NoteString} {Args.Velocity} \"{Args.StrFlags}\" {Args.Offset} {Args.RequiredLength} {Args.Consonant} {Args.Cutoff} {Args.Volume} {Args.Modulation} !{Args.Tempo} {Base64.Base64EncodeInt12(Args.pitchBend)}");

                var p = Process.Start(new ProcessStartInfo(ExePath, ArgParam)
                {
                    UseShellExecute = false, CreateNoWindow = true
                });
                p.WaitForExit();
                if (p != null)
                {
                    p.Close();
                    p.Dispose();
                    p = null;
                }

                if (File.Exists(tmpFile))
                {
                    data = File.ReadAllBytes(tmpFile);
                    try {
                        File.Delete(tmpFile);
                    } catch {; }
                }
            } catch (Exception) {; }
            return(data);
        }
示例#4
0
        public byte[] DoResampler(DriverModels.EngineInput Args, ILogger logger)
        {
            const bool debugResampler = false;

            byte[] data = new byte[0];
            if (!_isLegalPlugin)
            {
                return(data);
            }
            var    threadId = Thread.CurrentThread.ManagedThreadId;
            string tmpFile  = Path.GetTempFileName();
            string ArgParam = FormattableString.Invariant(
                $"\"{Args.inputWaveFile}\" \"{tmpFile}\" {Args.NoteString} {Args.Velocity} \"{Args.StrFlags}\" {Args.Offset} {Args.RequiredLength} {Args.Consonant} {Args.Cutoff} {Args.Volume} {Args.Modulation} !{Args.Tempo} {Base64.Base64EncodeInt12(Args.pitchBend)}");

            logger.Information($" > [thread-{threadId}] {ExePath} {ArgParam}");
            using (var proc = new Process()) {
                proc.StartInfo = new ProcessStartInfo(ExePath, ArgParam)
                {
                    UseShellExecute        = false,
                    RedirectStandardOutput = debugResampler,
                    RedirectStandardError  = debugResampler,
                    CreateNoWindow         = true,
                };
#pragma warning disable CS0162 // Unreachable code detected
                if (debugResampler)
                {
                    proc.OutputDataReceived += (o, e) => logger.Information($" >>> [thread-{threadId}] {e.Data}");
                    proc.ErrorDataReceived  += (o, e) => logger.Error($" >>> [thread-{threadId}] {e.Data}");
                }
                proc.Start();
                if (debugResampler)
                {
                    proc.BeginOutputReadLine();
                    proc.BeginErrorReadLine();
                }
#pragma warning restore CS0162 // Unreachable code detected
                if (!proc.WaitForExit(10000))
                {
                    logger.Warning($"[thread-{threadId}] Timeout, killing...");
                    try {
                        proc.Kill();
                        logger.Warning($"[thread-{threadId}] Killed.");
                    } catch (Exception e) {
                        logger.Error(e, $"[thread-{threadId}] Failed to kill");
                    }
                }
            }
            if (File.Exists(tmpFile))
            {
                data = File.ReadAllBytes(tmpFile);
                File.Delete(tmpFile);
            }
            return(data);
        }