public static byte[] GetCustomHarmonicLevels(WaveformParameters parameters, int count, int maxLevel) { List <byte> levels = new List <byte>(); var n = 0; while (n < count) { levels.Add((byte)WaveformEngine.GetHarmonicLevel(n + 1, parameters, maxLevel)); n++; } return(levels.ToArray()); }
public static int GetHarmonicLevel(int harmonicNumber, WaveformParameters para, int maxLevel = 99) { double aMax = 1.0; double a = WaveformEngine.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)); }
private Source GenerateAdditiveSource(string waveformTemplateName, string harmonicLevelTemplateName, string harmonicEnvelopeTemplateName, string formantFilterTemplateName) { Source source = new Source(); source.Zone = new Zone(0, 127); VelocitySwitchSettings vel = new VelocitySwitchSettings(); vel.SwitchKind = VelocitySwitchKind.Off; vel.Threshold = 68; source.VelocitySwitch = vel; source.Volume.Value = 120; source.KeyOnDelay.Value = 0; source.EffectPath = EffectPath.Path1; source.BenderCutoff.Value = 12; source.BenderPitch.Value = 2; source.Pan = PanKind.Normal; source.PanValue.Value = 0; // DCO settings for additive source source.DCO.Wave = new Wave(AdditiveKit.WaveNumber); source.DCO.Coarse.Value = 0; source.DCO.Fine.Value = 0; source.DCO.KSPitch = KeyScalingToPitch.ZeroCent; source.DCO.FixedKey = new FixedKey(); // OFF PitchEnvelope pitchEnv = new PitchEnvelope(); pitchEnv.StartLevel.Value = 0; pitchEnv.AttackTime.Value = 4; pitchEnv.AttackLevel.Value = 0; pitchEnv.DecayTime.Value = 64; pitchEnv.LevelVelocitySensitivity.Value = 0; pitchEnv.TimeVelocitySensitivity.Value = 0; source.DCO.Envelope = pitchEnv; // DCF source.DCF.IsActive = true; source.DCF.Cutoff.Value = 55; source.DCF.Resonance.Value = 0; source.DCF.Level.Value = 7; source.DCF.Mode = FilterMode.LowPass; source.DCF.VelocityCurve = VelocityCurve.Curve5; // DCF Envelope FilterEnvelope filterEnv = new FilterEnvelope(); source.DCF.EnvelopeDepth.Value = 25; filterEnv.AttackTime.Value = 0; filterEnv.Decay1Time.Value = 120; filterEnv.Decay1Level.Value = 63; filterEnv.Decay2Time.Value = 80; filterEnv.Decay2Level.Value = 63; filterEnv.ReleaseTime.Value = 20; source.DCF.Envelope = filterEnv; // DCF Modulation: source.DCF.KeyScalingToEnvelopeAttackTime.Value = 0; source.DCF.KeyScalingToEnvelopeDecay1Time.Value = 0; source.DCF.VelocityToEnvelopeDepth.Value = 30; source.DCF.VelocityToEnvelopeAttackTime.Value = 0; source.DCF.VelocityToEnvelopeDecay1Time.Value = 0; // DCA Envelope AmplifierEnvelope ampEnv = new AmplifierEnvelope(); ampEnv.AttackTime.Value = 1; ampEnv.Decay1Time.Value = 94; ampEnv.Decay1Level.Value = 127; ampEnv.Decay2Time.Value = 80; ampEnv.Decay2Level.Value = 63; ampEnv.ReleaseTime.Value = 20; source.DCA.Envelope = ampEnv; // DCA Modulation source.DCA.KeyScaling.Level.Value = 0; source.DCA.KeyScaling.AttackTime.Value = 0; source.DCA.KeyScaling.Decay1Time.Value = 0; source.DCA.KeyScaling.ReleaseTime.Value = 0; source.DCA.VelocitySensitivity.Level.Value = 20; source.DCA.VelocitySensitivity.AttackTime.Value = 20; source.DCA.VelocitySensitivity.Decay1Time.Value = 20; source.DCA.VelocitySensitivity.ReleaseTime.Value = 20; // Harmonic levels if (!string.IsNullOrEmpty(waveformTemplateName)) { int numHarmonics = 64; byte[] levels = WaveformEngine.GetHarmonicLevels(waveformTemplateName, numHarmonics, 127); // levels are 0...127 source.ADD.SoftHarmonics = levels; Console.WriteLine(String.Format("waveform template = {0}", waveformTemplateName)); /* * Console.WriteLine(String.Format("{0}, {1} harmonics:", waveformName, numHarmonics)); * for (int i = 0; i < levels.Length; i++) * { * Console.WriteLine(String.Format("{0} = {1}", i + 1, levels[i])); * } */ } else if (!string.IsNullOrEmpty(harmonicLevelTemplateName)) { Console.WriteLine(String.Format("harmonic template = {0}", harmonicLevelTemplateName)); int[] softLevels = this.harmonicLevelTemplates[harmonicLevelTemplateName].Low.ToArray(); source.ADD.SoftHarmonics = softLevels.Select(i => (byte)i).ToArray(); int[] loudLevels = this.harmonicLevelTemplates[harmonicLevelTemplateName].High.ToArray(); source.ADD.LoudHarmonics = loudLevels.Select(i => (byte)i).ToArray(); } else { Console.WriteLine("No template specified for waveform or harmonic levels, using defaults"); int[] softLevels = this.harmonicLevelTemplates["Init"].Low.ToArray(); source.ADD.SoftHarmonics = softLevels.Select(i => (byte)i).ToArray(); int[] loudLevels = this.harmonicLevelTemplates["Init"].High.ToArray(); source.ADD.LoudHarmonics = loudLevels.Select(i => (byte)i).ToArray(); } // Harmonic envelopes. Initially assign the same envelope for each harmonic. string harmEnvName = harmonicEnvelopeTemplateName; if (string.IsNullOrEmpty(harmonicEnvelopeTemplateName)) { harmEnvName = "Init"; } Console.WriteLine(String.Format("harmonic envelope template = {0}", harmEnvName)); HarmonicEnvelope harmEnv = this.harmonicEnvelopeTemplates[harmEnvName]; for (int i = 0; i < AdditiveKit.HarmonicCount; i++) { source.ADD.HarmonicEnvelopes[i] = harmEnv; } // Formant filter string formantName = formantFilterTemplateName; if (string.IsNullOrEmpty(formantFilterTemplateName)) { formantName = "Init"; } Console.WriteLine(String.Format("formant filter template = {0}", formantName)); int[] formantLevels = this.formantFilterTemplates[formantName].ToArray(); source.ADD.FormantFilter = formantLevels.Select(i => (byte)i).ToArray(); return(source); }
public static int RunEditAndReturnExitCode(EditOptions options) { byte[] levels; if (options.Waveform.Equals("custom")) { if (string.IsNullOrEmpty(options.Params)) { Console.WriteLine("Parameters required for Custom waveform"); return(1); } var paramStrings = new List <string>(options.Params.Split(',')); /* * foreach (string s in paramStrings) * { * Console.WriteLine(s); * } */ var paramValues = new List <double>(); foreach (string s in paramStrings) { double value = double.Parse(s, CultureInfo.InvariantCulture); paramValues.Add(value); } /* * foreach (double v in paramValues) * { * Console.WriteLine(v); * } */ var parameters = new WaveformParameters { A = paramValues[0], B = paramValues[1], C = paramValues[2], XP = paramValues[3], D = paramValues[4], E = paramValues[5], YP = paramValues[6] }; levels = WaveformEngine.GetCustomHarmonicLevels(parameters, 64, 127); } else { levels = WaveformEngine.GetHarmonicLevels(options.Waveform, 64, 127); } List <string> group1Lines = SendHarmonics(options.Device, 0, 1, levels, 1); foreach (var line in group1Lines) { Console.WriteLine(line); } List <string> group2Lines = SendHarmonics(options.Device, 0, 1, levels, 2); foreach (var line in group2Lines) { Console.WriteLine(line); } return(0); }