Mercurial > hg > release > icedtea6-1.2
view overlays/openjdk/jdk/src/share/classes/com/sun/media/sound/SoftLowFrequencyOscillator.java @ 843:bcba163568ac
Integrate Gervill.
2008-04-30 Mark Wielaard <mark@klomp.org>
* Makefile.am (ICEDTEA_PATCHES): Add patches/icedtea-gervill.patch.
* Makefile.in: Regenerated.
* patches/icedtea-gervill.patch: New patch.
* overlays/openjdk/jdk/src/share/classes/com/sun/media/sound/*:
New Gervill files.
author | Mark Wielaard <mark@klomp.org> |
---|---|
date | Wed, 30 Apr 2008 22:09:08 +0200 |
parents | |
children |
line wrap: on
line source
/* * Copyright 2007 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. */ package com.sun.media.sound; /** * * LFO control signal generator. * * @version %I%, %E% * @author Karl Helgason */ public class SoftLowFrequencyOscillator implements SoftProcess { private int max_count = 10; private int used_count = 0; private double[][] out = new double[max_count][1]; private double[][] delay = new double[max_count][1]; private double[][] delay2 = new double[max_count][1]; private double[][] freq = new double[max_count][1]; private int[] delay_counter = new int[max_count]; private double[] sin_phase = new double[max_count]; private double[] sin_stepfreq = new double[max_count]; private double[] sin_step = new double[max_count]; private double control_time = 0; private double sin_factor = 0; private static double PI2 = 2.0 * Math.PI; public void reset() { for (int i = 0; i < used_count; i++) { out[i][0] = 0; delay[i][0] = 0; delay2[i][0] = 0; freq[i][0] = 0; delay_counter[i] = 0; sin_phase[i] = 0; sin_stepfreq[i] = 0; sin_step[i] = 0; } used_count = 0; } public void init(SoftSynthesizer synth) { control_time = 1.0 / synth.getControlRate(); sin_factor = control_time * 2 * Math.PI; for (int i = 0; i < used_count; i++) { delay_counter[i] = (int) (Math.pow(2, this.delay[i][0] / 1200.0) / control_time); delay_counter[i] += (int) (delay2[i][0] / (control_time * 1000)); } processControlLogic(); } public void processControlLogic() { for (int i = 0; i < used_count; i++) { if (delay_counter[i] > 0) { delay_counter[i]--; out[i][0] = 0.5; } else { double f = freq[i][0]; if(sin_stepfreq[i] != f) { sin_stepfreq[i] = f; double fr = 440.0 * Math.exp( (f - 6900.0) * (Math.log(2)/ 1200.0)); sin_step[i] = fr * sin_factor; } /* double fr = 440.0 * Math.pow(2.0, (freq[i][0] - 6900.0) / 1200.0); sin_phase[i] += fr * sin_factor; */ /* sin_phase[i] += sin_step[i]; while (sin_phase[i] > PI2) sin_phase[i] -= PI2; out[i][0] = 0.5 + Math.sin(sin_phase[i]) * 0.5; */ double p = sin_phase[i]; p += sin_step[i]; while (p > PI2) p -= PI2; out[i][0] = 0.5 + Math.sin(p) * 0.5; sin_phase[i] = p; } } } public double[] get(int instance, String name) { if (instance >= used_count) used_count = instance + 1; if (name == null) return out[instance]; if (name.equals("delay")) return delay[instance]; if (name.equals("delay2")) return delay2[instance]; if (name.equals("freq")) return freq[instance]; return null; } }