using System; using System.Collections; using System.Collections.Generic; namespace Wavelet_Tracker { public class PitchRandomiseMachine : MachineParameterisedBase { private const string type = "Pitch Randomise"; private const string author = "Internal"; private const int version = 2; private Random qwer; public PitchRandomiseMachine(string name) : base(type, author, version, name) { qwer = new Random((int) System.DateTime.Now.Ticks%98765 + this.GetHashCode()); machineLimitations = MachineLimitations.ProcessWavelets; } protected override void endProductionImpl(long interval) { float dSpread = (float)(parameters[0].parameterValue); List list = inputs[0].buffer.getForProcessing(playTime, interval, true); for (int x = 0; x < list.Count; x++) { SoundEvent e = list[x]; if (e.eventType == EventType.AUDIO_WAVELETS) { float r = (float) qwer.NextDouble(); // (0.0 to 1.0) r -= 0.5f; // (+/- 0.5) r *= (float) dSpread; // (+/- dSpread/2) r += 1.0f; // (1 +/- dSpread/2) WaveletEvent w = (WaveletEvent) e; //WaveletEvent v = new WaveletEvent(w.frequency*r, w.amplitude, w.length, w.phase, w.time); w.frequency *= r; w.calcEndpoints(); } } outputs[0].buffer.addAllEvents(list); } protected override void endSeekImpl(long seekTime) { } protected override void endSetupParametersImpl() { parameters = new MachineParameter[1]; MachineParameterContinuous freq = new MachineParameterContinuous("Range", 0, 0.05f); freq.multiplier = 50; freq.label = "% +/-"; parameters[0] = freq; } protected override void endSetupInputOutputImpl() { outputs = new MachineConnection[1]; outputs[0] = new MachineConnection("Output"); inputs = new MachineConnection[1]; inputs[0] = new MachineConnection("Input"); } protected override void endTickImpl(ArrayList parameterChanges) { } } }