public GainFunction() { potentiometer = new UnitInputPort("PotentiometerInput"); input = new UnitInputPort("Input"); output = new UnitOutputPort("Output"); input.setDefault(0.0); potentiometer.setDefault(1.0); addPort(potentiometer); addPort(input); addPort(output); }
@Override public void generate(int start, int limit) { double[] wheelGain = potentiometer.getValues(); double[] inputSignal = input.getValues(); double[] outputs = output.getValues(); for (int i = start; i < limit; i++) { // Conversion of potentiometer in decibel, then bounded between 0 and 1 outputs[i] = inputSignal[i] * wheelGain[i]; // 20*Math.log(2*wheelGain[i]) / 12 } }
@Override public void generate(int start, int limit) { // Get signal arrays from ports. double[] inputs = input.getValues(); double[] outputs = output.getValues(); double[] amValues = am.getValues(); for (int i = start; i < limit; i++) { double amValWithGain = amValues[i] * 5 * DECIBEL_GAIN; // value from -5V to 5V // Do the math. outputs[i] = inputs[i] * ((amValWithGain == 0) ? 1.0 : amValWithGain); } }