private static void testLFO(boolean shared, int instance, float freq, float delay, float delay2) throws Exception { SoftLowFrequencyOscillator lfo = shared?TestProcessControlLogic.lfo:new SoftLowFrequencyOscillator(); lfo.reset(); double[] lfo_freq = lfo.get(instance, "freq"); double[] lfo_delay = lfo.get(instance, "delay"); double[] lfo_delay2 = lfo.get(instance, "delay2"); double[] lfo_output = lfo.get(instance, null); lfo_freq[0] = freq; lfo_delay[0] = delay; lfo_delay2[0] = delay2; lfo.init(synth); // For delayCount amount time, the output LFO should be 0.5 int delayCount = (int) ((Math.pow(2, delay / 1200.0) * control_rate)); delayCount += (int) ((delay2 * control_rate) / 1000.0); for (int i = 0; i < delayCount; i++) { if (Math.abs(0.5 - lfo_output[0]) > 0.000001) throw new Exception("Incorrect LFO output (" +"0.5 != "+lfo_output[0]+")!"); lfo.processControlLogic(); } // After the delay the LFO should start oscillate // Let make sure output is accurate enough double p_step = (440.0 / control_rate) * Math.exp((freq - 6900.0) * (Math.log(2) / 1200.0)); double p = 0; for (int i = 0; i < 30; i++) { p += p_step; double predicted_output = 0.5 + Math.sin(p * 2 * Math.PI) * 0.5; if (Math.abs(predicted_output - lfo_output[0]) > 0.001) throw new Exception("Incorrect LFO output (" +predicted_output+" != "+lfo_output[0]+")!"); lfo.processControlLogic(); } }