示例#1
0
        public static byte[] GetHarmonicLevels(string waveformName, int count)
        {
            LeiterParameters para   = WaveformParameters[waveformName];
            List <byte>      levels = new List <byte>();
            var n = 0;

            while (n < count)
            {
                levels.Add((byte)LeiterEngine.GetHarmonicLevel(n + 1, para));
                n++;
            }
            return(levels.ToArray());
        }
示例#2
0
        public static int RunGenerateAndReturnExitCode(GenerateOptions opts)
        {
            string waveformName = opts.WaveformName;

            byte[] harmonicLevels = LeiterEngine.GetHarmonicLevels(waveformName, 63);
            Console.WriteLine("Harmonic levels for '{0}':", waveformName);
            for (int i = 0; i < harmonicLevels.Length; i++)
            {
                Console.WriteLine(String.Format("{0}: {1}", i, harmonicLevels[i]));
            }
            Console.WriteLine(Util.HexDump(harmonicLevels));
            return(0);
        }
示例#3
0
        public static int GetHarmonicLevel(int harmonicNumber, LeiterParameters para, int maxLevel = 99)
        {
            double aMax  = 1.0;
            double a     = LeiterEngine.Compute(harmonicNumber, para);
            double v     = Math.Log(Math.Abs(a / aMax));
            double level = ((double)maxLevel) + 8.0 * v;

            System.Console.WriteLine(String.Format("DEBUG: n = {0}, a = {1}, v = {2}", harmonicNumber, a, v));
            if (level < 0)
            {
                return(0);
            }
            return((int)Math.Floor(level));
        }
示例#4
0
        public static int RunCreateAndReturnExitCode(CreateOptions opts)
        {
            //byte[] data = ExtractPatchData(message);
            //Single s = new Single(data);

            SinglePatch s = new SinglePatch();

            s.Name = "FRANKENP";

            byte[] newHarmonics = LeiterEngine.GetHarmonicLevels("saw", Source.HarmonicCount);
            for (int i = 0; i < Source.HarmonicCount; i++)
            {
                s.Source1.Harmonics[i].Level = newHarmonics[i];
                s.Source2.Harmonics[i].Level = newHarmonics[i];
            }
            s.Source1.Amplifier.EnvelopeSegments = Amplifier.Envelopes["regular"].Segments;
            s.Source2.Amplifier.EnvelopeSegments = Amplifier.Envelopes["silent"].Segments;

            int channel = 1;

            byte[]      newHeader = new byte[] { 0xF0, 0x40, (byte)(channel - 1), 0x20, 0x00, 0x02, 0x00, 0x2F };
            List <byte> newData   = new List <byte>();

            newData.AddRange(newHeader);
            newData.AddRange(Util.ConvertToTwoNybbleFormat(s.ToData()));
            newData.Add(0xf7);

            Console.WriteLine("Creating new patch, new SysEx data:\n{0}", Util.HexDump(newData.ToArray()));

            var folder      = Environment.SpecialFolder.Desktop;
            var newFileName = Path.Combine(new string[] { Environment.GetFolderPath(folder), "Frankenpatch.syx" });

            Console.WriteLine($"Writing SysEx data to '{newFileName}'...");
            File.WriteAllBytes(newFileName, newData.ToArray());

            return(0);
        }