using System; using System.Collections; using System.Collections.Generic; namespace Wavelet_Tracker { public class PCMDistortionMachine : MachineParameterisedBase { ////////////////////////////////////////////////////////////////////////// // TODO: Fill in (and *maintain*) these values. ////////////////////////////////////////////////////////////////////////// private const string type = "PCM Distortion"; private const string author = "Internal"; private const int version = 1; public PCMDistortionMachine(string name) : base(type, author, version, name) { machineLimitations = MachineLimitations.ProcessPCM; } protected override void endSetupInputOutputImpl() { ////////////////////////////////////////////////////////////////////////// // TODO: Describe your machine's inputs and outputs as demonstrated below. ////////////////////////////////////////////////////////////////////////// outputs = new MachineConnection[1]; outputs[0] = new MachineConnection("Output"); inputs = new MachineConnection[1]; inputs[0] = new MachineConnection("Input"); } protected override void endSetupParametersImpl() { ////////////////////////////////////////////////////////////////////////// // TODO: Describe your machine's parameters as demonstrated below. ////////////////////////////////////////////////////////////////////////// parameters = new MachineParameter[2]; MachineParameterContinuous param = new MachineParameterContinuous("Threshold", 0, 0.2f); param.multiplier = 100; param.label = "%"; parameters[0] = param; param = new MachineParameterContinuous("Level", 0, 1.0f); param.multiplier = 100; param.label = "%"; parameters[1] = param; } protected unsafe override void endProductionImpl(long interval) { List list = inputs[0].buffer.getForProcessing(playTime, interval, true); // We are simply going to loop through the list of events we have. for (int j = 0; j < list.Count; j++) { SoundEvent e = list[j]; // Here we can see the machine filtering out the events that it is interested in. if (e.eventType == EventType.AUDIO_PCM) { PCMEvent pcm = (PCMEvent)e; float clip = (float)parameters[0].parameterValue; float level = (float)parameters[1].parameterValue; float amp = (level / clip); for (int x = 0; x < pcm.numChannels; x++) { for (int y = 0; y < pcm.bufferLength; y++) { float f = *(pcm.data[x] + y); if (f > clip) f = clip; if (f < -clip) f = -clip; *(pcm.data[x] + y) = f * amp; } } // The original event is put into the 'dry' output. outputs[0].buffer.addEvent(pcm); } } } protected override void endSeekImpl(long seekTime) { ////////////////////////////////////////////////////////////////////////// // TODO: Anything you might need to do before each time play is pressed. // At this time, playTime is being set to seekTime. You may wish to reset // some internal timers, cancel currently playing notes or samples, things // like that. ////////////////////////////////////////////////////////////////////////// } protected override void endTickImpl(ArrayList parameterChanges) { ////////////////////////////////////////////////////////////////////////// // TODO: Explicitly handle pattern events if you so desire. See the score // machine for an example of this. ////////////////////////////////////////////////////////////////////////// } } } // TODO: (Developer) Add information here on the different events, their signatures and behaviours.