提交 afab6000 编写于 作者: K kalli

6823446: Gervill SoftLowFrequencyOscillator fails when freq is set to 0 cent or 8.1758 Hz.

Reviewed-by: amenkov
上级 f1dee8fa
......@@ -45,6 +45,13 @@ public class SoftLowFrequencyOscillator implements SoftProcess {
private double sin_factor = 0;
private static double PI2 = 2.0 * Math.PI;
public SoftLowFrequencyOscillator() {
// If sin_step is 0 then sin_stepfreq must be -INF
for (int i = 0; i < sin_stepfreq.length; i++) {
sin_stepfreq[i] = Double.NEGATIVE_INFINITY;
}
}
public void reset() {
for (int i = 0; i < used_count; i++) {
out[i][0] = 0;
......@@ -53,7 +60,8 @@ public class SoftLowFrequencyOscillator implements SoftProcess {
freq[i][0] = 0;
delay_counter[i] = 0;
sin_phase[i] = 0;
sin_stepfreq[i] = 0;
// If sin_step is 0 then sin_stepfreq must be -INF
sin_stepfreq[i] = Double.NEGATIVE_INFINITY;
sin_step[i] = 0;
}
used_count = 0;
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@summary Test SoftLowFrequencyOscillator processControlLogic method */
import com.sun.media.sound.AudioSynthesizerPropertyInfo;
import com.sun.media.sound.SoftLowFrequencyOscillator;
import com.sun.media.sound.SoftSynthesizer;
public class TestProcessControlLogic {
private static float control_rate = 147f;
private static SoftSynthesizer synth = new SoftSynthesizer();
private static SoftLowFrequencyOscillator lfo = new SoftLowFrequencyOscillator();
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();
}
}
public static void main(String[] args) throws Exception {
// Get default control rate from synthesizer
AudioSynthesizerPropertyInfo[] p = synth.getPropertyInfo(null);
for (int i = 0; i < p.length; i++) {
if (p[i].name.equals("control rate")) {
control_rate = ((Float) p[i].value).floatValue();
break;
}
}
// Test LFO under various configurations
for (int instance = 0; instance < 3; instance++)
for (int d1 = -3000; d1 < 0; d1 += 1000)
for (int d2 = 0; d2 < 5000; d2 += 1000)
for (int fr = -1000; fr < 1000; fr += 100) {
testLFO(true, instance,
(fr == -1000) ? Float.NEGATIVE_INFINITY : fr,
(d1 == -3000) ? Float.NEGATIVE_INFINITY : d1,
d2);
testLFO(false, instance,
(fr == -1000) ? Float.NEGATIVE_INFINITY : fr,
(d1 == -3000) ? Float.NEGATIVE_INFINITY : d1,
d2);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册