aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/jsyn/unitgen
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/jsyn/unitgen')
-rw-r--r--src/com/jsyn/unitgen/Add.java50
-rw-r--r--src/com/jsyn/unitgen/AsymptoticRamp.java81
-rw-r--r--src/com/jsyn/unitgen/BrownNoise.java75
-rw-r--r--src/com/jsyn/unitgen/ChannelIn.java59
-rw-r--r--src/com/jsyn/unitgen/ChannelOut.java62
-rw-r--r--src/com/jsyn/unitgen/Circuit.java122
-rw-r--r--src/com/jsyn/unitgen/Compare.java38
-rw-r--r--src/com/jsyn/unitgen/ContinuousRamp.java91
-rw-r--r--src/com/jsyn/unitgen/CrossFade.java60
-rw-r--r--src/com/jsyn/unitgen/Delay.java57
-rw-r--r--src/com/jsyn/unitgen/Divide.java53
-rw-r--r--src/com/jsyn/unitgen/DualInTwoOut.java59
-rw-r--r--src/com/jsyn/unitgen/EdgeDetector.java44
-rw-r--r--src/com/jsyn/unitgen/EnvelopeAttackDecay.java145
-rw-r--r--src/com/jsyn/unitgen/EnvelopeDAHDSR.java294
-rw-r--r--src/com/jsyn/unitgen/ExponentialRamp.java104
-rw-r--r--src/com/jsyn/unitgen/FFT.java36
-rw-r--r--src/com/jsyn/unitgen/FFTBase.java86
-rw-r--r--src/com/jsyn/unitgen/FilterAllPass.java62
-rw-r--r--src/com/jsyn/unitgen/FilterBandPass.java44
-rw-r--r--src/com/jsyn/unitgen/FilterBandStop.java49
-rw-r--r--src/com/jsyn/unitgen/FilterBiquad.java156
-rw-r--r--src/com/jsyn/unitgen/FilterBiquadCommon.java99
-rw-r--r--src/com/jsyn/unitgen/FilterBiquadShelf.java111
-rw-r--r--src/com/jsyn/unitgen/FilterFourPoles.java185
-rw-r--r--src/com/jsyn/unitgen/FilterHighPass.java46
-rw-r--r--src/com/jsyn/unitgen/FilterHighShelf.java38
-rw-r--r--src/com/jsyn/unitgen/FilterLowPass.java65
-rw-r--r--src/com/jsyn/unitgen/FilterLowShelf.java40
-rw-r--r--src/com/jsyn/unitgen/FilterOnePole.java62
-rw-r--r--src/com/jsyn/unitgen/FilterOnePoleOneZero.java68
-rw-r--r--src/com/jsyn/unitgen/FilterOneZero.java65
-rw-r--r--src/com/jsyn/unitgen/FilterPeakingEQ.java68
-rw-r--r--src/com/jsyn/unitgen/FilterStateVariable.java120
-rw-r--r--src/com/jsyn/unitgen/FilterTwoPoles.java66
-rw-r--r--src/com/jsyn/unitgen/FilterTwoPolesTwoZeros.java79
-rw-r--r--src/com/jsyn/unitgen/FixedRateMonoReader.java52
-rw-r--r--src/com/jsyn/unitgen/FixedRateMonoWriter.java54
-rw-r--r--src/com/jsyn/unitgen/FixedRateStereoReader.java59
-rw-r--r--src/com/jsyn/unitgen/FixedRateStereoWriter.java60
-rw-r--r--src/com/jsyn/unitgen/FourWayFade.java94
-rw-r--r--src/com/jsyn/unitgen/FunctionEvaluator.java76
-rw-r--r--src/com/jsyn/unitgen/FunctionOscillator.java58
-rw-r--r--src/com/jsyn/unitgen/Grain.java89
-rw-r--r--src/com/jsyn/unitgen/GrainCommon.java32
-rw-r--r--src/com/jsyn/unitgen/GrainEnvelope.java52
-rw-r--r--src/com/jsyn/unitgen/GrainFarm.java178
-rw-r--r--src/com/jsyn/unitgen/GrainScheduler.java44
-rw-r--r--src/com/jsyn/unitgen/GrainSource.java36
-rw-r--r--src/com/jsyn/unitgen/GrainSourceSine.java51
-rw-r--r--src/com/jsyn/unitgen/IFFT.java36
-rw-r--r--src/com/jsyn/unitgen/ImpulseOscillator.java59
-rw-r--r--src/com/jsyn/unitgen/ImpulseOscillatorBL.java39
-rw-r--r--src/com/jsyn/unitgen/Integrate.java82
-rw-r--r--src/com/jsyn/unitgen/InterpolatingDelay.java117
-rw-r--r--src/com/jsyn/unitgen/Latch.java53
-rw-r--r--src/com/jsyn/unitgen/LatchZeroCrossing.java72
-rw-r--r--src/com/jsyn/unitgen/LineIn.java51
-rw-r--r--src/com/jsyn/unitgen/LineOut.java57
-rw-r--r--src/com/jsyn/unitgen/LinearRamp.java94
-rw-r--r--src/com/jsyn/unitgen/Maximum.java42
-rw-r--r--src/com/jsyn/unitgen/Minimum.java43
-rw-r--r--src/com/jsyn/unitgen/MixerMono.java77
-rw-r--r--src/com/jsyn/unitgen/MixerMonoRamped.java54
-rw-r--r--src/com/jsyn/unitgen/MixerStereo.java94
-rw-r--r--src/com/jsyn/unitgen/MixerStereoRamped.java71
-rw-r--r--src/com/jsyn/unitgen/MonoStreamWriter.java49
-rw-r--r--src/com/jsyn/unitgen/MorphingOscillatorBL.java72
-rw-r--r--src/com/jsyn/unitgen/MultiPassThrough.java70
-rw-r--r--src/com/jsyn/unitgen/Multiply.java64
-rw-r--r--src/com/jsyn/unitgen/MultiplyAdd.java57
-rw-r--r--src/com/jsyn/unitgen/Pan.java64
-rw-r--r--src/com/jsyn/unitgen/PanControl.java61
-rw-r--r--src/com/jsyn/unitgen/ParabolicEnvelope.java110
-rw-r--r--src/com/jsyn/unitgen/PassThrough.java38
-rw-r--r--src/com/jsyn/unitgen/PeakFollower.java87
-rw-r--r--src/com/jsyn/unitgen/PhaseShifter.java90
-rw-r--r--src/com/jsyn/unitgen/PinkNoise.java128
-rw-r--r--src/com/jsyn/unitgen/PitchDetector.java115
-rw-r--r--src/com/jsyn/unitgen/PitchToFrequency.java26
-rw-r--r--src/com/jsyn/unitgen/PowerOfTwo.java108
-rw-r--r--src/com/jsyn/unitgen/PulseOscillator.java59
-rw-r--r--src/com/jsyn/unitgen/PulseOscillatorBL.java61
-rw-r--r--src/com/jsyn/unitgen/RaisedCosineEnvelope.java73
-rw-r--r--src/com/jsyn/unitgen/RangeConverter.java50
-rw-r--r--src/com/jsyn/unitgen/RectangularWindow.java39
-rw-r--r--src/com/jsyn/unitgen/RedNoise.java80
-rw-r--r--src/com/jsyn/unitgen/SampleGrainFarm.java71
-rw-r--r--src/com/jsyn/unitgen/SampleGrainSource.java69
-rw-r--r--src/com/jsyn/unitgen/SawtoothOscillator.java47
-rw-r--r--src/com/jsyn/unitgen/SawtoothOscillatorBL.java65
-rw-r--r--src/com/jsyn/unitgen/SawtoothOscillatorDPW.java76
-rw-r--r--src/com/jsyn/unitgen/SchmidtTrigger.java83
-rw-r--r--src/com/jsyn/unitgen/Select.java56
-rw-r--r--src/com/jsyn/unitgen/SequentialDataReader.java38
-rw-r--r--src/com/jsyn/unitgen/SequentialDataWriter.java44
-rw-r--r--src/com/jsyn/unitgen/SineOscillator.java85
-rw-r--r--src/com/jsyn/unitgen/SineOscillatorPhaseModulated.java74
-rw-r--r--src/com/jsyn/unitgen/SpectralFFT.java130
-rw-r--r--src/com/jsyn/unitgen/SpectralFilter.java130
-rw-r--r--src/com/jsyn/unitgen/SpectralIFFT.java92
-rw-r--r--src/com/jsyn/unitgen/SpectralProcessor.java73
-rw-r--r--src/com/jsyn/unitgen/SquareOscillator.java49
-rw-r--r--src/com/jsyn/unitgen/SquareOscillatorBL.java48
-rw-r--r--src/com/jsyn/unitgen/StereoStreamWriter.java53
-rw-r--r--src/com/jsyn/unitgen/StochasticGrainScheduler.java43
-rw-r--r--src/com/jsyn/unitgen/Subtract.java42
-rw-r--r--src/com/jsyn/unitgen/TriangleOscillator.java59
-rw-r--r--src/com/jsyn/unitgen/TunableFilter.java41
-rw-r--r--src/com/jsyn/unitgen/TwoInDualOut.java56
-rw-r--r--src/com/jsyn/unitgen/UnitBinaryOperator.java41
-rw-r--r--src/com/jsyn/unitgen/UnitFilter.java47
-rw-r--r--src/com/jsyn/unitgen/UnitGate.java54
-rw-r--r--src/com/jsyn/unitgen/UnitGenerator.java355
-rw-r--r--src/com/jsyn/unitgen/UnitOscillator.java93
-rw-r--r--src/com/jsyn/unitgen/UnitSink.java43
-rw-r--r--src/com/jsyn/unitgen/UnitSource.java30
-rw-r--r--src/com/jsyn/unitgen/UnitStreamWriter.java53
-rw-r--r--src/com/jsyn/unitgen/UnitVoice.java59
-rw-r--r--src/com/jsyn/unitgen/Unzipper.java47
-rw-r--r--src/com/jsyn/unitgen/VariableRateDataReader.java29
-rw-r--r--src/com/jsyn/unitgen/VariableRateMonoReader.java115
-rw-r--r--src/com/jsyn/unitgen/VariableRateStereoReader.java113
-rw-r--r--src/com/jsyn/unitgen/WhiteNoise.java56
-rw-r--r--src/com/jsyn/unitgen/ZeroCrossingCounter.java61
125 files changed, 0 insertions, 9136 deletions
diff --git a/src/com/jsyn/unitgen/Add.java b/src/com/jsyn/unitgen/Add.java
deleted file mode 100644
index 5a2a24c..0000000
--- a/src/com/jsyn/unitgen/Add.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * This unit performs a signed addition on its two inputs. <br>
- *
- * <pre>
- * output = inputA + inputB
- * </pre>
- *
- * <br>
- * Note that signals connected to an InputPort are automatically added together so you may not need
- * this unit.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see MultiplyAdd
- * @see Subtract
- */
-public class Add extends UnitBinaryOperator {
-
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
-
- // System.out.println("adder = " + this);
- // System.out.println("A = " + aValues[0]);
- for (int i = start; i < limit; i++) {
- outputs[i] = aValues[i] + bValues[i];
- }
- // System.out.println("add out = " + outputs[0]);
- }
-}
diff --git a/src/com/jsyn/unitgen/AsymptoticRamp.java b/src/com/jsyn/unitgen/AsymptoticRamp.java
deleted file mode 100644
index 8b51294..0000000
--- a/src/com/jsyn/unitgen/AsymptoticRamp.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Output approaches Input exponentially. This unit provides a slowly changing value that approaches
- * its Input value exponentially. The equation is:
- *
- * <PRE>
- * Output = Output + Rate * (Input - Output);
- * </PRE>
- *
- * Note that the output may never reach the value of the input. It approaches the input
- * asymptotically. The Rate is calculated internally based on the value on the halfLife port. Rate
- * is generally just slightly less than 1.0.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see LinearRamp
- * @see ExponentialRamp
- * @see ContinuousRamp
- */
-public class AsymptoticRamp extends UnitFilter {
- public UnitVariablePort current;
- public UnitInputPort halfLife;
- private double previousHalfLife = -1.0;
- private double decayScalar = 0.99;
-
- /* Define Unit Ports used by connect() and set(). */
- public AsymptoticRamp() {
- addPort(halfLife = new UnitInputPort(1, "HalfLife", 0.1));
- addPort(current = new UnitVariablePort("Current"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
- double[] inputs = input.getValues();
- double currentHalfLife = halfLife.getValues()[0];
- double currentValue = current.getValue();
- double inputValue = currentValue;
-
- if (currentHalfLife != previousHalfLife) {
- decayScalar = this.convertHalfLifeToMultiplier(currentHalfLife);
- previousHalfLife = currentHalfLife;
- }
-
- for (int i = start; i < limit; i++) {
- inputValue = inputs[i];
- currentValue = currentValue + decayScalar * (inputValue - currentValue);
- outputs[i] = currentValue;
- }
-
- /*
- * When current gets close to input, set current to input to prevent FP underflow, which can
- * cause a severe performance degradation in 'C'.
- */
- if (Math.abs(inputValue - currentValue) < VERY_SMALL_FLOAT) {
- currentValue = inputValue;
- }
-
- current.setValue(currentValue);
- }
-}
diff --git a/src/com/jsyn/unitgen/BrownNoise.java b/src/com/jsyn/unitgen/BrownNoise.java
deleted file mode 100644
index e70b7f4..0000000
--- a/src/com/jsyn/unitgen/BrownNoise.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.util.PseudoRandom;
-
-/**
- * BrownNoise unit. This unit uses a pseudo-random number generator to produce a noise related to
- * Brownian Motion. A DC blocker is used to prevent runaway drift.
- *
- * <pre>
- * <code>
- * output = (previous * (1.0 - damping)) + (random * amplitude)
- * </code>
- * </pre>
- *
- * The output drifts quite a bit and will generally exceed the range of +/1 amplitude.
- *
- * @author (C) 1997-2011 Phil Burk, Mobileer Inc
- * @see WhiteNoise
- * @see RedNoise
- * @see PinkNoise
- */
-public class BrownNoise extends UnitGenerator implements UnitSource {
- private PseudoRandom randomNum;
- /** Increasing the damping will effectively increase the cutoff
- * frequency of a high pass filter that is used to block DC bias.
- * Warning: setting this too close to zero can result in very large output values.
- */
- public UnitInputPort damping;
- public UnitInputPort amplitude;
- public UnitOutputPort output;
- private double previous;
-
- public BrownNoise() {
- randomNum = new PseudoRandom();
- addPort(damping = new UnitInputPort("Damping"));
- damping.setup(0.0001, 0.01, 0.1);
- addPort(amplitude = new UnitInputPort("Amplitude", UnitOscillator.DEFAULT_AMPLITUDE));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- double damper = 1.0 - damping.getValues()[0];
-
- for (int i = start; i < limit; i++) {
- double r = randomNum.nextRandomDouble() * amplitudes[i];
- outputs[i] = previous = (damper * previous) + r;
- }
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-}
diff --git a/src/com/jsyn/unitgen/ChannelIn.java b/src/com/jsyn/unitgen/ChannelIn.java
deleted file mode 100644
index c440b4f..0000000
--- a/src/com/jsyn/unitgen/ChannelIn.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Provides access to one specific channel of the audio input. For ChannelIn to work you must call
- * the {@link com.jsyn.Synthesizer} start() method with numInputChannels &gt; 0.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see ChannelOut
- * @see LineIn
- */
-public class ChannelIn extends UnitGenerator {
- public UnitOutputPort output;
- private int channelIndex;
-
- public ChannelIn() {
- this(0);
- }
-
- public ChannelIn(int channelIndex) {
- addPort(output = new UnitOutputPort());
- setChannelIndex(channelIndex);
- }
-
- public int getChannelIndex() {
- return channelIndex;
- }
-
- public void setChannelIndex(int channelIndex) {
- this.channelIndex = channelIndex;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues(0);
- double[] buffer = synthesisEngine.getInputBuffer(channelIndex);
- for (int i = start; i < limit; i++) {
- outputs[i] = buffer[i];
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/ChannelOut.java b/src/com/jsyn/unitgen/ChannelOut.java
deleted file mode 100644
index 8ef0677..0000000
--- a/src/com/jsyn/unitgen/ChannelOut.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Provides access to one channel of the audio output.
- * For more than two channels you must call
- * the {@link com.jsyn.Synthesizer} start() method with numOutputChannels &gt; 2.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see ChannelIn
- */
-public class ChannelOut extends UnitGenerator {
- public UnitInputPort input;
- private int channelIndex;
-
- public ChannelOut() {
- addPort(input = new UnitInputPort("Input"));
- }
-
- public int getChannelIndex() {
- return channelIndex;
- }
-
- public void setChannelIndex(int channelIndex) {
- this.channelIndex = channelIndex;
- }
-
- /**
- * This unit won't do anything unless you start() it.
- */
- @Override
- public boolean isStartRequired() {
- return true;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues(0);
- double[] buffer = synthesisEngine.getOutputBuffer(channelIndex);
- for (int i = start; i < limit; i++) {
- buffer[i] += inputs[i];
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Circuit.java b/src/com/jsyn/unitgen/Circuit.java
deleted file mode 100644
index 01cb860..0000000
--- a/src/com/jsyn/unitgen/Circuit.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-
-import com.jsyn.engine.SynthesisEngine;
-import com.jsyn.ports.UnitPort;
-
-/**
- * Contains a list of units that are executed together.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class Circuit extends UnitGenerator {
- private ArrayList<UnitGenerator> units = new ArrayList<UnitGenerator>();
-
- private final LinkedHashMap<String, UnitPort> portAliases = new LinkedHashMap<String, UnitPort>();
-
- @Override
- public void generate(int start, int limit) {
- for (UnitGenerator unit : units) {
- unit.generate(start, limit);
- }
- }
-
- /**
- * Call flattenOutputs on subunits. Flatten output ports so we don't output a changing signal
- * when stopped.
- */
- @Override
- public void flattenOutputs() {
- for (UnitGenerator unit : units) {
- unit.flattenOutputs();
- }
- }
-
- /**
- * Call setEnabled on subunits.
- */
- @Override
- public void setEnabled(boolean enabled) {
- super.setEnabled(enabled);
- for (UnitGenerator unit : units) {
- unit.setEnabled(enabled);
- }
- }
-
- /**
- * @deprecated ignored, frameRate comes from the SynthesisEngine
- * @param frameRate
- */
- @Deprecated
- @Override
- public void setFrameRate(int frameRate) {
- super.setFrameRate(frameRate);
- for (UnitGenerator unit : units) {
- unit.setFrameRate(frameRate);
- }
- }
-
- @Override
- public void setSynthesisEngine(SynthesisEngine engine) {
- super.setSynthesisEngine(engine);
- for (UnitGenerator unit : units) {
- unit.setSynthesisEngine(engine);
- }
- }
-
- /** Add a unit to the circuit. */
- public void add(UnitGenerator unit) {
- units.add(unit);
- unit.setCircuit(this);
- // Propagate circuit properties down into subunits.
- unit.setEnabled(isEnabled());
- }
-
- public void usePreset(int presetIndex) {
- }
-
-
- /**
- * Add an alternate name for looking up a port.
- * @param port
- * @param alias
- */
- public void addPortAlias(UnitPort port, String alias) {
- // Store in a hash table by an alternate name.
- portAliases.put(alias.toLowerCase(), port);
- }
-
-
- /**
- * Case-insensitive search for a port by its name or alias.
- * @param portName
- * @return matching port or null
- */
- @Override
- public UnitPort getPortByName(String portName) {
- UnitPort port = super.getPortByName(portName);
- if (port == null) {
- port = portAliases.get(portName.toLowerCase());
- }
- return port;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Compare.java b/src/com/jsyn/unitgen/Compare.java
deleted file mode 100644
index 7de2e53..0000000
--- a/src/com/jsyn/unitgen/Compare.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- *
- Output 1.0 if inputA &gt; inputB. Otherwise output 0.0.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Maximum
- */
-public class Compare extends UnitBinaryOperator {
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = (aValues[i] > bValues[i]) ? 1.0 : 0.0;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/ContinuousRamp.java b/src/com/jsyn/unitgen/ContinuousRamp.java
deleted file mode 100644
index dd90445..0000000
--- a/src/com/jsyn/unitgen/ContinuousRamp.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * A ramp whose function over time is continuous in value and in slope. Also called an "S curve".
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see LinearRamp
- * @see ExponentialRamp
- * @see AsymptoticRamp
- */
-public class ContinuousRamp extends UnitFilter {
- public UnitVariablePort current;
- /**
- * Time it takes to get from current value to input value when input is changed. Default value
- * is 1.0 seconds.
- */
- public UnitInputPort time;
- private double previousInput = Double.MIN_VALUE;
- // Coefficients for cubic polynomial.
- private double a;
- private double b;
- private double d;
- private int framesLeft;
-
- /* Define Unit Ports used by connect() and set(). */
- public ContinuousRamp() {
- addPort(time = new UnitInputPort(1, "Time", 1.0));
- addPort(current = new UnitVariablePort("Current"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
- double[] inputs = input.getValues();
- double currentTime = time.getValues()[0];
- double currentValue = current.getValue();
- double inputValue = currentValue;
-
- for (int i = start; i < limit; i++) {
- inputValue = inputs[i];
- double x;
- if (inputValue != previousInput) {
- x = framesLeft;
- // Calculate coefficients.
- double currentSlope = x * ((3 * a * x) + (2 * b));
-
- framesLeft = (int) (getSynthesisEngine().getFrameRate() * currentTime);
- if (framesLeft < 1) {
- framesLeft = 1;
- }
- x = framesLeft;
- // Calculate coefficients.
- d = inputValue;
- double xsq = x * x;
- b = ((3 * currentValue) - (currentSlope * x) - (3 * d)) / xsq;
- a = (currentSlope - (2 * b * x)) / (3 * xsq);
- previousInput = inputValue;
- }
-
- if (framesLeft > 0) {
- x = --framesLeft;
- // Cubic polynomial. c==0
- currentValue = (x * (x * ((x * a) + b))) + d;
- }
-
- outputs[i] = currentValue;
- }
-
- current.setValue(currentValue);
- }
-}
diff --git a/src/com/jsyn/unitgen/CrossFade.java b/src/com/jsyn/unitgen/CrossFade.java
deleted file mode 100644
index 4375fa6..0000000
--- a/src/com/jsyn/unitgen/CrossFade.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Linear CrossFade between parts of the input.
- * <P>
- * Mix input[0] and input[1] based on the value of "fade". When fade is -1, output is all input[0].
- * When fade is 0, output is half input[0] and half input[1]. When fade is +1, output is all
- * input[1].
- * <P>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Pan
- */
-public class CrossFade extends UnitGenerator {
- public UnitInputPort input;
- public UnitInputPort fade;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public CrossFade() {
- addPort(input = new UnitInputPort(2, "Input"));
- addPort(fade = new UnitInputPort("Fade"));
- fade.setup(-1.0, 0.0, 1.0);
- addPort(output = new UnitOutputPort());
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] input0s = input.getValues(0);
- double[] input1s = input.getValues(1);
- double[] fades = fade.getValues();
- double[] outputs = output.getValues();
- for (int i = start; i < limit; i++) {
- // Scale and offset to 0.0 to 1.0 range.
- double gain = (fades[i] * 0.5) + 0.5;
- outputs[i] = (input0s[i] * (1.0 - gain)) + (input1s[i] * gain);
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Delay.java b/src/com/jsyn/unitgen/Delay.java
deleted file mode 100644
index aa450a9..0000000
--- a/src/com/jsyn/unitgen/Delay.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Simple non-interpolating delay. The delay line must be allocated by calling allocate(n).
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see InterpolatingDelay
- */
-
-public class Delay extends UnitFilter {
- private float[] buffer;
- private int cursor;
- private int numSamples;
-
- /**
- * Allocate an internal array for the delay line.
- *
- * @param numSamples
- */
- public void allocate(int numSamples) {
- this.numSamples = numSamples;
- buffer = new float[numSamples];
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = buffer[cursor];
- buffer[cursor] = (float) inputs[i];
- cursor += 1;
- if (cursor >= numSamples) {
- cursor = 0;
- }
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Divide.java b/src/com/jsyn/unitgen/Divide.java
deleted file mode 100644
index cddcd7c..0000000
--- a/src/com/jsyn/unitgen/Divide.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * This unit divides its two inputs. <br>
- *
- * <pre>
- * output = inputA / inputB
- * </pre>
- *
- * <br>
- * Note that this unit is protected from dividing by zero. But you can still get some very big
- * outputs.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Multiply
- * @see Subtract
- */
-public class Divide extends UnitBinaryOperator {
-
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
- for (int i = start; i < limit; i++) {
- /* Prevent divide by zero crash. */
- double b = bValues[i];
- if (b == 0.0) {
- b = 0.0000001;
- }
-
- outputs[i] = aValues[i] / b;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/DualInTwoOut.java b/src/com/jsyn/unitgen/DualInTwoOut.java
deleted file mode 100644
index ec7dff5..0000000
--- a/src/com/jsyn/unitgen/DualInTwoOut.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * This unit splits a dual (stereo) input to two discrete outputs. <br>
- *
- * <pre>
- * outputA = input[0];
- * outputB = input[1];
- * </pre>
- *
- * <br>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- */
-
-public class DualInTwoOut extends UnitGenerator {
- public UnitInputPort input;
- public UnitOutputPort outputA;
- public UnitOutputPort outputB;
-
- public DualInTwoOut() {
- addPort(input = new UnitInputPort(2, "Input"));
- addPort(outputA = new UnitOutputPort("OutputA"));
- addPort(outputB = new UnitOutputPort("OutputB"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] input0s = input.getValues(0);
- double[] input1s = input.getValues(1);
- double[] outputAs = outputA.getValues();
- double[] outputBs = outputB.getValues();
-
- for (int i = start; i < limit; i++) {
- outputAs[i] = input0s[i];
- outputBs[i] = input1s[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/EdgeDetector.java b/src/com/jsyn/unitgen/EdgeDetector.java
deleted file mode 100644
index e314f7d..0000000
--- a/src/com/jsyn/unitgen/EdgeDetector.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Output 1.0 if the input crosses from zero while rising. Otherwise output zero. The output is a
- * single sample wide impulse. This can be used with a Latch to implement a "sample and hold"
- * circuit.
- *
- * @author (C) 1997-2010 Phil Burk, Mobileer Inc
- * @see Latch
- */
-public class EdgeDetector extends UnitFilter {
- private double previous = 0.0;
-
- public EdgeDetector() {
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- double in = inputs[i];
- outputs[i] = ((previous <= 0.0) && (in > 0.0)) ? 1.0 : 0.0;
- previous = in;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/EnvelopeAttackDecay.java b/src/com/jsyn/unitgen/EnvelopeAttackDecay.java
deleted file mode 100644
index db3ecaa..0000000
--- a/src/com/jsyn/unitgen/EnvelopeAttackDecay.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.SynthesisEngine;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Two stage Attack/Decay envelope that is triggered by an input level greater than THRESHOLD. This
- * does not sustain.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public class EnvelopeAttackDecay extends UnitGate {
- public static final double THRESHOLD = 0.01;
- private static final double MIN_DURATION = (1.0 / 100000.0);
-
- /**
- * Time in seconds for the rising stage of the envelope to go from 0.0 to 1.0. The attack is a
- * linear ramp.
- */
- public UnitInputPort attack;
- /**
- * Time in seconds for the falling stage to go from 0 dB to -90 dB.
- */
- public UnitInputPort decay;
-
- public UnitInputPort amplitude;
-
- private enum State {
- IDLE, ATTACKING, DECAYING
- }
-
- private State state = State.IDLE;
- private double scaler = 1.0;
- private double level;
- private double increment;
-
- public EnvelopeAttackDecay() {
- super();
- addPort(attack = new UnitInputPort("Attack"));
- attack.setup(0.001, 0.05, 8.0);
- addPort(decay = new UnitInputPort("Decay"));
- decay.setup(0.001, 0.2, 8.0);
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- startIdle();
- }
-
- public void export(Circuit circuit, String prefix) {
- circuit.addPort(attack, prefix + attack.getName());
- circuit.addPort(decay, prefix + decay.getName());
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit;) {
- boolean triggered = input.checkGate(i);
- switch (state) {
- case IDLE:
- for (; i < limit; i++) {
- outputs[i] = level;
- if (triggered) {
- startAttack(i);
- break;
- }
- }
- break;
- case ATTACKING:
- for (; i < limit; i++) {
- // Increment first so we can render fast attacks.
- level += increment;
- if (level >= 1.0) {
- level = 1.0;
- outputs[i] = level * amplitudes[i];
- startDecay(i);
- break;
- }
- outputs[i] = level * amplitudes[i];
- }
- break;
- case DECAYING:
- for (; i < limit; i++) {
- outputs[i] = level * amplitudes[i];
- level *= scaler;
- if (triggered) {
- startAttack(i);
- break;
- } else if (level < SynthesisEngine.DB90) {
- input.checkAutoDisable();
- startIdle();
- break;
- }
- }
- break;
- }
- }
- }
-
- private void startIdle() {
- state = State.IDLE;
- level = 0.0;
- }
-
- private void startAttack(int i) {
- double[] attacks = attack.getValues();
- double duration = attacks[i];
- if (duration < MIN_DURATION) {
- level = 1.0;
- startDecay(i);
- } else {
- // assume going from 0.0 to 1.0 even if retriggering
- increment = getFramePeriod() / duration;
- state = State.ATTACKING;
- }
- }
-
- private void startDecay(int i) {
- double[] decays = decay.getValues();
- double duration = decays[i];
- if (duration < MIN_DURATION) {
- startIdle();
- } else {
- scaler = getSynthesisEngine().convertTimeToExponentialScaler(duration);
- state = State.DECAYING;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/EnvelopeDAHDSR.java b/src/com/jsyn/unitgen/EnvelopeDAHDSR.java
deleted file mode 100644
index c5ebe83..0000000
--- a/src/com/jsyn/unitgen/EnvelopeDAHDSR.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright 2010 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.SegmentedEnvelope;
-import com.jsyn.engine.SynthesisEngine;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Six stage envelope similar to an ADSR. DAHDSR is like an ADSR but with an additional Delay stage
- * before the attack, and a Hold stage after the Attack. If Delay and Hold are both set to zero then
- * it will act like an ADSR. The envelope is triggered when the input goes above THRESHOLD. The
- * envelope is released when the input goes below THRESHOLD. The THRESHOLD is currently 0.01 but may
- * change so it would be best to use an input signal that went from 0 to 1. Mathematically an
- * exponential Release will never reach 0.0. But when it reaches -96 dB the DAHDSR just sets its
- * output to 0.0 and stops. There is an example program in the ZIP archive called HearDAHDSR. It
- * drives a DAHDSR with a square wave.
- *
- * @author Phil Burk (C) 2010 Mobileer Inc
- * @see SegmentedEnvelope
- */
-public class EnvelopeDAHDSR extends UnitGate implements UnitSource {
- private static final double MIN_DURATION = (1.0 / 100000.0);
-
- /**
- * Time in seconds for first stage of the envelope, before the attack. Typically zero.
- */
- public UnitInputPort delay;
- /**
- * Time in seconds for the rising stage of the envelope to go from 0.0 to 1.0. The attack is a
- * linear ramp.
- */
- public UnitInputPort attack;
- /** Time in seconds for the plateau between the attack and decay stages. */
- public UnitInputPort hold;
- /**
- * Time in seconds for the falling stage to go from 0 dB to -90 dB. The decay stage will stop at
- * the sustain level. But we calculate the time to fall to -90 dB so that the decay
- * <em>rate</em> will be unaffected by the sustain level.
- */
- public UnitInputPort decay;
- /**
- * Level for the sustain stage. The envelope will hold here until the input goes to zero or
- * less. This should be set between 0.0 and 1.0.
- */
- public UnitInputPort sustain;
- /**
- * Time in seconds to go from 0 dB to -90 dB. This stage is triggered when the input goes to
- * zero or less. The release stage will start from the sustain level. But we calculate the time
- * to fall from full amplitude so that the release <em>rate</em> will be unaffected by the
- * sustain level.
- */
- public UnitInputPort release;
- public UnitInputPort amplitude;
-
- enum State {
- IDLE, DELAYING, ATTACKING, HOLDING, DECAYING, SUSTAINING, RELEASING
- }
-
- private State state = State.IDLE;
- private double countdown;
- private double scaler = 1.0;
- private double level;
- private double increment;
-
- public EnvelopeDAHDSR() {
- super();
- addPort(delay = new UnitInputPort("Delay", 0.0));
- delay.setup(0.0, 0.0, 2.0);
- addPort(attack = new UnitInputPort("Attack", 0.1));
- attack.setup(0.01, 0.1, 8.0);
- addPort(hold = new UnitInputPort("Hold", 0.0));
- hold.setup(0.0, 0.0, 2.0);
- addPort(decay = new UnitInputPort("Decay", 0.2));
- decay.setup(0.01, 0.2, 8.0);
- addPort(sustain = new UnitInputPort("Sustain", 0.5));
- sustain.setup(0.0, 0.5, 1.0);
- addPort(release = new UnitInputPort("Release", 0.3));
- release.setup(0.01, 0.3, 8.0);
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] sustains = sustain.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit;) {
- boolean triggered = input.checkGate(i);
- switch (state) {
- case IDLE:
- for (; i < limit; i++) {
- outputs[i] = level * amplitudes[i];
- if (triggered) {
- startDelay(i);
- break;
- }
- }
- break;
-
- case DELAYING:
- for (; i < limit; i++) {
- outputs[i] = level * amplitudes[i];
- if (input.isOff()) {
- startRelease(i);
- break;
- } else {
- countdown -= 1;
- if (countdown <= 0) {
- startAttack(i);
- break;
- }
- }
- }
- break;
-
- case ATTACKING:
- for (; i < limit; i++) {
- // Increment first so we can render fast attacks.
- level += increment;
- if (level >= 1.0) {
- level = 1.0;
- outputs[i] = level * amplitudes[i];
- startHold(i);
- break;
- } else {
- outputs[i] = level * amplitudes[i];
- if (input.isOff()) {
- startRelease(i);
- break;
- }
- }
- }
- break;
-
- case HOLDING:
- for (; i < limit; i++) {
- outputs[i] = amplitudes[i]; // level is 1.0
- countdown -= 1;
- if (countdown <= 0) {
- startDecay(i);
- break;
- } else if (input.isOff()) {
- startRelease(i);
- break;
- }
- }
- break;
-
- case DECAYING:
- for (; i < limit; i++) {
- outputs[i] = level * amplitudes[i];
- level *= scaler; // exponential decay
- if (triggered) {
- startDelay(i);
- break;
- } else if (level < sustains[i]) {
- level = sustains[i];
- startSustain(i);
- break;
- } else if (level < SynthesisEngine.DB96) {
- input.checkAutoDisable();
- startIdle();
- break;
- } else if (input.isOff()) {
- startRelease(i);
- break;
- }
- }
- break;
-
- case SUSTAINING:
- for (; i < limit; i++) {
- level = sustains[i];
- outputs[i] = level * amplitudes[i];
- if (triggered) {
- startDelay(i);
- break;
- } else if (input.isOff()) {
- startRelease(i);
- break;
- }
- }
- break;
-
- case RELEASING:
- for (; i < limit; i++) {
- outputs[i] = level * amplitudes[i];
- level *= scaler; // exponential decay
- if (triggered) {
- startDelay(i);
- break;
- } else if (level < SynthesisEngine.DB96) {
- input.checkAutoDisable();
- startIdle();
- break;
- }
- }
- break;
- }
- }
- }
-
- private void startIdle() {
- state = State.IDLE;
- level = 0.0;
- }
-
- private void startDelay(int i) {
- double[] delays = delay.getValues();
- if (delays[i] <= 0.0) {
- startAttack(i);
- } else {
- countdown = (int) (delays[i] * getFrameRate());
- state = State.DELAYING;
- }
- }
-
- private void startAttack(int i) {
- double[] attacks = attack.getValues();
- double duration = attacks[i];
- if (duration < MIN_DURATION) {
- level = 1.0;
- startHold(i);
- } else {
- increment = getFramePeriod() / duration;
- state = State.ATTACKING;
- }
- }
-
- private void startHold(int i) {
- double[] holds = hold.getValues();
- if (holds[i] <= 0.0) {
- startDecay(i);
- } else {
- countdown = (int) (holds[i] * getFrameRate());
- state = State.HOLDING;
- }
- }
-
- private void startDecay(int i) {
- double[] decays = decay.getValues();
- double duration = decays[i];
- if (duration < MIN_DURATION) {
- startSustain(i);
- } else {
- scaler = getSynthesisEngine().convertTimeToExponentialScaler(duration);
- state = State.DECAYING;
- }
- }
-
- private void startSustain(int i) {
- state = State.SUSTAINING;
- }
-
- private void startRelease(int i) {
- double[] releases = release.getValues();
- double duration = releases[i];
- if (duration < MIN_DURATION) {
- duration = MIN_DURATION;
- }
- scaler = getSynthesisEngine().convertTimeToExponentialScaler(duration);
- state = State.RELEASING;
- }
-
- public void export(Circuit circuit, String prefix) {
- circuit.addPort(attack, prefix + attack.getName());
- circuit.addPort(decay, prefix + decay.getName());
- circuit.addPort(sustain, prefix + sustain.getName());
- circuit.addPort(release, prefix + release.getName());
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/ExponentialRamp.java b/src/com/jsyn/unitgen/ExponentialRamp.java
deleted file mode 100644
index 36159b4..0000000
--- a/src/com/jsyn/unitgen/ExponentialRamp.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2010 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Output approaches Input exponentially and will reach it in the specified time.
- *
- * @author Phil Burk (C) 2010 Mobileer Inc
- * @version 016
- * @see LinearRamp
- * @see AsymptoticRamp
- * @see ContinuousRamp
- */
-public class ExponentialRamp extends UnitFilter {
- public UnitInputPort time;
- public UnitVariablePort current;
-
- private double target;
- private double timeHeld = 0.0;
- private double scaler = 1.0;
-
- public ExponentialRamp() {
- addPort(time = new UnitInputPort("Time"));
- input.setup(0.0001, 1.0, 1.0);
- addPort(current = new UnitVariablePort("Current", 1.0));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
- double currentInput = input.getValues()[0];
- double currentTime = time.getValues()[0];
- double currentValue = current.getValue();
-
- if (currentTime != timeHeld) {
- scaler = convertTimeToExponentialScaler(currentTime, currentValue, currentInput);
- timeHeld = currentTime;
- }
-
- // If input has changed, start new segment.
- // Equality check is OK because we set them exactly equal below.
- if (currentInput != target) {
- scaler = convertTimeToExponentialScaler(currentTime, currentValue, currentInput);
- target = currentInput;
- }
-
- if (currentValue < target) {
- // Going up.
- for (int i = start; i < limit; i++) {
- currentValue = currentValue * scaler;
- if (currentValue > target) {
- currentValue = target;
- scaler = 1.0;
- }
- outputs[i] = currentValue;
- }
- } else if (currentValue > target) {
- // Going down.
- for (int i = start; i < limit; i++) {
- currentValue = currentValue * scaler;
- if (currentValue < target) {
- currentValue = target;
- scaler = 1.0;
- }
- outputs[i] = currentValue;
- }
-
- } else if (currentValue == target) {
- for (int i = start; i < limit; i++) {
- outputs[i] = target;
- }
- }
-
- current.setValue(currentValue);
- }
-
- private double convertTimeToExponentialScaler(double duration, double source, double target) {
- double product = source * target;
- if (product <= 0.0000001) {
- throw new IllegalArgumentException(
- "Exponential ramp crosses zero or gets too close to zero.");
- }
- // Calculate scaler so that scaler^frames = target/source
- double numFrames = duration * getFrameRate();
- return Math.pow((target / source), (1.0 / numFrames));
- }
-}
diff --git a/src/com/jsyn/unitgen/FFT.java b/src/com/jsyn/unitgen/FFT.java
deleted file mode 100644
index 63fce50..0000000
--- a/src/com/jsyn/unitgen/FFT.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Periodically transform the complex input signal using an FFT to a complex spectral stream. This
- * is probably not as useful as the SpectralFFT, which outputs complete spectra.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @see IFFT
- * @see SpectralFFT
- */
-public class FFT extends FFTBase {
- public FFT() {
- super();
- }
-
- @Override
- protected int getSign() {
- return 1; // 1 for FFT
- }
-}
diff --git a/src/com/jsyn/unitgen/FFTBase.java b/src/com/jsyn/unitgen/FFTBase.java
deleted file mode 100644
index 055c04b..0000000
--- a/src/com/jsyn/unitgen/FFTBase.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.Spectrum;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.softsynth.math.FourierMath;
-
-/**
- * Periodically transform the complex input signal using an FFT to a complex spectral stream.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @version 016
- * @see IFFT
- */
-public abstract class FFTBase extends UnitGenerator {
- public UnitInputPort inputReal;
- public UnitInputPort inputImaginary;
- public UnitOutputPort outputReal;
- public UnitOutputPort outputImaginary;
- protected double[] realInput;
- protected double[] realOutput;
- protected double[] imaginaryInput;
- protected double[] imaginaryOutput;
- protected int cursor;
-
- protected FFTBase() {
- addPort(inputReal = new UnitInputPort("InputReal"));
- addPort(inputImaginary = new UnitInputPort("InputImaginary"));
- addPort(outputReal = new UnitOutputPort("OutputReal"));
- addPort(outputImaginary = new UnitOutputPort("OutputImaginary"));
- setSize(Spectrum.DEFAULT_SIZE);
- }
-
- public void setSize(int size) {
- realInput = new double[size];
- realOutput = new double[size];
- imaginaryInput = new double[size];
- imaginaryOutput = new double[size];
- cursor = 0;
- }
-
- public int getSize() {
- return realInput.length;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputRs = inputReal.getValues();
- double[] inputIs = inputImaginary.getValues();
- double[] outputRs = outputReal.getValues();
- double[] outputIs = outputImaginary.getValues();
- for (int i = start; i < limit; i++) {
- realInput[cursor] = inputRs[i];
- imaginaryInput[cursor] = inputIs[i];
- outputRs[i] = realOutput[cursor];
- outputIs[i] = imaginaryOutput[cursor];
- cursor += 1;
- // When it is full, do the FFT.
- if (cursor == realInput.length) {
- // Copy to output buffer so we can do the FFT in place.
- System.arraycopy(realInput, 0, realOutput, 0, realInput.length);
- System.arraycopy(imaginaryInput, 0, imaginaryOutput, 0, imaginaryInput.length);
- FourierMath.transform(getSign(), realOutput.length, realOutput, imaginaryOutput);
- cursor = 0;
- }
- }
- }
-
- protected abstract int getSign();
-}
diff --git a/src/com/jsyn/unitgen/FilterAllPass.java b/src/com/jsyn/unitgen/FilterAllPass.java
deleted file mode 100644
index 749b2d6..0000000
--- a/src/com/jsyn/unitgen/FilterAllPass.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * AllPass filter using the following formula:
- *
- * <pre>
- * y(n) = -gain * x(n) + x(n - 1) + gain * y(n - 1)
- * </pre>
- *
- * where y(n) is Output, x(n) is Input, x(n-1) is a delayed copy of the input, and y(n-1) is a
- * delayed copy of the output. An all-pass filter will pass all frequencies with equal amplitude.
- * But it changes the phase relationships of the partials by delaying them by an amount proportional
- * to their wavelength,.
- *
- * @author (C) 2014 Phil Burk, SoftSynth.com
- * @see FilterLowPass
- */
-
-public class FilterAllPass extends UnitFilter {
- /** Feedback gain. Should be less than 1.0. Default is 0.8. */
- public UnitInputPort gain;
-
- private double x1;
- private double y1;
-
- public FilterAllPass() {
- addPort(gain = new UnitInputPort("Gain", 0.8));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double g = gain.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- y1 = (g * (y1 - x0)) + x1;
- x1 = x0;
- outputs[i] = y1;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterBandPass.java b/src/com/jsyn/unitgen/FilterBandPass.java
deleted file mode 100644
index b103400..0000000
--- a/src/com/jsyn/unitgen/FilterBandPass.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Aug 21, 2009
- * com.jsyn.engine.units.Filter_HighPass.java
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Filter that allows frequencies around the center frequency to pass and blocks others. This filter
- * is based on the BiQuad filter. Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- */
-public class FilterBandPass extends FilterBiquadCommon {
- /**
- * This method is by Filter_Biquad to update coefficients for the Filter_BandPass filter.
- */
- @Override
- public void updateCoefficients() {
- double scalar = 1.0 / (1.0 + alpha);
-
- a0 = alpha * scalar;
- a1 = 0.0;
- a2 = -a0;
- b1 = -2.0 * cos_omega * scalar;
- b2 = (1.0 - alpha) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterBandStop.java b/src/com/jsyn/unitgen/FilterBandStop.java
deleted file mode 100644
index d4f5249..0000000
--- a/src/com/jsyn/unitgen/FilterBandStop.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Filter that blocks frequencies around the center frequency. This filter is based on the BiQuad
- * filter. Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- */
-public class FilterBandStop extends FilterBiquadCommon {
-
- @Override
- public void updateCoefficients() {
-
- // scalar = 1.0f / (1.0f + BQCM.alpha);
- // A1_B1_Value = -2.0f * BQCM.cos_omega * scalar;
- //
- // csFilter->csFBQ_A0 = scalar;
- // csFilter->csFBQ_A1 = A1_B1_Value;
- // csFilter->csFBQ_A2 = scalar;
- // csFilter->csFBQ_B1 = A1_B1_Value;
- // csFilter->csFBQ_B2 = (1.0f - BQCM.alpha) * scalar;
-
- double scalar = 1.0 / (1.0 + alpha);
- double a1_b1_value = -2.0 * cos_omega * scalar;
-
- this.a0 = scalar;
- this.a1 = a1_b1_value;
- this.a2 = scalar;
- this.b1 = a1_b1_value;
- this.b2 = (1.0 - alpha) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterBiquad.java b/src/com/jsyn/unitgen/FilterBiquad.java
deleted file mode 100644
index f9b792f..0000000
--- a/src/com/jsyn/unitgen/FilterBiquad.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Base class for a set of IIR filters.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see FilterBandStop
- * @see FilterBandPass
- * @see FilterLowPass
- * @see FilterHighPass
- * @see FilterTwoPolesTwoZeros
- */
-public abstract class FilterBiquad extends TunableFilter {
- public UnitInputPort amplitude;
-
- protected static final double MINIMUM_FREQUENCY = 0.00001;
- protected static final double MINIMUM_GAIN = 0.00001;
- protected static final double RATIO_MINIMUM = 0.499;
- protected double a0;
- protected double a1;
- protected double a2;
- protected double b1;
- protected double b2;
- private double x1;
- private double x2;
- private double y1;
- private double y2;
- protected double previousFrequency;
- protected double omega;
- protected double sin_omega;
- protected double cos_omega;
-
- public FilterBiquad() {
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- }
-
- /**
- * Generic generate(int start, int limit) method calls this filter's recalculate() and
- * performBiquadFilter(int, int) methods.
- */
- @Override
- public void generate(int start, int limit) {
- recalculate();
- performBiquadFilter(start, limit);
- }
-
- protected abstract void recalculate();
-
- /**
- * Each filter calls performBiquadFilter() through the generate(int, int) method. This method
- * has converted Robert Bristow-Johnson's coefficients for the Direct I form in this way: Here
- * is the equation that JSyn uses for this filter:
- *
- * <pre>
- * y(n) = A0*x(n) + A1*x(n-1) + A2*x(n-2) -vB1*y(n-1) - B2*y(n-2)
- * </pre>
- *
- * Here is the equation that Robert Bristow-Johnson uses:
- *
- * <pre>
- * y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2] - (a1/a0)*y[n-1] - (a2/a0)*y[n-2]
- * </pre>
- *
- * So to translate between JSyn coefficients and RBJ coefficients:
- *
- * <pre>
- * JSyn =&gt; RBJ
- * A0 =&gt; b0/a0
- * A1 =&gt; b1/a0
- * A2 =&gt; b2/a0
- * B1 =&gt; a1/a0
- * B2 =&gt; a2/a0
- * </pre>
- *
- * @param start
- * @param limit
- */
- public void performBiquadFilter(int start, int limit) {
- double[] inputs = input.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- double a0_jsyn, a1_jsyn, a2_jsyn, b1_jsyn, b2_jsyn;
- double x0_jsyn, x1_jsyn, x2_jsyn, y1_jsyn, y2_jsyn;
-
- x1_jsyn = this.x1;
- x2_jsyn = this.x2;
-
- y1_jsyn = this.y1;
- y2_jsyn = this.y2;
-
- a0_jsyn = this.a0;
- a1_jsyn = this.a1;
- a2_jsyn = this.a2;
-
- b1_jsyn = this.b1;
- b2_jsyn = this.b2;
-
- // Permute filter operations to reduce data movement.
- for (int i = start; i < limit; i += 2)
-
- {
- x0_jsyn = inputs[i];
- y2_jsyn = (a0_jsyn * x0_jsyn) + (a1_jsyn * x1_jsyn) + (a2_jsyn * x2_jsyn)
- - (b1_jsyn * y1_jsyn) - (b2_jsyn * y2_jsyn);
-
- outputs[i] = amplitudes[i] * y2_jsyn;
-
- x2_jsyn = inputs[i + 1];
- y1_jsyn = (a0_jsyn * x2_jsyn) + (a1_jsyn * x0_jsyn) + (a2_jsyn * x1_jsyn)
- - (b1_jsyn * y2_jsyn) - (b2_jsyn * y1_jsyn);
-
- outputs[i + 1] = amplitudes[i + 1] * y1_jsyn;
-
- x1_jsyn = x2_jsyn;
- x2_jsyn = x0_jsyn;
- }
-
- this.x1 = x1_jsyn; // save filter state for next time
- this.x2 = x2_jsyn;
-
- // apply small bipolar impulse to prevent arithmetic underflow
- this.y1 = y1_jsyn + VERY_SMALL_FLOAT;
- this.y2 = y2_jsyn - VERY_SMALL_FLOAT;
- }
-
- protected void calculateOmega(double ratio) {
- if (ratio >= FilterBiquad.RATIO_MINIMUM) // keep a minimum
- // distance from Nyquist
- {
- ratio = FilterBiquad.RATIO_MINIMUM;
- }
-
- omega = 2.0 * Math.PI * ratio;
- cos_omega = Math.cos(omega); // compute cosine
- sin_omega = Math.sin(omega); // compute sine
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FilterBiquadCommon.java b/src/com/jsyn/unitgen/FilterBiquadCommon.java
deleted file mode 100644
index f21c8e7..0000000
--- a/src/com/jsyn/unitgen/FilterBiquadCommon.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Extend this class to create a filter that implements a Biquad filter with a Q port.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- */
-public abstract class FilterBiquadCommon extends FilterBiquad {
- public UnitInputPort Q;
-
- protected final static double MINIMUM_Q = 0.00001;
- private double previousQ;
- protected double alpha;
-
- /**
- * No-argument constructor instantiates the Biquad common and adds a Q port to this filter.
- */
- public FilterBiquadCommon() {
- addPort(Q = new UnitInputPort("Q"));
- Q.setup(0.1, 1.0, 10.0);
- }
-
- /**
- * Calculate coefficients based on the filter type, eg. LowPass.
- */
- public abstract void updateCoefficients();
-
- public void computeBiquadCommon(double ratio, double Q) {
- if (ratio >= FilterBiquad.RATIO_MINIMUM) // keep a minimum distance
- // from Nyquist
- {
- ratio = FilterBiquad.RATIO_MINIMUM;
- }
-
- omega = 2.0 * Math.PI * ratio;
- cos_omega = Math.cos(omega); // compute cosine
- sin_omega = Math.sin(omega); // compute sine
- alpha = sin_omega / (2.0 * Q); // set alpha
- // System.out.println("Q = " + Q + ", omega = " + omega +
- // ", cos(omega) = " + cos_omega + ", alpha = " + alpha );
- }
-
- /**
- * The recalculate() method checks and ensures that the frequency and Q values are at a minimum.
- * It also only updates the Biquad coefficients if either frequency or Q have changed.
- */
- @Override
- public void recalculate() {
- double frequencyValue = frequency.getValues()[0]; // grab frequency
- // element (we'll
- // only use
- // element[0])
- double qValue = Q.getValues()[0]; // grab Q element (we'll only use
- // element[0])
-
- if (frequencyValue < MINIMUM_FREQUENCY) // ensure a minimum frequency
- {
- frequencyValue = MINIMUM_FREQUENCY;
- }
-
- if (qValue < MINIMUM_Q) // ensure a minimum Q
- {
- qValue = MINIMUM_Q;
- }
- // only update changed values
- if (isRecalculationNeeded(frequencyValue, qValue)) {
- previousFrequency = frequencyValue; // hold previous frequency
- previousQ = qValue; // hold previous Q
-
- double ratio = frequencyValue * getFramePeriod();
- computeBiquadCommon(ratio, qValue);
- updateCoefficients();
- }
- }
-
- protected boolean isRecalculationNeeded(double frequencyValue, double qValue) {
- return (frequencyValue != previousFrequency) || (qValue != previousQ);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FilterBiquadShelf.java b/src/com/jsyn/unitgen/FilterBiquadShelf.java
deleted file mode 100644
index 737d18d..0000000
--- a/src/com/jsyn/unitgen/FilterBiquadShelf.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * This filter is based on the BiQuad filter and is used as a base class for FilterLowShelf and
- * FilterHighShelf. Coefficients are updated whenever the frequency, gain or slope changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class FilterBiquadShelf extends FilterBiquad {
- protected final static double MINIMUM_SLOPE = 0.00001;
-
- /**
- * Gain of peak. Use 1.0 for flat response.
- */
- public UnitInputPort gain;
-
- /**
- * Shelf Slope parameter. When S = 1, the shelf slope is as steep as you can get it and remain
- * monotonically increasing or decreasing gain with frequency.
- */
- public UnitInputPort slope;
-
- private double prevGain;
- private double prevSlope;
-
- private double beta;
- protected double alpha;
- protected double factorA;
- protected double AP1;
- protected double AM1;
- protected double beta_sn;
- protected double AP1cs;
- protected double AM1cs;
-
- public FilterBiquadShelf() {
- addPort(gain = new UnitInputPort("Gain", 1.0));
- addPort(slope = new UnitInputPort("Slope", 1.0));
- }
-
- /**
- * Abstract method. Each filter must implement its update of coefficients.
- */
- public abstract void updateCoefficients();
-
- /**
- * Compute coefficients for shelf filter if frequency, gain or slope have changed.
- */
- @Override
- public void recalculate() {
- // Just look at first value to save time.
- double frequencyValue = frequency.getValues()[0];
- if (frequencyValue < MINIMUM_FREQUENCY) {
- frequencyValue = MINIMUM_FREQUENCY;
- }
-
- double gainValue = gain.getValues()[0];
- if (gainValue < MINIMUM_GAIN) {
- gainValue = MINIMUM_GAIN;
- }
-
- double slopeValue = slope.getValues()[0];
- if (slopeValue < MINIMUM_SLOPE) {
- slopeValue = MINIMUM_SLOPE;
- }
-
- // Only do complex calculations if input changed.
- if ((frequencyValue != previousFrequency) || (gainValue != prevGain)
- || (slopeValue != prevSlope)) {
- previousFrequency = frequencyValue; // hold previous frequency
- prevGain = gainValue;
- prevSlope = slopeValue;
-
- double ratio = frequencyValue * getFramePeriod();
- calculateOmega(ratio);
-
- factorA = Math.sqrt(gainValue);
-
- AP1 = factorA + 1.0;
- AM1 = factorA - 1.0;
-
- /* Avoid sqrt(r<0) which hangs filter. */
- double beta2 = ((gainValue + 1.0) / slopeValue) - (AM1 * AM1);
- beta = (beta2 < 0.0) ? 0.0 : Math.sqrt(beta2);
-
- beta_sn = beta * sin_omega;
- AP1cs = AP1 * cos_omega;
- AM1cs = AM1 * cos_omega;
-
- updateCoefficients();
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FilterFourPoles.java b/src/com/jsyn/unitgen/FilterFourPoles.java
deleted file mode 100644
index 39a47c7..0000000
--- a/src/com/jsyn/unitgen/FilterFourPoles.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Resonant filter in the style of the Moog ladder filter. This implementation is loosely based on:
- * http://www.musicdsp.org/archive.php?classid=3#26
- * More interesting reading:
- * http://dafx04.na.infn.it/WebProc/Proc/P_061.pdf
- * http://www.acoustics.ed.ac.uk/wp-content/uploads/AMT_MSc_FinalProjects
- * /2012__Daly__AMT_MSc_FinalProject_MoogVCF.pdf
- * http://www.music.mcgill.ca/~ich/research/misc/papers/cr1071.pdf
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- * @see FilterLowPass
- */
-public class FilterFourPoles extends TunableFilter {
- public UnitInputPort Q;
- public UnitInputPort gain;
-
- private static final double MINIMUM_FREQUENCY = 1.0; // blows up if near 0.01
- private static final double MINIMUM_Q = 0.00001;
-
- //private static final double SATURATION_COEFFICIENT = 0.1666667;
- private static final double SATURATION_COEFFICIENT = 0.2;
- // Inflection point where slope is zero.
- private static final double SATURATION_UPPER_INPUT = 1.0 / Math.sqrt(3.0 * SATURATION_COEFFICIENT);
- private static final double SATURATION_LOWER_INPUT = 0.0 - SATURATION_UPPER_INPUT;
- private static final double SATURATION_UPPER_OUTPUT = cubicPolynomial(SATURATION_UPPER_INPUT);
- private static final double SATURATION_LOWER_OUTPUT = cubicPolynomial(SATURATION_LOWER_INPUT);
-
- private double x1;
- private double x2;
- private double x3;
- private double x4;
- private double y1;
- private double y2;
- private double y3;
- private double y4;
-
- private double previousFrequency;
- private double previousQ;
- // filter coefficients
- private double f;
- private double fTo4th;
- private double feedback;
-
- private boolean oversampled = true;
-
- public FilterFourPoles() {
- addPort(Q = new UnitInputPort("Q"));
- frequency.setup(40.0, DEFAULT_FREQUENCY, 4000.0);
- Q.setup(0.1, 2.0, 10.0);
- }
-
- /**
- * The recalculate() method checks and ensures that the frequency and Q values are at a minimum.
- * It also only updates the coefficients if either frequency or Q have changed.
- */
- public void recalculate() {
- double frequencyValue = frequency.getValues()[0];
- double qValue = Q.getValues()[0];
-
- if (frequencyValue < MINIMUM_FREQUENCY) // ensure a minimum frequency
- {
- frequencyValue = MINIMUM_FREQUENCY;
- }
- if (qValue < MINIMUM_Q) // ensure a minimum Q
- {
- qValue = MINIMUM_Q;
- }
-
- // Only recompute coefficients if changed.
- if ((frequencyValue != previousFrequency) || (qValue != previousQ)) {
- previousFrequency = frequencyValue;
- previousQ = qValue;
- computeCoefficients();
- }
- }
-
- private void computeCoefficients() {
- double normalizedFrequency = previousFrequency * getFramePeriod();
- double fudge = 4.9 - 0.27 * previousQ;
- if (fudge < 3.0)
- fudge = 3.0;
- f = normalizedFrequency * (oversampled ? 1.0 : 2.0) * fudge;
-
- double fSquared = f * f;
- fTo4th = fSquared * fSquared;
- feedback = 0.5 * previousQ * (1.0 - 0.15 * fSquared);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- recalculate();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
-
- if (oversampled) {
- oneSample(0.0);
- }
- oneSample(x0);
- outputs[i] = y4;
- }
-
- // apply small bipolar impulse to prevent arithmetic underflow
- y1 += VERY_SMALL_FLOAT;
- y2 -= VERY_SMALL_FLOAT;
- }
-
- private void oneSample(double x0) {
- final double coeff = 0.3;
- x0 -= y4 * feedback; // feedback
- x0 *= 0.35013 * fTo4th;
- y1 = x0 + coeff * x1 + (1 - f) * y1; // pole 1
- x1 = x0;
- y2 = y1 + coeff * x2 + (1 - f) * y2; // pole 2
- x2 = y1;
- y3 = y2 + coeff * x3 + (1 - f) * y3; // pole 3
- x3 = y2;
- y4 = y3 + coeff * x4 + (1 - f) * y4; // pole 4
- y4 = clip(y4);
- x4 = y3;
- }
-
- public boolean isOversampled() {
- return oversampled;
- }
-
- public void setOversampled(boolean oversampled) {
- this.oversampled = oversampled;
- }
-
- // Soft saturation. This used to blow up the filter!
- private static double cubicPolynomial(double x) {
- return x - (x * x * x * SATURATION_COEFFICIENT);
- }
-
- private static double clip(double x) {
- if (x > SATURATION_UPPER_INPUT) {
- return SATURATION_UPPER_OUTPUT;
- } else if (x < SATURATION_LOWER_INPUT) {
- return SATURATION_LOWER_OUTPUT;
- } else {
- return cubicPolynomial(x);
- }
- }
-
- public void reset() {
- x1 = 0.0;
- x2 = 0.0;
- x3 = 0.0;
- x4 = 0.0;
- y1 = 0.0;
- y2 = 0.0;
- y3 = 0.0;
- y4 = 0.0;
-
- previousFrequency = 0.0;
- previousQ = 0.0;
- f = 0.0;
- fTo4th = 0.0;
- feedback = 0.0;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterHighPass.java b/src/com/jsyn/unitgen/FilterHighPass.java
deleted file mode 100644
index 76ad6b9..0000000
--- a/src/com/jsyn/unitgen/FilterHighPass.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Aug 21, 2009
- * com.jsyn.engine.units.Filter_HighPass.java
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Filter that allows frequencies above the center frequency to pass. This filter is based on the
- * BiQuad filter. Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- */
-public class FilterHighPass extends FilterBiquadCommon {
- /**
- * This method is used by Filter_Biquad to update coefficients for the Filter_HighPass filter.
- */
- @Override
- public void updateCoefficients() {
- double scalar = 1.0 / (1.0 + alpha);
- double onePlusCosine = 1.0 + cos_omega;
- double a0_a2_value = onePlusCosine * 0.5 * scalar;
-
- this.a0 = a0_a2_value;
- this.a1 = -onePlusCosine * scalar;
- this.a2 = a0_a2_value;
- this.b1 = -2.0 * cos_omega * scalar;
- this.b2 = (1.0 - alpha) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterHighShelf.java b/src/com/jsyn/unitgen/FilterHighShelf.java
deleted file mode 100644
index 449090a..0000000
--- a/src/com/jsyn/unitgen/FilterHighShelf.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * HighShelf Filter. This creates a flat response above the cutoff frequency. This filter is
- * sometimes used at the end of a bank of EQ filters.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FilterHighShelf extends FilterBiquadShelf {
- /**
- * This method is called by by Filter_BiquadShelf to update coefficients.
- */
- @Override
- public void updateCoefficients() {
- double scalar = 1.0 / (AP1 - AM1cs + beta_sn);
- a0 = factorA * (AP1 + AM1cs + beta_sn) * scalar;
- a1 = -2.0 * factorA * (AM1 + AP1cs) * scalar;
- a2 = factorA * (AP1 + AM1cs - beta_sn) * scalar;
- b1 = 2.0 * (AM1 - AP1cs) * scalar;
- b2 = (AP1 - AM1cs - beta_sn) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterLowPass.java b/src/com/jsyn/unitgen/FilterLowPass.java
deleted file mode 100644
index 1557367..0000000
--- a/src/com/jsyn/unitgen/FilterLowPass.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Aug 21, 2009
- * com.jsyn.engine.units.Filter_HighPass.java
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Filter that allows frequencies below the center frequency to pass. This filter is based on the
- * BiQuad filter. Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- *
- * @see FilterFourPoles
- */
-public class FilterLowPass extends FilterBiquadCommon {
-
- /**
- * This method is by FilterBiquad to update coefficients for the lowpass filter.
- */
- @Override
- public void updateCoefficients() {
-
- // scalar = 1.0f / (1.0f + BQCM.alpha);
- // omc = (1.0f - BQCM.cos_omega);
- // A0_A2_Value = omc * 0.5f * scalar;
- // // translating from RBJ coefficients
- // // A0 = (b0/(2*a0)
- // // = ((1 - cos_omega)/2) / (1 + alpha)
- // // = (omc*0.5) / (1 + alpha)
- // // = (omc*0.5) * (1.0/(1 + alpha))
- // // = omc * 0.5 * scalar
- // csFilter->csFBQ_A0 = A0_A2_Value;
- // csFilter->csFBQ_A1 = omc * scalar;
- // csFilter->csFBQ_A2 = A0_A2_Value;
- // csFilter->csFBQ_B1 = -2.0f * BQCM.cos_omega * scalar;
- // csFilter->csFBQ_B2 = (1.0f - BQCM.alpha) * scalar;
-
- double scalar = 1.0 / (1.0 + alpha);
- double oneMinusCosine = 1.0 - cos_omega;
- double a0_a2_value = oneMinusCosine * 0.5 * scalar;
-
- this.a0 = a0_a2_value;
- this.a1 = oneMinusCosine * scalar;
- this.a2 = a0_a2_value;
- this.b1 = -2.0 * cos_omega * scalar;
- this.b2 = (1.0 - alpha) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterLowShelf.java b/src/com/jsyn/unitgen/FilterLowShelf.java
deleted file mode 100644
index cf41f45..0000000
--- a/src/com/jsyn/unitgen/FilterLowShelf.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * LowShelf Filter. This creates a flat response below the cutoff frequency. This filter is
- * sometimes used at the end of a bank of EQ filters. This filter is based on the BiQuad filter.
- * Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FilterLowShelf extends FilterBiquadShelf {
-
- /**
- * This method is called by Filter_BiquadShelf to update coefficients.
- */
- @Override
- public void updateCoefficients() {
- double scalar = 1.0 / (AP1 + AM1cs + beta_sn);
- a0 = factorA * (AP1 - AM1cs + beta_sn) * scalar;
- a1 = 2.0 * factorA * (AM1 - AP1cs) * scalar;
- a2 = factorA * (AP1 - AM1cs - beta_sn) * scalar;
- b1 = -2.0 * (AM1 + AP1cs) * scalar;
- b2 = (AP1 + AM1cs - beta_sn) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterOnePole.java b/src/com/jsyn/unitgen/FilterOnePole.java
deleted file mode 100644
index 090e42b..0000000
--- a/src/com/jsyn/unitgen/FilterOnePole.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * First Order, One Pole filter using the following formula:
- *
- * <pre>
- * y(n) = A0 * x(n) - B1 * y(n - 1)
- * </pre>
- *
- * where y(n) is Output, x(n) is Input and y(n-1) is a delayed copy of the output. This filter is a
- * recursive IIR or Infinite Impulse Response filter. It can be unstable depending on the values of
- * the coefficients. This can be useful as a low-pass filter, or a "leaky integrator". A thorough
- * description of the digital filter theory needed to fully describe this filter is beyond the scope
- * of this document. Calculating coefficients is non-intuitive; the interested user is referred to
- * one of the standard texts on filter theory (e.g., Moore, "Elements of Computer Music", section
- * 2.4).
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see FilterLowPass
- */
-public class FilterOnePole extends UnitFilter {
- public UnitVariablePort a0;
- public UnitVariablePort b1;
- private double y1;
-
- public FilterOnePole() {
- addPort(a0 = new UnitVariablePort("A0", 0.6));
- addPort(b1 = new UnitVariablePort("B1", -0.3));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double a0v = a0.getValue();
- double b1v = b1.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- outputs[i] = y1 = (a0v * x0) - (b1v * y1);
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterOnePoleOneZero.java b/src/com/jsyn/unitgen/FilterOnePoleOneZero.java
deleted file mode 100644
index ed1868c..0000000
--- a/src/com/jsyn/unitgen/FilterOnePoleOneZero.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * First Order, One Pole, One Zero filter using the following formula:
- *
- * <pre>
- * y(n) = A0 * x(n) + A1 * x(n - 1) - B1 * y(n - 1)
- * </pre>
- *
- * where y(n) is Output, x(n) is Input, x(n-1) is a delayed copy of the input, and y(n-1) is a
- * delayed copy of the output. This filter is a recursive IIR or Infinite Impulse Response filter.
- * it can be unstable depending on the values of the coefficients. A thorough description of the
- * digital filter theory needed to fully describe this filter is beyond the scope of this document.
- * Calculating coefficients is non-intuitive; the interested user is referred to one of the standard
- * texts on filter theory (e.g., Moore, "Elements of Computer Music", section 2.4).
- *
- * @author (C) 1997-2009 Phil Burk, SoftSynth.com
- * @see FilterLowPass
- */
-
-public class FilterOnePoleOneZero extends UnitFilter {
- public UnitVariablePort a0;
- public UnitVariablePort a1;
- public UnitVariablePort b1;
-
- private double x1;
- private double y1;
-
- public FilterOnePoleOneZero() {
- addPort(a0 = new UnitVariablePort("A0"));
- addPort(a1 = new UnitVariablePort("A1"));
- addPort(b1 = new UnitVariablePort("B1"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double a0v = a0.getValue();
- double a1v = a1.getValue();
- double b1v = b1.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- outputs[i] = y1 = (a0v * x0) + (a1v * x1) + (b1v * y1);
- x1 = x0;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterOneZero.java b/src/com/jsyn/unitgen/FilterOneZero.java
deleted file mode 100644
index 2a07a16..0000000
--- a/src/com/jsyn/unitgen/FilterOneZero.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * First Order, One Zero filter using the following formula:
- *
- * <pre>
- * y(n) = A0 * x(n) + A1 * x(n - 1)
- * </pre>
- *
- * where y(n) is Output, x(n) is Input and x(n-1) is Input at the prior sample tick. Setting A1
- * positive gives a low-pass response; setting A1 negative gives a high-pass response. The bandwidth
- * of this filter is fairly high, so it often serves a building block by being cascaded with other
- * filters. If A0 and A1 are both 0.5, then this filter is a simple averaging lowpass filter, with a
- * zero at SR/2 = 22050 Hz. If A0 is 0.5 and A1 is -0.5, then this filter is a high pass filter,
- * with a zero at 0.0 Hz. A thorough description of the digital filter theory needed to fully
- * describe this filter is beyond the scope of this document. Calculating coefficients is
- * non-intuitive; the interested user is referred to one of the standard texts on filter theory
- * (e.g., Moore, "Elements of Computer Music", section 2.4).
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see FilterLowPass
- */
-public class FilterOneZero extends UnitFilter {
- public UnitVariablePort a0;
- public UnitVariablePort a1;
- private double x1;
-
- public FilterOneZero() {
- addPort(a0 = new UnitVariablePort("A0", 0.5));
- addPort(a1 = new UnitVariablePort("A1", 0.5));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double a0v = a0.getValue();
- double a1v = a1.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- outputs[i] = (a0v * x0) + (a1v * x1);
- x1 = x0;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterPeakingEQ.java b/src/com/jsyn/unitgen/FilterPeakingEQ.java
deleted file mode 100644
index bec7096..0000000
--- a/src/com/jsyn/unitgen/FilterPeakingEQ.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * PeakingEQ Filter. This can be used to raise or lower the gain around the cutoff frequency. This
- * filter is sometimes used in the middle of a bank of EQ filters. This filter is based on the
- * BiQuad filter. Coefficients are updated whenever the frequency or Q changes.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FilterPeakingEQ extends FilterBiquadCommon {
- public UnitInputPort gain;
-
- private double previousGain;
-
- public FilterPeakingEQ() {
- addPort(gain = new UnitInputPort("Gain", 1.0));
- }
-
- @Override
- protected boolean isRecalculationNeeded(double frequencyValue, double qValue) {
- double currentGain = gain.getValues()[0];
- if (currentGain < MINIMUM_GAIN) {
- currentGain = MINIMUM_GAIN;
- }
-
- boolean needed = super.isRecalculationNeeded(frequencyValue, qValue);
- needed |= (previousGain != currentGain);
-
- previousGain = currentGain;
- return needed;
- }
-
- @Override
- public void updateCoefficients() {
- double factorA = Math.sqrt(previousGain);
- double alphaTimesA = alpha * factorA;
- double alphaOverA = alpha / factorA;
- // Note this is not the normal scalar!
- double scalar = 1.0 / (1.0 + alphaOverA);
- double a1_b1_value = -2.0 * cos_omega * scalar;
-
- this.a0 = (1.0 + alphaTimesA) * scalar;
-
- this.a1 = a1_b1_value;
- this.a2 = (1.0 - alphaTimesA) * scalar;
-
- this.b1 = a1_b1_value;
- this.b2 = (1.0 - alphaOverA) * scalar;
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterStateVariable.java b/src/com/jsyn/unitgen/FilterStateVariable.java
deleted file mode 100644
index 74dde5e..0000000
--- a/src/com/jsyn/unitgen/FilterStateVariable.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * A versatile filter described in Hal Chamberlain's "Musical Applications of MicroProcessors". It
- * is convenient because its frequency and resonance can each be controlled by a single value. The
- * "output" port of this filter is the "lowPass" output multiplied by the "amplitude"
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see FilterLowPass
- * @see FilterHighPass
- * @see FilterFourPoles
- */
-public class FilterStateVariable extends TunableFilter {
- /**
- * Amplitude of Output in the range of 0.0 to 1.0. SIGNAL_TYPE_RAW_SIGNED Defaults to 1.0
- * <P>
- * Note that the amplitude only affects the "output" port and not the lowPass, bandPass or
- * highPass signals. Use a Multiply unit if you need to scale those signals.
- */
- public UnitInputPort amplitude;
-
- /**
- * Controls feedback that causes self oscillation. Actually 1/Q - SIGNAL_TYPE_RAW_SIGNED in the
- * range of 0.0 to 1.0. Defaults to 0.125.
- */
- public UnitInputPort resonance;
- /**
- * Low pass filtered signal.
- * <P>
- * Note that this signal is not affected by the amplitude port.
- */
- public UnitOutputPort lowPass;
- /**
- * Band pass filtered signal.
- * <P>
- * Note that this signal is not affected by the amplitude port.
- */
- public UnitOutputPort bandPass;
- /**
- * High pass filtered signal.
- * <P>
- * Note that this signal is not affected by the amplitude port.
- */
- public UnitOutputPort highPass;
-
- private double freqInternal;
- private double previousFrequency = Double.MAX_VALUE; // So we trigger an immediate update.
- private double lowPassValue;
- private double bandPassValue;
-
- /**
- * No-argument constructor instantiates the Biquad common and adds an amplitude port to this
- * filter.
- */
- public FilterStateVariable() {
- frequency.set(440.0);
- addPort(resonance = new UnitInputPort("Resonance", 0.2));
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- addPort(lowPass = new UnitOutputPort("LowPass"));
- addPort(bandPass = new UnitOutputPort("BandPass"));
- addPort(highPass = new UnitOutputPort("HighPass"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] reses = resonance.getValues();
- double[] lows = lowPass.getValues();
- double[] highs = highPass.getValues();
- double[] bands = bandPass.getValues();
-
- double newFreq = frequencies[0];
- if (newFreq != previousFrequency) {
- previousFrequency = newFreq;
- freqInternal = 2.0 * Math.sin(Math.PI * newFreq * getFramePeriod());
- }
-
- for (int i = start; i < limit; i++) {
- lowPassValue = (freqInternal * bandPassValue) + lowPassValue;
- // Clip between -1 and +1 to prevent blowup.
- lowPassValue = (lowPassValue < -1.0) ? -1.0 : ((lowPassValue > 1.0) ? 1.0
- : lowPassValue);
- lows[i] = lowPassValue;
-
- outputs[i] = lowPassValue * (amplitudes[i]);
- double highPassValue = inputs[i] - (reses[i] * bandPassValue) - lowPassValue;
- // System.out.println("low = " + lowPassValue + ", band = " + bandPassValue +
- // ", high = " + highPassValue );
- highs[i] = highPassValue;
-
- bandPassValue = (freqInternal * highPassValue) + bandPassValue;
- bands[i] = bandPassValue;
- // System.out.println("low = " + lowPassValue + ", band = " + bandPassValue +
- // ", high = " + highPassValue );
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FilterTwoPoles.java b/src/com/jsyn/unitgen/FilterTwoPoles.java
deleted file mode 100644
index 0c68a64..0000000
--- a/src/com/jsyn/unitgen/FilterTwoPoles.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Second Order, Two Pole filter using the following formula:
- *
- * <pre>
- * y(n) = A0 * x(n) - B1 * y(n - 1) - B2 * y(n - 2)
- * </pre>
- *
- * where y(n) is Output, x(n) is Input, and y(n-1) is a delayed copy of the output. This filter is a
- * recursive IIR or Infinite Impulse Response filter. it can be unstable depending on the values of
- * the coefficients. A thorough description of the digital filter theory needed to fully describe
- * this filter is beyond the scope of this document. Calculating coefficients is non-intuitive; the
- * interested user is referred to one of the standard texts on filter theory (e.g., Moore,
- * "Elements of Computer Music", section 2.4).
- *
- * @author (C) 1997-2009 Phil Burk, Mobileer Inc
- */
-
-public class FilterTwoPoles extends UnitFilter {
- public UnitVariablePort a0;
- public UnitVariablePort b1;
- public UnitVariablePort b2;
- private double y1;
- private double y2;
-
- public FilterTwoPoles() {
- addPort(a0 = new UnitVariablePort("A0"));
- addPort(b1 = new UnitVariablePort("B1"));
- addPort(b2 = new UnitVariablePort("B2"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double a0v = a0.getValue();
- double b1v = b1.getValue();
- double b2v = b2.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- outputs[i] = y1 = 2.0 * ((a0v * x0) + (b1v * y1) + (b2v * y2));
- y2 = y1;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FilterTwoPolesTwoZeros.java b/src/com/jsyn/unitgen/FilterTwoPolesTwoZeros.java
deleted file mode 100644
index cde279f..0000000
--- a/src/com/jsyn/unitgen/FilterTwoPolesTwoZeros.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Second Order, Two Pole, Two Zero filter using the following formula:
- *
- * <pre>
- * y(n) = 2.0 * (A0 * x(n) + A1 * x(n - 1) + A2 * x(n - 2) - B1 * y(n - 1) - B2 * y(n - 2))
- * </pre>
- *
- * where y(n) is Output, x(n) is Input, x(n-1) is a delayed copy of the input, and y(n-1) is a
- * delayed copy of the output. This filter is a recursive IIR or Infinite Impulse Response filter.
- * It can be unstable depending on the values of the coefficients. This filter is basically the same
- * as the FilterBiquad with different ports. A thorough description of the digital filter theory
- * needed to fully describe this filter is beyond the scope of this document. Calculating
- * coefficients is non-intuitive; the interested user is referred to one of the standard texts on
- * filter theory (e.g., Moore, "Elements of Computer Music", section 2.4). Special thanks to Robert
- * Bristow-Johnson for contributing his filter equations to the music-dsp list. They were used for
- * calculating the coefficients for the lowPass, highPass, and other parametric filter calculations.
- *
- * @author (C) 1997-2009 Phil Burk, SoftSynth.com
- */
-
-public class FilterTwoPolesTwoZeros extends UnitFilter {
- public UnitVariablePort a0;
- public UnitVariablePort a1;
- public UnitVariablePort a2;
- public UnitVariablePort b1;
- public UnitVariablePort b2;
- private double x1;
- private double y1;
- private double x2;
- private double y2;
-
- public FilterTwoPolesTwoZeros() {
- addPort(a0 = new UnitVariablePort("A0"));
- addPort(a1 = new UnitVariablePort("A1"));
- addPort(a2 = new UnitVariablePort("A2"));
- addPort(b1 = new UnitVariablePort("B1"));
- addPort(b2 = new UnitVariablePort("B2"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double a0v = a0.getValue();
- double a1v = a1.getValue();
- double a2v = a2.getValue();
- double b1v = b1.getValue();
- double b2v = b2.getValue();
-
- for (int i = start; i < limit; i++) {
- double x0 = inputs[i];
- outputs[i] = y1 = 2.0 * ((a0v * x0) + (a1v * x1) + (a2v * x2) + (b1v * y1) + (b2v * y2));
- x2 = x1;
- x1 = x0;
- y2 = y1;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FixedRateMonoReader.java b/src/com/jsyn/unitgen/FixedRateMonoReader.java
deleted file mode 100644
index c6edc23..0000000
--- a/src/com/jsyn/unitgen/FixedRateMonoReader.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Simple sample player. Play one sample per audio frame with no interpolation.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FixedRateMonoReader extends SequentialDataReader {
-
- public FixedRateMonoReader() {
- addPort(output = new UnitOutputPort());
- }
-
- @Override
- public void generate(int start, int limit) {
-
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- if (dataQueue.hasMore()) {
- double fdata = dataQueue.readNextMonoDouble(getFramePeriod());
- outputs[i] = fdata * amplitudes[i];
- } else {
- outputs[i] = 0.0;
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- dataQueue.firePendingCallbacks();
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FixedRateMonoWriter.java b/src/com/jsyn/unitgen/FixedRateMonoWriter.java
deleted file mode 100644
index c215c55..0000000
--- a/src/com/jsyn/unitgen/FixedRateMonoWriter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Simple sample writer. Write one sample per audio frame with no interpolation. This can be used to
- * record audio or to build delay lines.
- *
- * Note that you must call start() on this unit because it does not have an output for pulling data.
- *
- * @see FixedRateStereoWriter
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FixedRateMonoWriter extends SequentialDataWriter {
-
- public FixedRateMonoWriter() {
- addPort(input = new UnitInputPort("Input"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
-
- for (int i = start; i < limit; i++) {
- if (dataQueue.hasMore()) {
- double value = inputs[i];
- dataQueue.writeNextDouble(value);
- } else {
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- dataQueue.firePendingCallbacks();
- }
-
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FixedRateStereoReader.java b/src/com/jsyn/unitgen/FixedRateStereoReader.java
deleted file mode 100644
index c5c00ce..0000000
--- a/src/com/jsyn/unitgen/FixedRateStereoReader.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Simple stereo sample player. Play one sample per audio frame with no interpolation.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FixedRateStereoReader extends SequentialDataReader {
- public FixedRateStereoReader() {
- addPort(output = new UnitOutputPort(2, "Output"));
- dataQueue.setNumChannels(2);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] output0s = output.getValues(0);
- double[] output1s = output.getValues(1);
-
- for (int i = start; i < limit; i++) {
- if (dataQueue.hasMore()) {
- dataQueue.beginFrame(getFramePeriod());
- double fdata = dataQueue.readCurrentChannelDouble(0);
- // System.out.println("SampleReader_16F2: left = " + fdata );
- double amp = amplitudes[i];
- output0s[i] = fdata * amp;
- fdata = dataQueue.readCurrentChannelDouble(1);
- // System.out.println("SampleReader_16F2: right = " + fdata );
- output1s[i] = fdata * amp;
- dataQueue.endFrame();
- } else {
- output0s[i] = 0.0;
- output1s[i] = 0.0;
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- dataQueue.firePendingCallbacks();
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/FixedRateStereoWriter.java b/src/com/jsyn/unitgen/FixedRateStereoWriter.java
deleted file mode 100644
index e4502f9..0000000
--- a/src/com/jsyn/unitgen/FixedRateStereoWriter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Simple stereo sample writer. Write two samples per audio frame with no interpolation. This can be
- * used to record audio or to build delay lines.
- *
- * Note that you must call start() on this unit because it does not have an output for pulling data.
- *
- * @see FixedRateMonoWriter
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FixedRateStereoWriter extends SequentialDataWriter {
-
- public FixedRateStereoWriter() {
- addPort(input = new UnitInputPort(2, "Input"));
- dataQueue.setNumChannels(2);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] input0s = input.getValues(0);
- double[] input1s = input.getValues(1);
-
- for (int i = start; i < limit; i++) {
- if (dataQueue.hasMore()) {
- dataQueue.beginFrame(getFramePeriod());
- double value = input0s[i];
- dataQueue.writeCurrentChannelDouble(0, value);
- value = input1s[i];
- dataQueue.writeCurrentChannelDouble(1, value);
- dataQueue.endFrame();
- } else {
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- dataQueue.firePendingCallbacks();
- }
-
- }
-
-}
diff --git a/src/com/jsyn/unitgen/FourWayFade.java b/src/com/jsyn/unitgen/FourWayFade.java
deleted file mode 100644
index c7fd22a..0000000
--- a/src/com/jsyn/unitgen/FourWayFade.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * FourWayFade unit.
- * <P>
- * Mix inputs 0-3 based on the value of two fade ports. You can think of the four inputs arranged
- * clockwise as follows.
- * <P>
- *
- * <PRE>
- * input[0] ---- input[1]
- * | |
- * | |
- * | |
- * input[3] ---- input[2]
- * </PRE>
- *
- * The "fade" port has two parts. Fade[0] fades between the pair of inputs (0,3) and the pair of
- * inputs (1,2). Fade[1] fades between the pair of inputs (0,1) and the pair of inputs (3,2).
- *
- * <PRE>
- * Fade[0] Fade[1] Output
- * -1 -1 Input[3]
- * -1 +1 Input[0]
- * +1 -1 Input[2]
- * +1 +1 Input[1]
- *
- *
- * -----Fade[0]-----&gt;
- *
- * A
- * |
- * |
- * Fade[1]
- * |
- * |
- * </PRE>
- * <P>
- *
- * @author (C) 1997-2009 Phil Burk, Mobileer Inc
- */
-public class FourWayFade extends UnitGenerator {
- public UnitInputPort input;
- public UnitInputPort fade;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public FourWayFade() {
- addPort(input = new UnitInputPort(4, "Input"));
- addPort(fade = new UnitInputPort(2, "Fade"));
- addPort(output = new UnitOutputPort());
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputAs = input.getValues(0);
- double[] inputBs = input.getValues(1);
- double[] inputCs = input.getValues(2);
- double[] inputDs = input.getValues(3);
- double[] fadeLRs = fade.getValues(0);
- double[] fadeFBs = fade.getValues(1);
- double[] outputs = output.getValues(0);
-
- for (int i = start; i < limit; i++) {
- // Scale and offset to 0.0 to 1.0 range.
- double gainLR = (fadeLRs[i] * 0.5) + 0.5;
- double temp = 1.0 - gainLR;
- double mixFront = (inputAs[i] * temp) + (inputBs[i] * gainLR);
- double mixBack = (inputDs[i] * temp) + (inputCs[i] * gainLR);
-
- double gainFB = (fadeFBs[i] * 0.5) + 0.5;
- outputs[i] = (mixBack * (1.0 - gainFB)) + (mixFront * gainFB);
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/FunctionEvaluator.java b/src/com/jsyn/unitgen/FunctionEvaluator.java
deleted file mode 100644
index 0cc0c83..0000000
--- a/src/com/jsyn/unitgen/FunctionEvaluator.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Aug 26, 2009
- * com.jsyn.engine.units.TunableFilter.java
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.Function;
-import com.jsyn.ports.UnitFunctionPort;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Convert an input value to an output value. The Function is typically implemented by looking up a
- * value in a DoubleTable. But other implementations of Function can be used. Input typically ranges
- * from -1.0 to +1.0.
- *
- * <pre>
- * <code>
- * // A unit that will lookup the function.
- * FunctionEvaluator shaper = new FunctionEvaluator();
- * synth.add( shaper );
- * shaper.start();
- * // Define a custom function.
- * Function cuber = new Function()
- * {
- * public double evaluate( double x )
- * {
- * return x * x * x;
- * }
- * };
- * shaper.function.set(cuber);
- *
- * shaper.input.set( 0.5 );
- * </code>
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see Function
- */
-public class FunctionEvaluator extends UnitFilter {
- public UnitInputPort amplitude;
- public UnitFunctionPort function;
-
- public FunctionEvaluator() {
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- addPort(function = new UnitFunctionPort("Function"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- Function functionObject = function.get();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = functionObject.evaluate(inputs[i]) * amplitudes[i];
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/FunctionOscillator.java b/src/com/jsyn/unitgen/FunctionOscillator.java
deleted file mode 100644
index 30d32d5..0000000
--- a/src/com/jsyn/unitgen/FunctionOscillator.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.Function;
-import com.jsyn.ports.UnitFunctionPort;
-
-/**
- * Oscillator that uses a Function object to define the waveform. Note that a DoubleTable can be
- * used as the Function.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class FunctionOscillator extends UnitOscillator {
- public UnitFunctionPort function;
-
- public FunctionOscillator() {
- addPort(function = new UnitFunctionPort("Function"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- Function functionObject = function.get();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- // Generate sawtooth phasor to provide phase for function lookup.
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- double value = functionObject.evaluate(currentPhase);
- outputs[i] = value * amplitudes[i];
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Grain.java b/src/com/jsyn/unitgen/Grain.java
deleted file mode 100644
index 812061c..0000000
--- a/src/com/jsyn/unitgen/Grain.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * A single Grain that is normally created and controlled by a GrainFarm.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public class Grain implements GrainEnvelope {
- private double frameRate;
- private double amplitude = 1.0;
-
- private GrainSource source;
- private GrainEnvelope envelope;
-
- public Grain(GrainSource source, GrainEnvelope envelope) {
- this.source = source;
- this.envelope = envelope;
- }
-
- @Override
- public double next() {
- if (envelope.hasMoreValues()) {
- double env = envelope.next();
- return source.next() * env * amplitude;
- } else {
- return 0.0;
- }
- }
-
- @Override
- public boolean hasMoreValues() {
- return envelope.hasMoreValues();
- }
-
- @Override
- public void reset() {
- source.reset();
- envelope.reset();
- }
-
- public void setRate(double rate) {
- source.setRate(rate);
- }
-
- @Override
- public void setDuration(double duration) {
- envelope.setDuration(duration);
- }
-
- @Override
- public double getFrameRate() {
- return frameRate;
- }
-
- @Override
- public void setFrameRate(double frameRate) {
- this.frameRate = frameRate;
- source.setFrameRate(frameRate);
- envelope.setFrameRate(frameRate);
- }
-
- public double getAmplitude() {
- return amplitude;
- }
-
- public void setAmplitude(double amplitude) {
- this.amplitude = amplitude;
- }
-
- public GrainSource getSource() {
- return source;
- }
-}
diff --git a/src/com/jsyn/unitgen/GrainCommon.java b/src/com/jsyn/unitgen/GrainCommon.java
deleted file mode 100644
index a7a04fc..0000000
--- a/src/com/jsyn/unitgen/GrainCommon.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-public class GrainCommon {
- protected double frameRate;
-
- public double getFrameRate() {
- return frameRate;
- }
-
- public void setFrameRate(double frameRate) {
- this.frameRate = frameRate;
- }
-
- public void reset() {
- }
-}
diff --git a/src/com/jsyn/unitgen/GrainEnvelope.java b/src/com/jsyn/unitgen/GrainEnvelope.java
deleted file mode 100644
index e6ff24c..0000000
--- a/src/com/jsyn/unitgen/GrainEnvelope.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * This envelope should start at 0.0, go up to 1.0 and then return to 0.0 in duration time.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public interface GrainEnvelope {
-
- double getFrameRate();
-
- void setFrameRate(double frameRate);
-
- /**
- * @return next amplitude value of envelope
- */
- double next();
-
- /**
- * Are there any more values to be generated in the envelope?
- *
- * @return true if more
- */
- boolean hasMoreValues();
-
- /**
- * Prepare to start a new envelope.
- */
- void reset();
-
- /**
- * @param duration in seconds.
- */
- void setDuration(double duration);
-
-}
diff --git a/src/com/jsyn/unitgen/GrainFarm.java b/src/com/jsyn/unitgen/GrainFarm.java
deleted file mode 100644
index 78179bc..0000000
--- a/src/com/jsyn/unitgen/GrainFarm.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.util.PseudoRandom;
-
-/**
- * A unit generator that generates a cloud of sound using multiple Grains. Special thanks to my
- * friend Ross Bencina for his excellent article on Granular Synthesis. Several of his ideas are
- * reflected in this architecture. "Implementing Real-Time Granular Synthesis" by Ross Bencina,
- * Audio Anecdotes III, 2001.
- *
- * <pre><code>
- synth.add( sampleGrainFarm = new GrainFarm() );
- grainFarm.allocate( NUM_GRAINS );
-</code></pre>
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see Grain
- * @see GrainSourceSine
- * @see RaisedCosineEnvelope
- */
-public class GrainFarm extends UnitGenerator implements UnitSource {
- /** A scaler for playback rate. Nominally 1.0. */
- public UnitInputPort rate;
- public UnitInputPort rateRange;
- public UnitInputPort amplitude;
- public UnitInputPort amplitudeRange;
- public UnitInputPort density;
- public UnitInputPort duration;
- public UnitInputPort durationRange;
- public UnitOutputPort output;
-
- PseudoRandom randomizer;
- private GrainState[] states;
- private double countScaler = 1.0;
- private final GrainScheduler scheduler = new StochasticGrainScheduler();
-
- public GrainFarm() {
- randomizer = new PseudoRandom();
- addPort(rate = new UnitInputPort("Rate", 1.0));
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- addPort(duration = new UnitInputPort("Duration", 0.01));
- addPort(rateRange = new UnitInputPort("RateRange", 0.0));
- addPort(amplitudeRange = new UnitInputPort("AmplitudeRange", 0.0));
- addPort(durationRange = new UnitInputPort("DurationRange", 0.0));
- addPort(density = new UnitInputPort("Density", 0.1));
- addPort(output = new UnitOutputPort());
- }
-
- private class GrainState {
- Grain grain;
- int countdown;
- double lastDuration;
- final static int STATE_IDLE = 0;
- final static int STATE_GAP = 1;
- final static int STATE_RUNNING = 2;
- int state = STATE_IDLE;
- private double gapError;
-
- public double next(int i) {
- double output = 0.0;
- if (state == STATE_RUNNING) {
- if (grain.hasMoreValues()) {
- output = grain.next();
- } else {
- startGap(i);
- }
- } else if (state == STATE_GAP) {
- if (countdown > 0) {
- countdown -= 1;
- } else if (countdown == 0) {
- state = STATE_RUNNING;
- grain.reset();
-
- setupGrain(grain, i);
-
- double dur = nextDuration(i);
- grain.setDuration(dur);
- }
- } else if (state == STATE_IDLE) {
- nextDuration(i); // initialize lastDuration
- startGap(i);
- }
- return output;
- }
-
- private double nextDuration(int i) {
- double dur = duration.getValues()[i];
- dur = scheduler.nextDuration(dur);
- lastDuration = dur;
- return dur;
- }
-
- private void startGap(int i) {
- state = STATE_GAP;
- double dens = density.getValues()[i];
- double gap = scheduler.nextGap(lastDuration, dens) * getFrameRate();
- gap += gapError;
- countdown = (int) gap;
- gapError = gap - countdown;
- }
- }
-
- public void setGrainArray(Grain[] grains) {
- countScaler = 1.0 / grains.length;
- states = new GrainState[grains.length];
- for (int i = 0; i < states.length; i++) {
- states[i] = new GrainState();
- states[i].grain = grains[i];
- grains[i].setFrameRate(getSynthesisEngine().getFrameRate());
- }
- }
-
- public void setupGrain(Grain grain, int i) {
- double temp = rate.getValues()[i] * calculateOctaveScaler(rateRange.getValues()[i]);
- grain.setRate(temp);
-
- // Scale the amplitude range so that we never go above
- // original amplitude.
- double base = amplitude.getValues()[i];
- double offset = base * Math.random() * amplitudeRange.getValues()[i];
- grain.setAmplitude(base - offset);
- }
-
- public void allocate(int numGrains) {
- Grain[] grainArray = new Grain[numGrains];
- for (int i = 0; i < numGrains; i++) {
- Grain grain = new Grain(new GrainSourceSine(), new RaisedCosineEnvelope());
- grainArray[i] = grain;
- }
- setGrainArray(grainArray);
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
- private double calculateOctaveScaler(double rangeValue) {
- double octaveRange = 0.5 * randomizer.nextRandomDouble() * rangeValue;
- return Math.pow(2.0, octaveRange);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
- double[] amplitudes = amplitude.getValues();
- // double frp = getSynthesisEngine().getFramePeriod();
- for (int i = start; i < limit; i++) {
- double result = 0.0;
-
- // Mix the grains together.
- for (GrainState grainState : states) {
- result += grainState.next(i);
- }
-
- outputs[i] = result * amplitudes[i] * countScaler;
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/GrainScheduler.java b/src/com/jsyn/unitgen/GrainScheduler.java
deleted file mode 100644
index df9c25e..0000000
--- a/src/com/jsyn/unitgen/GrainScheduler.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Defines a class that can schedule the execution of Grains in a GrainFarm. This is mostly for
- * internal use.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public interface GrainScheduler {
-
- /**
- * Calculate time in seconds for the next gap between grains.
- *
- * @param duration
- * @param density
- * @return seconds before next grain
- */
- double nextGap(double duration, double density);
-
- /**
- * Calculate duration in seconds for the next grains.
- *
- * @param suggestedDuration
- * @return duration of grain seconds
- */
- double nextDuration(double suggestedDuration);
-
-}
diff --git a/src/com/jsyn/unitgen/GrainSource.java b/src/com/jsyn/unitgen/GrainSource.java
deleted file mode 100644
index 1d5c522..0000000
--- a/src/com/jsyn/unitgen/GrainSource.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Defines classes that can provide the signal inside a Grain.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public interface GrainSource {
- double getFrameRate();
-
- void setFrameRate(double frameRate);
-
- /** Generate one more value or the source signal. */
- double next();
-
- /** Reset the internal phase of the grain. */
- void reset();
-
- void setRate(double rate);
-}
diff --git a/src/com/jsyn/unitgen/GrainSourceSine.java b/src/com/jsyn/unitgen/GrainSourceSine.java
deleted file mode 100644
index 0af9cbd..0000000
--- a/src/com/jsyn/unitgen/GrainSourceSine.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * A simple sine wave generator for a Grain. This uses the same fast Taylor expansion that the
- * SineOscillator uses.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public class GrainSourceSine extends GrainCommon implements GrainSource {
- protected double phase;
- protected double phaseIncrement;
-
- public GrainSourceSine() {
- setRate(1.0);
- }
-
- public void setPhaseIncrement(double phaseIncrement) {
- this.phaseIncrement = phaseIncrement;
- }
-
- @Override
- public double next() {
- phase += phaseIncrement;
- if (phase > 1.0) {
- phase -= 2.0;
- }
- return SineOscillator.fastSin(phase);
- }
-
- @Override
- public void setRate(double rate) {
- setPhaseIncrement(rate * 0.1 / Math.PI);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/IFFT.java b/src/com/jsyn/unitgen/IFFT.java
deleted file mode 100644
index 307acd2..0000000
--- a/src/com/jsyn/unitgen/IFFT.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Periodically transform the complex input spectrum using an IFFT to a complex signal stream.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @version 016
- * @see FFT
- */
-public class IFFT extends FFTBase {
-
- public IFFT() {
- super();
- }
-
- @Override
- protected int getSign() {
- return -1; // -1 for IFFT
- }
-}
diff --git a/src/com/jsyn/unitgen/ImpulseOscillator.java b/src/com/jsyn/unitgen/ImpulseOscillator.java
deleted file mode 100644
index 8c676f3..0000000
--- a/src/com/jsyn/unitgen/ImpulseOscillator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Narrow impulse oscillator. An impulse is only one sample wide. It is useful for pinging filters
- * or generating an "impulse response".
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class ImpulseOscillator extends UnitOscillator {
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- double inverseNyquist = synthesisEngine.getInverseNyquist();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for impulse generation. */
- double phaseIncrement = frequencies[i] * inverseNyquist;
- currentPhase += phaseIncrement;
-
- double ampl = amplitudes[i];
- double result = 0.0;
- if (currentPhase >= 1.0) {
- currentPhase -= 2.0;
- result = ampl;
- } else if (currentPhase < -1.0) {
- currentPhase += 2.0;
- result = ampl;
- }
- outputs[i] = result;
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/ImpulseOscillatorBL.java b/src/com/jsyn/unitgen/ImpulseOscillatorBL.java
deleted file mode 100644
index 23686b8..0000000
--- a/src/com/jsyn/unitgen/ImpulseOscillatorBL.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.MultiTable;
-
-/**
- * Impulse oscillator created by differentiating a sawtoothBL. A band limited impulse is very narrow
- * but is slightly wider than one sample.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class ImpulseOscillatorBL extends SawtoothOscillatorBL {
- private double previous = 0.0;
-
- @Override
- protected double generateBL(MultiTable multiTable, double currentPhase,
- double positivePhaseIncrement, double flevel, int i) {
- double saw = multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
- double result = previous - saw;
- previous = saw;
- return result;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Integrate.java b/src/com/jsyn/unitgen/Integrate.java
deleted file mode 100644
index b5beea9..0000000
--- a/src/com/jsyn/unitgen/Integrate.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * IntegrateUnit unit.
- * <P>
- * Output accumulated sum of the input signal. This can be used to transform one signal into
- * another, or to generate ramps between the limits by setting the input signal positive or
- * negative. For a "leaky integrator" use a FilterOnePoleOneZero.
- * <P>
- *
- * <pre>
- * output = output + input;
- * if (output &lt; lowerLimit)
- * output = lowerLimit;
- * else if (output &gt; upperLimit)
- * output = upperLimit;
- * </pre>
- *
- * @author (C) 1997-2011 Phil Burk, Mobileer Inc
- * @see FilterOnePoleOneZero
- */
-public class Integrate extends UnitGenerator {
- public UnitInputPort input;
- /**
- * Output will be stopped internally from going below this value. Default is -1.0.
- */
- public UnitInputPort lowerLimit;
- /**
- * Output will be stopped internally from going above this value. Default is +1.0.
- */
- public UnitInputPort upperLimit;
- public UnitOutputPort output;
-
- private double accum;
-
- /* Define Unit Ports used by connect() and set(). */
- public Integrate() {
- addPort(input = new UnitInputPort("Input"));
- addPort(lowerLimit = new UnitInputPort("LowerLimit", -1.0));
- addPort(upperLimit = new UnitInputPort("UpperLimit", 1.0));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] lowerLimits = lowerLimit.getValues();
- double[] upperLimits = upperLimit.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- accum += inputs[i]; // INTEGRATE
-
- // clip to limits
- if (accum > upperLimits[i])
- accum = upperLimits[i];
- else if (accum < lowerLimits[i])
- accum = lowerLimits[i];
-
- outputs[i] = accum;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/InterpolatingDelay.java b/src/com/jsyn/unitgen/InterpolatingDelay.java
deleted file mode 100644
index 24de4f9..0000000
--- a/src/com/jsyn/unitgen/InterpolatingDelay.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * InterpolatingDelay
- * <P>
- * InterpolatingDelay provides a variable time delay with an input and output. The internal data
- * format is 32-bit floating point. The amount of delay can be varied from 0.0 to a time in seconds
- * corresponding to the numFrames allocated. The fractional delay values are calculated by linearly
- * interpolating between adjacent values in the delay line.
- * <P>
- * This unit can be used to implement time varying delay effects such as a flanger or a chorus. It
- * can also be used to implement physical models of acoustic instruments, or other tunable delay
- * based resonant systems.
- * <P>
- *
- * @author (C) 1997-2011 Phil Burk, Mobileer Inc
- * @see Delay
- */
-
-public class InterpolatingDelay extends UnitFilter {
- /**
- * Delay time in seconds. This value will converted to frames and clipped between zero and the
- * numFrames value passed to allocate(). The minimum and default delay time is 0.0.
- */
- public UnitInputPort delay;
-
- private float[] buffer;
- private int cursor;
- private int numFrames;
-
- public InterpolatingDelay() {
- addPort(delay = new UnitInputPort("Delay"));
- }
-
- /**
- * Allocate memory for the delay buffer. For a 2 second delay at 44100 Hz sample rate you will
- * need at least 88200 samples.
- *
- * @param numFrames size of the float array to hold the delayed samples
- */
- public void allocate(int numFrames) {
- this.numFrames = numFrames;
- // Allocate extra frame for guard point to speed up interpolation.
- buffer = new float[numFrames + 1];
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double[] delays = delay.getValues();
-
- for (int i = start; i < limit; i++) {
- // This should be at the beginning of the loop
- // because the guard point should == buffer[0].
- if (cursor == numFrames) {
- // Write guard point! Must allocate one extra sample.
- buffer[numFrames] = (float) inputs[i];
- cursor = 0;
- }
-
- buffer[cursor] = (float) inputs[i];
-
- /* Convert delay time to a clipped frame offset. */
- double delayFrames = delays[i] * getFrameRate();
-
- // Clip to zero delay.
- if (delayFrames <= 0.0) {
- outputs[i] = buffer[cursor];
- } else {
- // Clip to maximum delay.
- if (delayFrames >= numFrames) {
- delayFrames = numFrames - 1;
- }
-
- // Calculate fractional index into delay buffer.
- double readIndex = cursor - delayFrames;
- if (readIndex < 0.0) {
- readIndex += numFrames;
- }
- // setup for interpolation.
- // We know readIndex is > 0 so we do not need to call floor().
- int iReadIndex = (int) readIndex;
- double frac = readIndex - iReadIndex;
-
- // Get adjacent values relying on guard point to prevent overflow.
- double val0 = buffer[iReadIndex];
- double val1 = buffer[iReadIndex + 1];
-
- // Interpolate new value.
- outputs[i] = val0 + (frac * (val1 - val0));
- }
-
- cursor += 1;
- }
-
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Latch.java b/src/com/jsyn/unitgen/Latch.java
deleted file mode 100644
index 0518f69..0000000
--- a/src/com/jsyn/unitgen/Latch.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Latch or hold an input value.
- * <p>
- * Pass a value unchanged if gate true, otherwise output held value.
- * <p>
- * output = ( gate &gt; 0.0 ) ? input : previous_output;
- *
- * @author (C) 1997-2010 Phil Burk, Mobileer Inc
- * @see EdgeDetector
- */
-public class Latch extends UnitFilter {
- public UnitInputPort gate;
- private double held;
-
- /* Define Unit Ports used by connect() and set(). */
- public Latch() {
- addPort(gate = new UnitInputPort("Gate"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] gates = gate.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- if (gates[i] > 0.0) {
- held = inputs[i];
- }
- outputs[i] = held;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/LatchZeroCrossing.java b/src/com/jsyn/unitgen/LatchZeroCrossing.java
deleted file mode 100644
index 9e6c011..0000000
--- a/src/com/jsyn/unitgen/LatchZeroCrossing.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2010 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Latches when input crosses zero.
- * <P>
- * Pass a value unchanged if gate true, otherwise pass input unchanged until input crosses zero then
- * output zero. This can be used to turn off a sound at a zero crossing so there is no pop.
- * <P>
- *
- * @author (C) 2010 Phil Burk, Mobileer Inc
- * @see Latch
- * @see Minimum
- */
-public class LatchZeroCrossing extends UnitGenerator {
- public UnitInputPort input;
- public UnitInputPort gate;
- public UnitOutputPort output;
- private double held;
- private boolean crossed;
-
- /* Define Unit Ports used by connect() and set(). */
- public LatchZeroCrossing() {
- addPort(input = new UnitInputPort("Input"));
- addPort(gate = new UnitInputPort("Gate", 1.0));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] gates = gate.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- double current = inputs[i];
- if (gates[i] > 0.0) {
- held = current;
- crossed = false;
- } else {
- // If we haven't already seen a zero crossing then look for one.
- if (!crossed) {
- if ((held * current) <= 0.0) {
- held = 0.0;
- crossed = true;
- } else {
- held = current;
- }
- }
- }
- outputs[i] = held;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/LineIn.java b/src/com/jsyn/unitgen/LineIn.java
deleted file mode 100644
index aeef965..0000000
--- a/src/com/jsyn/unitgen/LineIn.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.Synthesizer;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * External audio input is sent to the output of this unit. The LineIn provides a stereo signal
- * containing channels 0 and 1. For LineIn to work you must call the Synthesizer start() method with
- * numInputChannels &gt; 0.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see Synthesizer
- * @see ChannelIn
- * @see LineOut
- */
-public class LineIn extends UnitGenerator {
- public UnitOutputPort output;
-
- public LineIn() {
- addPort(output = new UnitOutputPort(2, "Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs0 = output.getValues(0);
- double[] outputs1 = output.getValues(1);
- double[] buffer0 = synthesisEngine.getInputBuffer(0);
- double[] buffer1 = synthesisEngine.getInputBuffer(1);
- for (int i = start; i < limit; i++) {
- outputs0[i] = buffer0[i];
- outputs1[i] = buffer1[i];
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/LineOut.java b/src/com/jsyn/unitgen/LineOut.java
deleted file mode 100644
index 29c8ce7..0000000
--- a/src/com/jsyn/unitgen/LineOut.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Input audio is sent to the external audio output device.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class LineOut extends UnitGenerator implements UnitSink {
- public UnitInputPort input;
-
- public LineOut() {
- addPort(input = new UnitInputPort(2, "Input"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs0 = input.getValues(0);
- double[] inputs1 = input.getValues(1);
- double[] buffer0 = synthesisEngine.getOutputBuffer(0);
- double[] buffer1 = synthesisEngine.getOutputBuffer(1);
- for (int i = start; i < limit; i++) {
- buffer0[i] += inputs0[i];
- buffer1[i] += inputs1[i];
- }
- }
-
- /**
- * This unit won't do anything unless you start() it.
- */
- @Override
- public boolean isStartRequired() {
- return true;
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-}
diff --git a/src/com/jsyn/unitgen/LinearRamp.java b/src/com/jsyn/unitgen/LinearRamp.java
deleted file mode 100644
index cad53d5..0000000
--- a/src/com/jsyn/unitgen/LinearRamp.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Output approaches Input linearly.
- * <P>
- * When you change the value of the input port, the ramp will start changing from its current output
- * value toward the value of input. An internal phase value will go from 0.0 to 1.0 at a rate
- * controlled by time. When the internal phase reaches 1.0, the output will equal input.
- * <P>
- *
- * @author (C) 1997 Phil Burk, SoftSynth.com
- * @see ExponentialRamp
- * @see AsymptoticRamp
- * @see ContinuousRamp
- */
-public class LinearRamp extends UnitFilter {
- /** Time in seconds to get to the input value. */
- public UnitInputPort time;
- public UnitVariablePort current;
-
- private double source;
- private double phase;
- private double target;
- private double timeHeld = 0.0;
- private double rate = 1.0;
-
- public LinearRamp() {
- addPort(time = new UnitInputPort("Time"));
- addPort(current = new UnitVariablePort("Current"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
- double currentInput = input.getValues()[0];
- double currentValue = current.getValue();
-
- // If input has changed, start new segment.
- // Equality check is OK because we set them exactly equal below.
- if (currentInput != target)
- {
- source = currentValue;
- phase = 0.0;
- target = currentInput;
- }
-
- if (currentValue == target) {
- // at end of ramp
- for (int i = start; i < limit; i++) {
- outputs[i] = currentValue;
- }
- } else {
- // in middle of ramp
- double currentTime = time.getValues()[0];
- // Has time changed?
- if (currentTime != timeHeld) {
- rate = convertTimeToRate(currentTime);
- timeHeld = currentTime;
- }
-
- for (int i = start; i < limit; i++) {
- if (phase < 1.0) {
- /* Interpolate current. */
- currentValue = source + (phase * (target - source));
- phase += rate;
- } else {
- currentValue = target;
- }
- outputs[i] = currentValue;
- }
- }
-
- current.setValue(currentValue);
- }
-}
diff --git a/src/com/jsyn/unitgen/Maximum.java b/src/com/jsyn/unitgen/Maximum.java
deleted file mode 100644
index 296e5da..0000000
--- a/src/com/jsyn/unitgen/Maximum.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- *
- Output largest of inputA or inputB.
- *
- * <pre>
- * output = (inputA &gt; InputB) ? inputA : InputB;
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Minimum
- */
-public class Maximum extends UnitBinaryOperator {
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = (aValues[i] > bValues[i]) ? aValues[i] : bValues[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/Minimum.java b/src/com/jsyn/unitgen/Minimum.java
deleted file mode 100644
index 046387e..0000000
--- a/src/com/jsyn/unitgen/Minimum.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- *
- Output smallest of inputA or inputB.
- *
- * <pre>
- * output = (inputA &lt; InputB) ? inputA : InputB;
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Maximum
- */
-public class Minimum extends UnitBinaryOperator {
-
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = (aValues[i] < bValues[i]) ? aValues[i] : bValues[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/MixerMono.java b/src/com/jsyn/unitgen/MixerMono.java
deleted file mode 100644
index f4c7d7d..0000000
--- a/src/com/jsyn/unitgen/MixerMono.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Multi-channel mixer with mono output and master amplitude.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- * @see MixerMonoRamped
- * @see MixerStereo
- */
-public class MixerMono extends UnitGenerator implements UnitSink, UnitSource {
- public UnitInputPort input;
- /**
- * Linear gain for the corresponding input.
- */
- public UnitInputPort gain;
- /**
- * Master gain control.
- */
- public UnitInputPort amplitude;
- public UnitOutputPort output;
-
- public MixerMono(int numInputs) {
- addPort(input = new UnitInputPort(numInputs, "Input"));
- addPort(gain = new UnitInputPort(numInputs, "Gain", 1.0));
- addPort(amplitude = new UnitInputPort("Amplitude", 1.0));
- addPort(output = new UnitOutputPort(getNumOutputs(), "Output"));
- }
-
- public int getNumOutputs() {
- return 1;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues(0);
- double[] outputs = output.getValues(0);
- for (int i = start; i < limit; i++) {
- double sum = 0;
- for (int n = 0; n < input.getNumParts(); n++) {
- double[] inputs = input.getValues(n);
- double[] gains = gain.getValues(n);
- sum += inputs[i] * gains[i];
- }
- outputs[i] = sum * amplitudes[i];
- }
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MixerMonoRamped.java b/src/com/jsyn/unitgen/MixerMonoRamped.java
deleted file mode 100644
index 30f5342..0000000
--- a/src/com/jsyn/unitgen/MixerMonoRamped.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Similar to MixerMono but the gain and amplitude ports are smoothed using short linear ramps. So
- * you can control them with knobs and not hear any zipper noise.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- */
-public class MixerMonoRamped extends MixerMono {
- private Unzipper[] unzippers;
- private Unzipper amplitudeUnzipper;
-
- public MixerMonoRamped(int numInputs) {
- super(numInputs);
- unzippers = new Unzipper[numInputs];
- for (int i = 0; i < numInputs; i++) {
- unzippers[i] = new Unzipper();
- }
- amplitudeUnzipper = new Unzipper();
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues(0);
- double[] outputs = output.getValues(0);
- for (int i = start; i < limit; i++) {
- double sum = 0;
- for (int n = 0; n < input.getNumParts(); n++) {
- double[] inputs = input.getValues(n);
- double[] gains = gain.getValues(n);
- double smoothGain = unzippers[n].smooth(gains[i]);
- sum += inputs[i] * smoothGain;
- }
- outputs[i] = sum * amplitudeUnzipper.smooth(amplitudes[i]);
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MixerStereo.java b/src/com/jsyn/unitgen/MixerStereo.java
deleted file mode 100644
index 218546e..0000000
--- a/src/com/jsyn/unitgen/MixerStereo.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Mixer with monophonic inputs and two channels of output. Each signal can be panned left or right
- * using an equal power curve. The "left" signal will be on output part zero. The "right" signal
- * will be on output part one.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- * @see MixerMono
- * @see MixerStereoRamped
- */
-public class MixerStereo extends MixerMono {
- /**
- * Set to -1.0 for all left channel, 0.0 for center, or +1.0 for all right. Or anywhere in
- * between.
- */
- public UnitInputPort pan;
- protected PanTracker[] panTrackers;
-
- static class PanTracker {
- double previousPan = Double.MAX_VALUE; // so we update immediately
- double leftGain;
- double rightGain;
-
- public void update(double pan) {
- if (pan != previousPan) {
- // fastSine range is -1.0 to +1.0 for full cycle.
- // We want a quarter cycle. So map -1.0 to +1.0 into 0.0 to 0.5
- double phase = pan * 0.25 + 0.25;
- leftGain = SineOscillator.fastSin(0.5 - phase);
- rightGain = SineOscillator.fastSin(phase);
- previousPan = pan;
- }
- }
- }
-
- public MixerStereo(int numInputs) {
- super(numInputs);
- addPort(pan = new UnitInputPort(numInputs, "Pan"));
- pan.setup(-1.0, 0.0, 1.0);
- panTrackers = new PanTracker[numInputs];
- for (int i = 0; i < numInputs; i++) {
- panTrackers[i] = new PanTracker();
- }
- }
-
- @Override
- public int getNumOutputs() {
- return 2;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues(0);
- double[] outputs0 = output.getValues(0);
- double[] outputs1 = output.getValues(1);
- for (int i = start; i < limit; i++) {
- double sum0 = 0.0;
- double sum1 = 0.0;
- for (int n = 0; n < input.getNumParts(); n++) {
- double[] inputs = input.getValues(n);
- double[] gains = gain.getValues(n);
- double[] pans = pan.getValues(n);
- PanTracker panTracker = panTrackers[n];
- panTracker.update(pans[i]);
- double scaledInput = inputs[i] * gains[i];
- sum0 += scaledInput * panTracker.leftGain;
- sum1 += scaledInput * panTracker.rightGain;
- }
- double amp = amplitudes[i];
- outputs0[i] = sum0 * amp;
- outputs1[i] = sum1 * amp;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MixerStereoRamped.java b/src/com/jsyn/unitgen/MixerStereoRamped.java
deleted file mode 100644
index 6f3bfcc..0000000
--- a/src/com/jsyn/unitgen/MixerStereoRamped.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Similar to MixerStereo but the gain, pan and amplitude ports are smoothed using short linear
- * ramps. So you can control them with knobs and not hear any zipper noise.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- */
-public class MixerStereoRamped extends MixerStereo {
- private Unzipper[] gainUnzippers;
- private Unzipper[] panUnzippers;
- private Unzipper amplitudeUnzipper;
-
- public MixerStereoRamped(int numInputs) {
- super(numInputs);
- gainUnzippers = new Unzipper[numInputs];
- for (int i = 0; i < numInputs; i++) {
- gainUnzippers[i] = new Unzipper();
- }
- panUnzippers = new Unzipper[numInputs];
- for (int i = 0; i < numInputs; i++) {
- panUnzippers[i] = new Unzipper();
- }
- amplitudeUnzipper = new Unzipper();
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues(0);
- double[] outputs0 = output.getValues(0);
- double[] outputs1 = output.getValues(1);
- for (int i = start; i < limit; i++) {
- double sum0 = 0;
- double sum1 = 0;
- for (int n = 0; n < input.getNumParts(); n++) {
- double[] inputs = input.getValues(n);
- double[] gains = gain.getValues(n);
- double[] pans = pan.getValues(n);
-
- PanTracker panTracker = panTrackers[n];
- double smoothPan = panUnzippers[n].smooth(pans[i]);
- panTracker.update(smoothPan);
-
- double smoothGain = gainUnzippers[n].smooth(gains[i]);
- double scaledInput = inputs[i] * smoothGain;
- sum0 += scaledInput * panTracker.leftGain;
- sum1 += scaledInput * panTracker.rightGain;
- }
- double amp = amplitudeUnzipper.smooth(amplitudes[i]);
- outputs0[i] = sum0 * amp;
- outputs1[i] = sum1 * amp;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MonoStreamWriter.java b/src/com/jsyn/unitgen/MonoStreamWriter.java
deleted file mode 100644
index 283af81..0000000
--- a/src/com/jsyn/unitgen/MonoStreamWriter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import java.io.IOException;
-
-import com.jsyn.io.AudioOutputStream;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Write one sample per audio frame to an AudioOutputStream with no interpolation.
- *
- * Note that you must call start() on this unit because it does not have an output for pulling data.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class MonoStreamWriter extends UnitStreamWriter {
- public MonoStreamWriter() {
- addPort(input = new UnitInputPort("Input"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- AudioOutputStream output = outputStream;
- if (output != null) {
- int count = limit - start;
- try {
- output.write(inputs, start, count);
- } catch (IOException e) {
- }
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MorphingOscillatorBL.java b/src/com/jsyn/unitgen/MorphingOscillatorBL.java
deleted file mode 100644
index 7ca440d..0000000
--- a/src/com/jsyn/unitgen/MorphingOscillatorBL.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.MultiTable;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Oscillator that can change its shape from sine to sawtooth to pulse.
- *
- * @author Phil Burk (C) 2016 Mobileer Inc
- */
-public class MorphingOscillatorBL extends PulseOscillatorBL {
- /**
- * Controls the shape of the waveform.
- * The shape varies continuously from a sine wave at -1.0,
- * to a sawtooth at 0.0 to a pulse wave at 1.0.
- */
- public UnitInputPort shape;
-
- public MorphingOscillatorBL() {
- addPort(shape = new UnitInputPort("Shape"));
- shape.setMinimum(-1.0);
- shape.setMaximum(1.0);
- }
-
- @Override
- protected double generateBL(MultiTable multiTable, double currentPhase,
- double positivePhaseIncrement, double flevel, int i) {
- double[] shapes = shape.getValues();
- double shape = shapes[i];
-
- if (shape < 0.0) {
- // Squeeze flevel towards the pure sine table.
- flevel += flevel * shape;
- return multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
- } else {
- double[] widths = width.getValues();
- double width = widths[i];
- width = (width > 0.999) ? 0.999 : ((width < -0.999) ? -0.999 : width);
-
- double val1 = multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
- // Generate second sawtooth so we can add them together.
- double phase2 = currentPhase + 1.0 - width; // 180 degrees out of phase
- if (phase2 >= 1.0) {
- phase2 -= 2.0;
- }
- double val2 = multiTable.calculateSawtooth(phase2, positivePhaseIncrement, flevel);
-
- /*
- * Need to adjust amplitude based on positive phaseInc. little less than half at
- * Nyquist/2.0!
- */
- double scale = 1.0 - positivePhaseIncrement;
- return scale * (val1 - ((val2 + width) * shape)); // apply shape morphing
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/MultiPassThrough.java b/src/com/jsyn/unitgen/MultiPassThrough.java
deleted file mode 100644
index 9125fc3..0000000
--- a/src/com/jsyn/unitgen/MultiPassThrough.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Pass the input through to the output unchanged. This is often used for distributing a signal to
- * multiple ports inside a circuit. It can also be used as a summing node, in other words, a mixer.
- *
- * This is just like PassThrough except the input and output ports have multiple parts.
- * The default is two parts, ie. stereo.
- *
- * @author Phil Burk (C) 2016 Mobileer Inc
- * @see Circuit
- * @see PassThrough
- */
-public class MultiPassThrough extends UnitGenerator implements UnitSink, UnitSource {
- public UnitInputPort input;
- public UnitOutputPort output;
- private final int mNumParts;
-
- /* Define Unit Ports used by connect() and set(). */
- public MultiPassThrough(int numParts) {
- mNumParts = numParts;
- addPort(input = new UnitInputPort(numParts, "Input"));
- addPort(output = new UnitOutputPort(numParts, "Output"));
- }
-
- public MultiPassThrough() {
- this(2); // stereo
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
- @Override
- public void generate(int start, int limit) {
- for (int partIndex = 0; partIndex < mNumParts; partIndex++) {
- double[] inputs = input.getValues(partIndex);
- double[] outputs = output.getValues(partIndex);
-
- for (int i = start; i < limit; i++) {
- outputs[i] = inputs[i];
- }
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/Multiply.java b/src/com/jsyn/unitgen/Multiply.java
deleted file mode 100644
index ded7646..0000000
--- a/src/com/jsyn/unitgen/Multiply.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * This unit multiplies its two inputs. <br>
- *
- * <pre>
- * output = inputA * inputB
- * </pre>
- *
- * <br>
- * Note that some units have an amplitude port, which controls an internal multiply. So you may not
- * need this unit.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see MultiplyAdd
- * @see Subtract
- */
-public class Multiply extends UnitBinaryOperator {
- public Multiply() {
- }
-
- /** Connect a to inputA and b to inputB. */
- public Multiply(UnitOutputPort a, UnitOutputPort b) {
- a.connect(inputA);
- b.connect(inputB);
- }
-
- /** Connect a to inputA and b to inputB and connect output to c. */
- public Multiply(UnitOutputPort a, UnitOutputPort b, UnitInputPort c) {
- this(a, b);
- output.connect(c);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
- for (int i = start; i < limit; i++) {
- outputs[i] = aValues[i] * bValues[i];
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/MultiplyAdd.java b/src/com/jsyn/unitgen/MultiplyAdd.java
deleted file mode 100644
index adbee6c..0000000
--- a/src/com/jsyn/unitgen/MultiplyAdd.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * <pre>
- * output = (inputA * inputB) + inputC
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see Multiply
- * @see Add
- */
-public class MultiplyAdd extends UnitGenerator {
- public UnitInputPort inputA;
- public UnitInputPort inputB;
- public UnitInputPort inputC;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public MultiplyAdd() {
- addPort(inputA = new UnitInputPort("InputA"));
- addPort(inputB = new UnitInputPort("InputB"));
- addPort(inputC = new UnitInputPort("InputC"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] cValues = inputC.getValues();
- double[] outputs = output.getValues();
- for (int i = start; i < limit; i++) {
- outputs[i] = (aValues[i] * bValues[i]) + cValues[i];
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Pan.java b/src/com/jsyn/unitgen/Pan.java
deleted file mode 100644
index bc90984..0000000
--- a/src/com/jsyn/unitgen/Pan.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Pan unit. The profile is constant amplitude and not constant energy.
- * <P>
- * Takes an input and pans it between two outputs based on value of pan. When pan is -1, output[0]
- * is input, and output[1] is zero. When pan is 0, output[0] and output[1] are both input/2. When
- * pan is +1, output[0] is zero, and output[1] is input.
- * <P>
- *
- * @author (C) 1997 Phil Burk, SoftSynth.com
- * @see Select
- */
-public class Pan extends UnitGenerator {
- public UnitInputPort input;
- /**
- * Pan control varies from -1.0 for full left to +1.0 for full right. Set to 0.0 for center.
- */
- public UnitInputPort pan;
- public UnitOutputPort output;
-
- public Pan() {
- addPort(input = new UnitInputPort("Input"));
- addPort(pan = new UnitInputPort("Pan"));
- addPort(output = new UnitOutputPort(2, "Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] panPtr = pan.getValues();
- double[] outputs_0 = output.getValues(0);
- double[] outputs_1 = output.getValues(1);
-
- for (int i = start; i < limit; i++) {
- double gainB = (panPtr[i] * 0.5) + 0.5; /*
- * Scale and offset to 0.0 to 1.0
- */
- double gainA = 1.0 - gainB;
- double inVal = inputs[i];
- outputs_0[i] = inVal * gainA;
- outputs_1[i] = inVal * gainB;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/PanControl.java b/src/com/jsyn/unitgen/PanControl.java
deleted file mode 100644
index 63bddd8..0000000
--- a/src/com/jsyn/unitgen/PanControl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * PanControl unit.
- * <P>
- * Generates control signals that can be used to control a mixer or the amplitude ports of two
- * units.
- *
- * <PRE>
- * temp = (pan * 0.5) + 0.5;
- * output[0] = temp;
- * output[1] = 1.0 - temp;
- * </PRE>
- * <P>
- *
- * @author (C) 1997-2009 Phil Burk, SoftSynth.com
- */
-public class PanControl extends UnitGenerator {
- public UnitInputPort pan;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public PanControl() {
- addPort(pan = new UnitInputPort("Pan"));
- addPort(output = new UnitOutputPort(2, "Output", 0.0));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] panPtr = pan.getValues();
- double[] output0s = output.getValues(0);
- double[] output1s = output.getValues(1);
-
- for (int i = start; i < limit; i++) {
- double gainB = (panPtr[i] * 0.5) + 0.5; /*
- * Scale and offset to 0.0 to 1.0
- */
- output0s[i] = 1.0 - gainB;
- output1s[i] = gainB;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/ParabolicEnvelope.java b/src/com/jsyn/unitgen/ParabolicEnvelope.java
deleted file mode 100644
index 6de97d9..0000000
--- a/src/com/jsyn/unitgen/ParabolicEnvelope.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * ParabolicEnvelope unit. Output goes from zero to amplitude then back to zero in a parabolic arc.
- * <P>
- * Generate a short parabolic envelope that could be used for granular synthesis. The output starts
- * at zero, peaks at the value of amplitude then returns to zero. This unit has two states, IDLE and
- * RUNNING. If a trigger is received when IDLE, the envelope is started and another trigger is sent
- * out the triggerOutput port. This triggerOutput can be used to latch values for the synthesis of a
- * grain. If a trigger is received when RUNNING, then it is ignored and passed out the triggerPass
- * port. The triggerPass can be connected to the triggerInput of another ParabolicEnvelope. Thus you
- * can implement a simple grain allocation scheme by daisy chaining the triggers of
- * ParabolicEnvelopes.
- * <P>
- * The envelope is generated by a double integrator method so it uses relatively little CPU time.
- *
- * @author (C) 1997 Phil Burk, SoftSynth.com
- * @see EnvelopeDAHDSR
- */
-public class ParabolicEnvelope extends UnitGenerator {
-
- /** Fastest repeat rate of envelope if it were continually retriggered in Hertz. */
- public UnitInputPort frequency;
- /** True value triggers envelope when in resting state. */
- public UnitInputPort triggerInput;
- public UnitInputPort amplitude;
-
- /** Trigger output when envelope started. */
- public UnitOutputPort triggerOutput;
- /** Input trigger passed out if ignored for daisy chaining. */
- public UnitOutputPort triggerPass;
- public UnitOutputPort output;
-
- private double slope;
- private double curve;
- private double level;
- private boolean running;
-
- /* Define Unit Ports used by connect() and set(). */
- public ParabolicEnvelope() {
- addPort(triggerInput = new UnitInputPort("Input"));
- addPort(frequency = new UnitInputPort("Frequency", UnitOscillator.DEFAULT_FREQUENCY));
- addPort(amplitude = new UnitInputPort("Amplitude", UnitOscillator.DEFAULT_AMPLITUDE));
-
- addPort(output = new UnitOutputPort("Output"));
- addPort(triggerOutput = new UnitOutputPort("TriggerOutput"));
- addPort(triggerPass = new UnitOutputPort("TriggerPass"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] triggerInputs = triggerInput.getValues();
- double[] outputs = output.getValues();
- double[] triggerPasses = triggerPass.getValues();
- double[] triggerOutputs = triggerOutput.getValues();
-
- for (int i = start; i < limit; i++) {
- if (!running) {
- if (triggerInputs[i] > 0) {
- double freq = frequencies[i] * synthesisEngine.getInverseNyquist();
- freq = (freq > 1.0) ? 1.0 : ((freq < -1.0) ? -1.0 : freq);
- double ampl = amplitudes[i];
- double freq2 = freq * freq; /* Square frequency. */
- slope = 4.0 * ampl * (freq - freq2);
- curve = -8.0 * ampl * freq2;
- level = 0.0;
- triggerOutputs[i] = UnitGenerator.TRUE;
- running = true;
- } else {
- triggerOutputs[i] = UnitGenerator.FALSE;
- }
- triggerPasses[i] = UnitGenerator.FALSE;
- } else /* RUNNING */
- {
- level += slope;
- slope += curve;
- if (level <= 0.0) {
- level = 0.0;
- running = false;
- /* Autostop? - FIXME */
- }
-
- triggerOutputs[i] = UnitGenerator.FALSE;
- triggerPasses[i] = triggerInputs[i];
- }
- outputs[i] = level;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/PassThrough.java b/src/com/jsyn/unitgen/PassThrough.java
deleted file mode 100644
index 8ac0b93..0000000
--- a/src/com/jsyn/unitgen/PassThrough.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Pass the input through to the output unchanged. This is often used for distributing a signal to
- * multiple ports inside a circuit. It can also be used as a summing node, in other words, a mixer.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see Circuit
- * @see MultiPassThrough
- */
-public class PassThrough extends UnitFilter {
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = inputs[i];
- }
-
- }
-}
diff --git a/src/com/jsyn/unitgen/PeakFollower.java b/src/com/jsyn/unitgen/PeakFollower.java
deleted file mode 100644
index 7bf0508..0000000
--- a/src/com/jsyn/unitgen/PeakFollower.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.ports.UnitVariablePort;
-
-/**
- * Tracks the peaks of an input signal. This can be used to monitor the overall amplitude of a
- * signal. The output can be used to drive color organs, vocoders, VUmeters, etc. Output drops
- * exponentially when the input drops below the current output level. The output approaches zero
- * based on the value on the halfLife port.
- *
- * @author (C) 1997-2009 Phil Burk, SoftSynth.com
- */
-public class PeakFollower extends UnitGenerator {
- public UnitInputPort input;
- public UnitVariablePort current;
- public UnitInputPort halfLife;
- public UnitOutputPort output;
-
- private double previousHalfLife = -1.0;
- private double decayScalar = 0.99;
-
- /* Define Unit Ports used by connect() and set(). */
- public PeakFollower() {
- addPort(input = new UnitInputPort("Input"));
- addPort(halfLife = new UnitInputPort(1, "HalfLife", 0.1));
- addPort(current = new UnitVariablePort("Current"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double currentHalfLife = halfLife.getValues()[0];
- double currentValue = current.getValue();
-
- if (currentHalfLife != previousHalfLife) {
- decayScalar = this.convertHalfLifeToMultiplier(currentHalfLife);
- previousHalfLife = currentHalfLife;
- }
-
- double scalar = 1.0 - decayScalar;
-
- for (int i = start; i < limit; i++) {
- double inputValue = inputs[i];
- if (inputValue < 0.0) {
- inputValue = -inputValue; // absolute value
- }
-
- if (inputValue >= currentValue) {
- currentValue = inputValue;
- } else {
- currentValue = currentValue * scalar;
- }
-
- outputs[i] = currentValue;
- }
-
- /*
- * When current gets close to zero, set current to zero to prevent FP underflow, which can
- * cause a severe performance degradation in 'C'.
- */
- if (currentValue < VERY_SMALL_FLOAT) {
- currentValue = 0.0;
- }
-
- current.setValue(currentValue);
- }
-}
diff --git a/src/com/jsyn/unitgen/PhaseShifter.java b/src/com/jsyn/unitgen/PhaseShifter.java
deleted file mode 100644
index 4b17245..0000000
--- a/src/com/jsyn/unitgen/PhaseShifter.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * PhaseShifter effects processor. This unit emulates a common guitar pedal effect but without the
- * LFO modulation. You can use your own modulation source connected to the "offset" port. Different
- * frequencies are phase shifted varying amounts using a series of AllPass filters. By feeding the
- * output back to the input we can get varying phase cancellation. This implementation was based on
- * code posted to the music-dsp archive by Ross Bencina. http://www.musicdsp.org/files/phaser.cpp
- *
- * @author (C) 2014 Phil Burk, Mobileer Inc
- * @see FilterLowPass
- * @see FilterAllPass
- * @see RangeConverter
- */
-
-public class PhaseShifter extends UnitFilter {
- /**
- * Connect an oscillator to this port to sweep the phase. A range of 0.05 to 0.4 is a good
- * start.
- */
- public UnitInputPort offset;
- public UnitInputPort feedback;
- public UnitInputPort depth;
-
- private double zm1;
- private double[] xs;
- private double[] ys;
-
- public PhaseShifter() {
- this(6);
- }
-
- public PhaseShifter(int numStages) {
- addPort(offset = new UnitInputPort("Offset", 0.1));
- addPort(feedback = new UnitInputPort("Feedback", 0.7));
- addPort(depth = new UnitInputPort("Depth", 1.0));
-
- xs = new double[numStages];
- ys = new double[numStages];
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
- double[] feedbacks = feedback.getValues();
- double[] depths = depth.getValues();
- double[] offsets = offset.getValues();
- double gain;
-
- for (int i = start; i < limit; i++) {
- // Support audio rate modulation.
- double currentOffset = offsets[i];
-
- // Prevent gain from exceeding 1.0.
- gain = 1.0 - (currentOffset * currentOffset);
- if (gain < -1.0) {
- gain = -1.0;
- }
-
- double x = inputs[i] + (zm1 * feedbacks[i]);
- // Cascaded all-pass filters.
- for (int stage = 0; stage < xs.length; stage++) {
- double temp = ys[stage] = (gain * (ys[stage] - x)) + xs[stage];
- xs[stage] = x;
- x = temp;
- }
- zm1 = x;
- outputs[i] = inputs[i] + (x * depths[i]);
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/PinkNoise.java b/src/com/jsyn/unitgen/PinkNoise.java
deleted file mode 100644
index 84aa2f2..0000000
--- a/src/com/jsyn/unitgen/PinkNoise.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.util.PseudoRandom;
-
-/**
- * Random output with 3dB per octave rolloff providing a soft natural noise sound. Generated using
- * Gardner method. Optimization suggested by James McCartney uses a tree to select which random
- * value to replace.
- *
- * <pre>
- * x x x x x x x x x x x x x x x x
- * x x x x x x x x
- * x x x x
- * x x
- * x
- * </pre>
- *
- * Tree is generated by counting trailing zeros in an increasing index. When the index is zero, no
- * random number is selected. Author: Phil Burk (C) 1996 SoftSynth.com.
- */
-
-public class PinkNoise extends UnitGenerator implements UnitSource {
-
- public UnitInputPort amplitude;
- public UnitOutputPort output;
-
- private final int NUM_ROWS = 16;
- private final int RANDOM_BITS = 24;
- private final int RANDOM_SHIFT = 32 - RANDOM_BITS;
-
- private PseudoRandom randomNum;
- protected double prevNoise, currNoise;
-
- private long[] rows = new long[NUM_ROWS]; // NEXT RANDOM UNSIGNED 32
- private double scalar; // used to scale within range of -1.0 to +1.0
- private int runningSum; // used to optimize summing of generators
- private int index; // incremented with each sample
- private int indexMask; // index wrapped and ANDing with this mask
-
- /* Define Unit Ports used by connect() and set(). */
- public PinkNoise() {
- addPort(amplitude = new UnitInputPort("Amplitude", UnitOscillator.DEFAULT_AMPLITUDE));
- addPort(output = new UnitOutputPort("Output"));
-
- randomNum = new PseudoRandom();
-
- // set up for N rows of generators
- index = 0;
- indexMask = (1 << NUM_ROWS) - 1;
-
- // Calculate maximum possible signed random value. Extra 1 for white
- // noise always added.
- int pmax = (NUM_ROWS + 1) * (1 << (RANDOM_BITS - 1));
- scalar = 1.0 / pmax;
-
- // initialize rows
- for (int i = 0; i < NUM_ROWS; i++) {
- rows[i] = 0;
- }
-
- runningSum = 0;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = generatePinkNoise() * amplitudes[i];
- }
- }
-
- public double generatePinkNoise() {
- index = (index + 1) & indexMask;
-
- // If index is zero, don't update any random values.
- if (index != 0) {
- // Determine how many trailing zeros in PinkIndex.
- // This algorithm will hang of n==0 so test first
- int numZeros = 0;
- int n = index;
-
- while ((n & 1) == 0) {
- n = n >> 1;
- numZeros++;
- }
-
- // Replace the indexed ROWS random value.
- // Subtract and add back to RunningSum instead of adding all the
- // random values together. Only one changes each time.
- runningSum -= rows[numZeros];
- int newRandom = randomNum.nextRandomInteger() >> RANDOM_SHIFT;
- runningSum += newRandom;
- rows[numZeros] = newRandom;
- }
-
- // Add extra white noise value.
- int newRandom = randomNum.nextRandomInteger() >> RANDOM_SHIFT;
- int sum = runningSum + newRandom;
-
- // Scale to range of -1.0 to 0.9999.
- return scalar * sum;
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-}
diff --git a/src/com/jsyn/unitgen/PitchDetector.java b/src/com/jsyn/unitgen/PitchDetector.java
deleted file mode 100644
index da6a0e3..0000000
--- a/src/com/jsyn/unitgen/PitchDetector.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2012 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.util.AutoCorrelator;
-import com.jsyn.util.SignalCorrelator;
-
-/**
- * Estimate the fundamental frequency of a monophonic signal. Analyzes an input signal and outputs
- * an estimated period in frames and a frequency in Hertz. The frequency is frameRate/period. The
- * confidence tells you how accurate the estimate is. When the confidence is low, you should ignore
- * the period. You can use a CompareUnit and a LatchUnit to hold values that you are confident of.
- * <P>
- * Note that a stable monophonic signal is required for accurate pitch tracking.
- *
- * @author (C) 2012 Phil Burk, Mobileer Inc
- */
-public class PitchDetector extends UnitGenerator {
- public UnitInputPort input;
-
- public UnitOutputPort period;
- public UnitOutputPort confidence;
- public UnitOutputPort frequency;
- public UnitOutputPort updated;
-
- protected SignalCorrelator signalCorrelator;
-
- private double lastFrequency = 440.0;
- private double lastPeriod = 44100.0 / lastFrequency; // result of analysis TODO update for 48000
- private double lastConfidence = 0.0; // Measure of confidence in the result.
-
- private static final int LOWEST_FREQUENCY = 40;
- private static final int HIGHEST_RATE = 48000;
- private static final int CYCLES_NEEDED = 2;
-
- public PitchDetector() {
- super();
- addPort(input = new UnitInputPort("Input"));
-
- addPort(period = new UnitOutputPort("Period"));
- addPort(confidence = new UnitOutputPort("Confidence"));
- addPort(frequency = new UnitOutputPort("Frequency"));
- addPort(updated = new UnitOutputPort("Updated"));
- signalCorrelator = createSignalCorrelator();
- }
-
- public SignalCorrelator createSignalCorrelator() {
- int framesNeeded = HIGHEST_RATE * CYCLES_NEEDED / LOWEST_FREQUENCY;
- return new AutoCorrelator(framesNeeded);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] periods = period.getValues();
- double[] confidences = confidence.getValues();
- double[] frequencies = frequency.getValues();
- double[] updateds = updated.getValues();
-
- for (int i = start; i < limit; i++) {
- double current = inputs[i];
- if (signalCorrelator.addSample(current)) {
- lastPeriod = signalCorrelator.getPeriod();
- if (lastPeriod < 0.1) {
- System.out.println("ILLEGAL PERIOD");
- }
- double currentFrequency = getFrameRate() / (lastPeriod + 0);
- double confidence = signalCorrelator.getConfidence();
- if (confidence > 0.1) {
- if (true) {
- double coefficient = confidence * 0.2;
- // Take weighted average with previous frequency.
- lastFrequency = ((lastFrequency * (1.0 - coefficient)) + (currentFrequency * coefficient));
- } else {
- lastFrequency = ((lastFrequency * lastConfidence) + (currentFrequency * confidence))
- / (lastConfidence + confidence);
- }
- }
- lastConfidence = confidence;
- updateds[i] = 1.0;
- } else {
- updateds[i] = 0.0;
- }
- periods[i] = lastPeriod;
- confidences[i] = lastConfidence;
- frequencies[i] = lastFrequency;
- }
- }
-
- /**
- * For debugging only.
- *
- * @return internal array of correlation results.
- */
- public float[] getDiffs() {
- return signalCorrelator.getDiffs();
- }
-
-}
diff --git a/src/com/jsyn/unitgen/PitchToFrequency.java b/src/com/jsyn/unitgen/PitchToFrequency.java
deleted file mode 100644
index 9086749..0000000
--- a/src/com/jsyn/unitgen/PitchToFrequency.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.jsyn.unitgen;
-
-import com.softsynth.math.AudioMath;
-
-public class PitchToFrequency extends PowerOfTwo {
-
- public PitchToFrequency() {
- input.setup(0.0, 60.0, 127.0);
- }
-
- /**
- * Convert from MIDI pitch to an octave offset from Concert A.
- */
- @Override
- public double adjustInput(double in) {
- return (in - AudioMath.CONCERT_A_PITCH) * (1.0/12.0);
- }
-
- /**
- * Convert scaler to a frequency relative to Concert A.
- */
- @Override
- public double adjustOutput(double out) {
- return out * AudioMath.getConcertAFrequency();
- }
-}
diff --git a/src/com/jsyn/unitgen/PowerOfTwo.java b/src/com/jsyn/unitgen/PowerOfTwo.java
deleted file mode 100644
index 5916860..0000000
--- a/src/com/jsyn/unitgen/PowerOfTwo.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2010 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * output = (2.0^input) This is useful for converting a pitch modulation value into a frequency
- * scaler. An input value of +1.0 will output 2.0 for an octave increase. An input value of -1.0
- * will output 0.5 for an octave decrease.
- *
- * This implementation uses a table lookup to optimize for
- * speed. It is accurate enough for tuning. It also checks to see if the current input value is the
- * same as the previous input value. If so then it reuses the previous computed value.
- *
- * @author Phil Burk (C) 2010 Mobileer Inc
- */
-public class PowerOfTwo extends UnitGenerator {
- /**
- * Offset in octaves.
- */
- public UnitInputPort input;
- public UnitOutputPort output;
-
- private static double[] table;
- private static final int NUM_VALUES = 2048;
- // Cached computation.
- private double lastInput = 0.0;
- private double lastOutput = 1.0;
-
- static {
- // Add guard point for faster interpolation.
- // Add another point to handle inputs like -1.5308084989341915E-17,
- // which generate indices above range.
- table = new double[NUM_VALUES + 2];
- // Fill one octave of the table.
- for (int i = 0; i < table.length; i++) {
- double value = Math.pow(2.0, ((double) i) / NUM_VALUES);
- table[i] = value;
- }
- }
-
- public PowerOfTwo() {
- addPort(input = new UnitInputPort("Input"));
- input.setup(-8.0, 0.0, 8.0);
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- double in = inputs[i];
- // Can we reuse a previously computed value?
- if (in == lastInput) {
- outputs[i] = lastOutput;
- } else {
- lastInput = in;
- double adjustedInput = adjustInput(in);
- int octave = (int) Math.floor(adjustedInput);
- double normal = adjustedInput - octave;
- // Do table lookup.
- double findex = normal * NUM_VALUES;
- int index = (int) findex;
- double fraction = findex - index;
- double value = table[index] + (fraction * (table[index + 1] - table[index]));
-
- // Adjust for octave.
- while (octave > 0) {
- octave -= 1;
- value *= 2.0;
- }
- while (octave < 0) {
- octave += 1;
- value *= 0.5;
- }
- double adjustedOutput = adjustOutput(value);
- outputs[i] = adjustedOutput;
- lastOutput = adjustedOutput;
- }
- }
- }
-
- public double adjustInput(double in) {
- return in;
- }
-
- public double adjustOutput(double out) {
- return out;
- }
-}
diff --git a/src/com/jsyn/unitgen/PulseOscillator.java b/src/com/jsyn/unitgen/PulseOscillator.java
deleted file mode 100644
index 5ac7352..0000000
--- a/src/com/jsyn/unitgen/PulseOscillator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Simple pulse wave oscillator.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class PulseOscillator extends UnitOscillator {
- /**
- * Pulse width varies from -1.0 to +1.0. At 0.0 the pulse is actually a square wave.
- */
- public UnitInputPort width;
-
- public PulseOscillator() {
- addPort(width = new UnitInputPort("Width"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] widths = width.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- // Generate sawtooth phaser to provide phase for pulse generation.
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- double ampl = amplitudes[i];
- // Either full negative or positive amplitude.
- outputs[i] = (currentPhase < widths[i]) ? -ampl : ampl;
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/PulseOscillatorBL.java b/src/com/jsyn/unitgen/PulseOscillatorBL.java
deleted file mode 100644
index c0e234c..0000000
--- a/src/com/jsyn/unitgen/PulseOscillatorBL.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.MultiTable;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Pulse oscillator that uses two band limited sawtooth waveforms.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class PulseOscillatorBL extends SawtoothOscillatorBL {
- /** Controls the duty cycle of the pulse waveform.
- * The width varies from -1.0 to +1.0.
- * When width is zero the output is a square wave.
- */
- public UnitInputPort width;
-
- public PulseOscillatorBL() {
- addPort(width = new UnitInputPort("Width"));
- }
-
- @Override
- protected double generateBL(MultiTable multiTable, double currentPhase,
- double positivePhaseIncrement, double flevel, int i) {
- double[] widths = width.getValues();
- double width = widths[i];
- width = (width > 0.999) ? 0.999 : ((width < -0.999) ? -0.999 : width);
-
- double val1 = multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
-
- // Generate second sawtooth so we can add them together.
- double phase2 = currentPhase + 1.0 - width; // 180 degrees out of phase
- if (phase2 >= 1.0) {
- phase2 -= 2.0;
- }
- double val2 = multiTable.calculateSawtooth(phase2, positivePhaseIncrement, flevel);
-
- /*
- * Need to adjust amplitude based on positive phaseInc and width. little less than half at
- * Nyquist/2.0!
- */
- double scale = 1.0 - positivePhaseIncrement;
- return scale * (val1 - val2 - width);
- }
-}
diff --git a/src/com/jsyn/unitgen/RaisedCosineEnvelope.java b/src/com/jsyn/unitgen/RaisedCosineEnvelope.java
deleted file mode 100644
index c32417c..0000000
--- a/src/com/jsyn/unitgen/RaisedCosineEnvelope.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * An envelope that can be used in a GrainFarm to shape the amplitude of a Grain. The envelope
- * starts at 0.0, rises to 1.0, then returns to 0.0 following a cosine curve.
- *
- * <pre>
- * output = 0.5 - (0.5 * cos(phase))
- * </pre>
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see GrainFarm
- */
-public class RaisedCosineEnvelope extends GrainCommon implements GrainEnvelope {
- protected double phase;
- protected double phaseIncrement;
-
- public RaisedCosineEnvelope() {
- setFrameRate(44100);
- setDuration(0.1);
- }
-
- /**
- * @return next value of the envelope.
- */
- @Override
- public double next() {
- phase += phaseIncrement;
- if (phase > (2.0 * Math.PI)) {
- return 0.0;
- } else {
- return 0.5 - (0.5 * Math.cos(phase)); // TODO optimize using Taylor expansion
- }
- }
-
- /**
- * @return true if there are more envelope values left.
- */
- @Override
- public boolean hasMoreValues() {
- return (phase < (2.0 * Math.PI));
- }
-
- /**
- * Reset the envelope back to the beginning.
- */
- @Override
- public void reset() {
- phase = 0.0;
- }
-
- @Override
- public void setDuration(double duration) {
- phaseIncrement = 2.0 * Math.PI / (getFrameRate() * duration);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/RangeConverter.java b/src/com/jsyn/unitgen/RangeConverter.java
deleted file mode 100644
index ae94b0f..0000000
--- a/src/com/jsyn/unitgen/RangeConverter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Convert an input signal between -1.0 and +1.0 to the range min to max. This is handy when using
- * an oscillator as a modulator.
- *
- * @author (C) 2014 Phil Burk, Mobileer Inc
- * @see EdgeDetector
- */
-public class RangeConverter extends UnitFilter {
- public UnitInputPort min;
- public UnitInputPort max;
-
- /* Define Unit Ports used by connect() and set(). */
- public RangeConverter() {
- addPort(min = new UnitInputPort("Min", 40.0));
- addPort(max = new UnitInputPort("Max", 2000.0));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] mins = min.getValues();
- double[] maxs = max.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- double low = mins[i];
- outputs[i] = low + ((maxs[i] - low) * (inputs[i] + 1) * 0.5);
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/RectangularWindow.java b/src/com/jsyn/unitgen/RectangularWindow.java
deleted file mode 100644
index d61f763..0000000
--- a/src/com/jsyn/unitgen/RectangularWindow.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.SpectralWindow;
-
-/**
- * Window that is just 1.0. Flat like a rectangle.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @see SpectralFFT
- */
-public class RectangularWindow implements SpectralWindow {
- static RectangularWindow instance = new RectangularWindow();
-
- @Override
- /** This always returns 1.0. Do not pass indices outside the window range. */
- public double get(int index) {
- return 1.0; // impressive, eh?
- }
-
- public static RectangularWindow getInstance() {
- return instance;
- }
-}
diff --git a/src/com/jsyn/unitgen/RedNoise.java b/src/com/jsyn/unitgen/RedNoise.java
deleted file mode 100644
index d3e4321..0000000
--- a/src/com/jsyn/unitgen/RedNoise.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.util.PseudoRandom;
-
-/**
- * RedNoise unit. This unit interpolates straight line segments between pseudo-random numbers to
- * produce "red" noise. It is a grittier alternative to the white generator WhiteNoise. It is also
- * useful as a slowly changing random control generator for natural sounds. Frequency port controls
- * the number of times per second that a new random number is chosen.
- *
- * @author (C) 1997 Phil Burk, SoftSynth.com
- * @see WhiteNoise
- */
-public class RedNoise extends UnitOscillator {
- private PseudoRandom randomNum;
- protected double prevNoise, currNoise;
-
- /* Define Unit Ports used by connect() and set(). */
- public RedNoise() {
- super();
- randomNum = new PseudoRandom();
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] frequencies = frequency.getValues();
- double[] outputs = output.getValues();
- double currPhase = phase.getValue();
- double phaseIncrement, currOutput;
-
- double framePeriod = getFramePeriod();
-
- for (int i = start; i < limit; i++) {
- // compute phase
- phaseIncrement = frequencies[i] * framePeriod;
-
- // verify that phase is within minimums and is not negative
- if (phaseIncrement < 0.0) {
- phaseIncrement = 0.0 - phaseIncrement;
- }
- if (phaseIncrement > 1.0) {
- phaseIncrement = 1.0;
- }
-
- currPhase += phaseIncrement;
-
- // calculate new random whenever phase passes 1.0
- if (currPhase > 1.0) {
- prevNoise = currNoise;
- currNoise = randomNum.nextRandomDouble();
- // reset phase for interpolation
- currPhase -= 1.0;
- }
-
- // interpolate current
- currOutput = prevNoise + (currPhase * (currNoise - prevNoise));
- outputs[i] = currOutput * amplitudes[i];
- }
-
- // store new phase
- phase.setValue(currPhase);
- }
-}
diff --git a/src/com/jsyn/unitgen/SampleGrainFarm.java b/src/com/jsyn/unitgen/SampleGrainFarm.java
deleted file mode 100644
index 3f908d6..0000000
--- a/src/com/jsyn/unitgen/SampleGrainFarm.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.FloatSample;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * A GrainFarm that uses a FloatSample as source material. In this example we load a FloatSample for
- * use as a source material.
- *
- * <pre><code>
- synth.add(sampleGrainFarm = new SampleGrainFarm());
- // Load a sample that we want to "granulate" from a file.
- sample = SampleLoader.loadFloatSample(sampleFile);
- sampleGrainFarm.setSample(sample);
- // Use a ramp to move smoothly within the file.
- synth.add(ramp = new ContinuousRamp());
- ramp.output.connect(sampleGrainFarm.position);
-</code></pre>
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public class SampleGrainFarm extends GrainFarm {
- private FloatSample sample;
- public UnitInputPort position;
- public UnitInputPort positionRange;
-
- public SampleGrainFarm() {
- super();
- addPort(position = new UnitInputPort("Position", 0.0));
- addPort(positionRange = new UnitInputPort("PositionRange", 0.0));
- }
-
- @Override
- public void allocate(int numGrains) {
- Grain[] grainArray = new Grain[numGrains];
- for (int i = 0; i < numGrains; i++) {
- Grain grain = new Grain(new SampleGrainSource(), new RaisedCosineEnvelope());
- grainArray[i] = grain;
- }
- setGrainArray(grainArray);
- }
-
- @Override
- public void setupGrain(Grain grain, int i) {
- SampleGrainSource sampleGrainSource = (SampleGrainSource) grain.getSource();
- sampleGrainSource.setSample(sample);
- sampleGrainSource.setPosition(position.getValues()[i]);
- sampleGrainSource.setPositionRange(positionRange.getValues()[i]);
- super.setupGrain(grain, i);
- }
-
- public void setSample(FloatSample sample) {
- this.sample = sample;
- }
-}
diff --git a/src/com/jsyn/unitgen/SampleGrainSource.java b/src/com/jsyn/unitgen/SampleGrainSource.java
deleted file mode 100644
index f33817f..0000000
--- a/src/com/jsyn/unitgen/SampleGrainSource.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.FloatSample;
-
-public class SampleGrainSource extends GrainCommon implements GrainSource {
- private FloatSample sample;
- private double position; // ranges from -1.0 to 1.0
- private double positionRange;
- private double phase; // ranges from 0.0 to 1.0
- private double phaseIncrement;
- private int numFramesGuarded;
- private static final double MAX_PHASE = 0.9999999999;
-
- @Override
- public double next() {
- phase += phaseIncrement;
- if (phase > MAX_PHASE) {
- phase = MAX_PHASE;
- }
- double fractionalIndex = phase * numFramesGuarded;
- return sample.interpolate(fractionalIndex);
- }
-
- @Override
- public void setRate(double rate) {
- phaseIncrement = rate * sample.getFrameRate() / (getFrameRate() * numFramesGuarded);
- }
-
- public void setSample(FloatSample sample) {
- this.sample = sample;
- numFramesGuarded = sample.getNumFrames() - 1;
- }
-
- public void setPosition(double position) {
- this.position = position;
- }
-
- @Override
- public void reset() {
- double randomPosition = position + (positionRange * (Math.random() - 0.5));
- phase = (randomPosition * 0.5) + 0.5;
- if (phase < 0.0) {
- phase = 0.0;
- } else if (phase > MAX_PHASE) {
- phase = MAX_PHASE;
- }
- }
-
- public void setPositionRange(double positionRange) {
- this.positionRange = positionRange;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SawtoothOscillator.java b/src/com/jsyn/unitgen/SawtoothOscillator.java
deleted file mode 100644
index 1b3dead..0000000
--- a/src/com/jsyn/unitgen/SawtoothOscillator.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Simple sawtooth oscillator.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SawtoothOscillator extends UnitOscillator {
-
- @Override
- public void generate(int start, int limit) {
-
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for sine generation. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- outputs[i] = currentPhase * amplitudes[i];
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SawtoothOscillatorBL.java b/src/com/jsyn/unitgen/SawtoothOscillatorBL.java
deleted file mode 100644
index 8b58f6c..0000000
--- a/src/com/jsyn/unitgen/SawtoothOscillatorBL.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.MultiTable;
-
-/**
- * Sawtooth oscillator that uses multiple wave tables for band limiting. This requires more CPU than
- * a plain SawtoothOscillator but has less aliasing at high frequencies.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SawtoothOscillatorBL extends UnitOscillator {
- @Override
- public void generate(int start, int limit) {
- MultiTable multiTable = MultiTable.getInstance();
-
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[0]);
- double positivePhaseIncrement = Math.abs(phaseIncrement);
- // This is very expensive so we moved it outside the loop.
- // Try to optimize it with a table lookup.
- double flevel = multiTable.convertPhaseIncrementToLevel(positivePhaseIncrement);
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for sine generation. */
- phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- positivePhaseIncrement = Math.abs(phaseIncrement);
-
- double val = generateBL(multiTable, currentPhase, positivePhaseIncrement, flevel, i);
-
- outputs[i] = val * amplitudes[i];
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
- protected double generateBL(MultiTable multiTable, double currentPhase,
- double positivePhaseIncrement, double flevel, int i) {
- /* Calculate table level then use it for lookup. */
- return multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SawtoothOscillatorDPW.java b/src/com/jsyn/unitgen/SawtoothOscillatorDPW.java
deleted file mode 100644
index 27d0c5a..0000000
--- a/src/com/jsyn/unitgen/SawtoothOscillatorDPW.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Sawtooth DPW oscillator (a sawtooth with reduced aliasing).
- * Based on a paper by Antti Huovilainen and Vesa Valimaki:
- * http://www.scribd.com/doc/33863143/New-Approaches-to-Digital-Subtractive-Synthesis
- *
- * @author Phil Burk and Lisa Tolentino (C) 2009 Mobileer Inc
- */
-public class SawtoothOscillatorDPW extends UnitOscillator {
- // At a very low frequency, switch from DPW to raw sawtooth.
- private static final double VERY_LOW_FREQUENCY = 2.0 * 0.1 / 44100.0;
- private double z1;
- private double z2;
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate raw sawtooth phaser. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
-
- /* Square the raw sawtooth. */
- double squared = currentPhase * currentPhase;
- // Differentiate using a delayed value.
- double diffed = squared - z2;
- z2 = z1;
- z1 = squared;
-
- /* Calculate scaling based on phaseIncrement */
- double pinc = phaseIncrement;
- // Absolute value.
- if (pinc < 0.0) {
- pinc = 0.0 - pinc;
- }
-
- double dpw;
- // If the frequency is very low then just use the raw sawtooth.
- // This avoids divide by zero problems and scaling problems.
- if (pinc < VERY_LOW_FREQUENCY) {
- dpw = currentPhase;
- } else {
- dpw = diffed * 0.25 / pinc;
- }
-
- outputs[i] = amplitudes[i] * dpw;
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SchmidtTrigger.java b/src/com/jsyn/unitgen/SchmidtTrigger.java
deleted file mode 100644
index 64129ff..0000000
--- a/src/com/jsyn/unitgen/SchmidtTrigger.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * SchmidtTrigger unit.
- * <P>
- * Output logic level value with hysteresis. Transition high when input exceeds setLevel. Only go
- * low when input is below resetLevel. This can be used to reject low level noise on the input
- * signal. The default values for setLevel and resetLevel are both 0.0. Setting setLevel to 0.1 and
- * resetLevel to -0.1 will give some hysteresis. The outputPulse is a single sample wide pulse set
- * when the output transitions from low to high.
- *
- * <PRE>
- * if (output == 0.0)
- * output = (input &gt; setLevel) ? 1.0 : 0.0;
- * else if (output &gt; 0.0)
- * output = (input &lt;= resetLevel) ? 0.0 : 1.0;
- * else
- * output = previous_output;
- * </PRE>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see Compare
- */
-public class SchmidtTrigger extends UnitFilter {
- public UnitInputPort setLevel;
- public UnitInputPort resetLevel;
- public UnitOutputPort outputPulse;
-
- /* Define Unit Ports used by connect() and set(). */
- public SchmidtTrigger() {
- addPort(setLevel = new UnitInputPort("SetLevel"));
- addPort(resetLevel = new UnitInputPort("ResetLevel"));
- addPort(input = new UnitInputPort("Input"));
- addPort(outputPulse = new UnitOutputPort("OutputPulse"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inPtr = input.getValues();
- double[] pulsePtr = outputPulse.getValues();
- double[] outPtr = output.getValues();
- double[] setPtr = setLevel.getValues();
- double[] resetPtr = resetLevel.getValues();
-
- double outputValue = outPtr[0];
- boolean state = (outputValue > UnitGenerator.FALSE);
- for (int i = start; i < limit; i++) {
- pulsePtr[i] = UnitGenerator.FALSE;
- if (state) {
- if (inPtr[i] <= resetPtr[i]) {
- state = false;
- outputValue = UnitGenerator.FALSE;
- }
- } else {
- if (inPtr[i] > setPtr[i]) {
- state = true;
- outputValue = UnitGenerator.TRUE;
- pulsePtr[i] = UnitGenerator.TRUE; /* Single impulse. */
- }
- }
- outPtr[i] = outputValue;
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/Select.java b/src/com/jsyn/unitgen/Select.java
deleted file mode 100644
index 6d8792e..0000000
--- a/src/com/jsyn/unitgen/Select.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2004 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * SelectUnit unit. Select InputA or InputB based on value on Select port.
- *
- *<pre> <code>
- output = ( select &gt; 0.0 ) ? inputB : inputA;
-</code> </pre>
- *
- * @author (C) 2004-2009 Phil Burk, SoftSynth.com
- */
-
-public class Select extends UnitGenerator {
- public UnitInputPort inputA;
- public UnitInputPort inputB;
- public UnitInputPort select;
- public UnitOutputPort output;
-
- public Select() {
- addPort(inputA = new UnitInputPort("InputA"));
- addPort(inputB = new UnitInputPort("InputB"));
- addPort(select = new UnitInputPort("Select"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputAs = inputA.getValues();
- double[] inputBs = inputB.getValues();
- double[] selects = select.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = (selects[i] > UnitGenerator.FALSE) ? inputBs[i] : inputAs[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/SequentialDataReader.java b/src/com/jsyn/unitgen/SequentialDataReader.java
deleted file mode 100644
index 901767b..0000000
--- a/src/com/jsyn/unitgen/SequentialDataReader.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitDataQueuePort;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Base class for reading a sample or envelope.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class SequentialDataReader extends UnitGenerator {
- public UnitDataQueuePort dataQueue;
- public UnitInputPort amplitude;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public SequentialDataReader() {
- addPort(dataQueue = new UnitDataQueuePort("Data"));
- addPort(amplitude = new UnitInputPort("Amplitude", UnitOscillator.DEFAULT_AMPLITUDE));
- }
-}
diff --git a/src/com/jsyn/unitgen/SequentialDataWriter.java b/src/com/jsyn/unitgen/SequentialDataWriter.java
deleted file mode 100644
index cb3bb11..0000000
--- a/src/com/jsyn/unitgen/SequentialDataWriter.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitDataQueuePort;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Base class for writing to a sample.
- *
- * Note that you must call start() on subclasses of this unit because it does not have an output for pulling data.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class SequentialDataWriter extends UnitGenerator {
- public UnitDataQueuePort dataQueue;
- public UnitInputPort input;
-
- public SequentialDataWriter() {
- addPort(dataQueue = new UnitDataQueuePort("Data"));
- }
-
- /**
- * This unit won't do anything unless you start() it.
- */
- @Override
- public boolean isStartRequired() {
- return true;
- }
-}
diff --git a/src/com/jsyn/unitgen/SineOscillator.java b/src/com/jsyn/unitgen/SineOscillator.java
deleted file mode 100644
index 8c49ead..0000000
--- a/src/com/jsyn/unitgen/SineOscillator.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Sine oscillator generates a frequency controlled sine wave. It is implemented using a fast Taylor
- * expansion.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SineOscillator extends UnitOscillator {
- public SineOscillator() {
- }
-
- public SineOscillator(double freq) {
- frequency.set(freq);
- }
-
- public SineOscillator(double freq, double amp) {
- frequency.set(freq);
- amplitude.set(amp);
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for sine generation. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- if (true) {
- double value = fastSin(currentPhase);
- outputs[i] = value * amplitudes[i];
- } else {
- // Slower but more accurate implementation.
- outputs[i] = Math.sin(currentPhase * Math.PI) * amplitudes[i];
- }
- }
-
- phase.setValue(currentPhase);
- }
-
- /**
- * Calculate sine using Taylor expansion. Do not use values outside the range.
- *
- * @param currentPhase in the range of -1.0 to +1.0 for one cycle
- */
- public static double fastSin(double currentPhase) {
- // Factorial constants so code is easier to read.
- final double IF3 = 1.0 / (2 * 3);
- final double IF5 = IF3 / (4 * 5);
- final double IF7 = IF5 / (6 * 7);
- final double IF9 = IF7 / (8 * 9);
- final double IF11 = IF9 / (10 * 11);
-
- /* Wrap phase back into region where results are more accurate. */
- double yp = (currentPhase > 0.5) ? 1.0 - currentPhase : ((currentPhase < (-0.5)) ? (-1.0)
- - currentPhase : currentPhase);
-
- double x = yp * Math.PI;
- double x2 = (x * x);
- /* Taylor expansion out to x**11/11! factored into multiply-adds */
- double fastsin = x
- * (x2 * (x2 * (x2 * (x2 * ((x2 * (-IF11)) + IF9) - IF7) + IF5) - IF3) + 1);
- return fastsin;
- }
-}
diff --git a/src/com/jsyn/unitgen/SineOscillatorPhaseModulated.java b/src/com/jsyn/unitgen/SineOscillatorPhaseModulated.java
deleted file mode 100644
index 7631dff..0000000
--- a/src/com/jsyn/unitgen/SineOscillatorPhaseModulated.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Sine oscillator with a phase modulation input. Phase modulation is similar to frequency
- * modulation but is easier to use in some ways.
- *
- * <pre>
- * output = sin(PI * (phase + modulation))
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SineOscillatorPhaseModulated extends SineOscillator {
- public UnitInputPort modulation;
-
- /* Define Unit Ports used by connect() and set(). */
- public SineOscillatorPhaseModulated() {
- super();
- addPort(modulation = new UnitInputPort("Modulation"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
- double[] modulations = modulation.getValues();
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phaser to provide phase for sine generation. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
- double modulatedPhase = currentPhase + modulations[i];
- double value;
- if (false) {
- // TODO Compare benchmarks.
- while (modulatedPhase >= 1.0) {
- modulatedPhase -= 2.0;
- }
- while (modulatedPhase < -1.0) {
- modulatedPhase += 2.0;
- }
- value = fastSin(modulatedPhase);
- } else {
- value = Math.sin(modulatedPhase * Math.PI);
- }
- outputs[i] = value * amplitudes[i];
- // System.out.format("Sine: freq = %10.4f , amp = %8.5f, out = %8.5f, phase = %8.5f, frame = %8d\n",
- // frequencies[i], amplitudes[i],outputs[i],currentPhase,frame++ );
- }
-
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SpectralFFT.java b/src/com/jsyn/unitgen/SpectralFFT.java
deleted file mode 100644
index f3e881a..0000000
--- a/src/com/jsyn/unitgen/SpectralFFT.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import java.util.Arrays;
-
-import com.jsyn.data.SpectralWindow;
-import com.jsyn.data.Spectrum;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitSpectralOutputPort;
-import com.softsynth.math.FourierMath;
-
-/**
- * Periodically transform the input signal using an FFT. Output complete spectra.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @version 016
- * @see SpectralIFFT
- * @see Spectrum
- * @see SpectralFilter
- */
-public class SpectralFFT extends UnitGenerator {
- public UnitInputPort input;
- /**
- * Provides complete complex spectra when the FFT completes.
- */
- public UnitSpectralOutputPort output;
- private double[] buffer;
- private int cursor;
- private SpectralWindow window = RectangularWindow.getInstance();
- private int sizeLog2;
- private int offset;
- private boolean running;
-
- /* Define Unit Ports used by connect() and set(). */
- public SpectralFFT() {
- this(Spectrum.DEFAULT_SIZE_LOG_2);
- }
-
- /**
- * @param sizeLog2 for example, pass 10 to get a 1024 bin FFT
- */
- public SpectralFFT(int sizeLog2) {
- addPort(input = new UnitInputPort("Input"));
- addPort(output = new UnitSpectralOutputPort("Output", 1 << sizeLog2));
- setSizeLog2(sizeLog2);
- }
-
- /**
- * Please do not change the size of the FFT while JSyn is running.
- *
- * @param sizeLog2 for example, pass 9 to get a 512 bin FFT
- */
- public void setSizeLog2(int sizeLog2) {
- this.sizeLog2 = sizeLog2;
- output.setSize(1 << sizeLog2);
- buffer = output.getSpectrum().getReal();
- cursor = 0;
- }
-
- public int getSizeLog2() {
- return sizeLog2;
- }
-
- @Override
- public void generate(int start, int limit) {
- if (!running) {
- int mask = (1 << sizeLog2) - 1;
- if (((getSynthesisEngine().getFrameCount() - offset) & mask) == 0) {
- running = true;
- cursor = 0;
- }
- }
- // Don't use "else" because "running" may have changed in above block.
- if (running) {
- double[] inputs = input.getValues();
- for (int i = start; i < limit; i++) {
- buffer[cursor] = inputs[i] * window.get(cursor);
- ++cursor;
- // When it is full, do the FFT.
- if (cursor == buffer.length) {
- Spectrum spectrum = output.getSpectrum();
- Arrays.fill(spectrum.getImaginary(), 0.0);
- FourierMath.fft(buffer.length, spectrum.getReal(), spectrum.getImaginary());
- output.advance();
- cursor = 0;
- }
- }
- }
- }
-
- public SpectralWindow getWindow() {
- return window;
- }
-
- /**
- * Multiply input data by this window before doing the FFT. The default is a RectangularWindow.
- */
- public void setWindow(SpectralWindow window) {
- this.window = window;
- }
-
- /**
- * The FFT will be performed on a frame that is a multiple of the size plus this offset.
- *
- * @param offset
- */
- public void setOffset(int offset) {
- this.offset = offset;
- }
-
- public int getOffset() {
- return offset;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SpectralFilter.java b/src/com/jsyn/unitgen/SpectralFilter.java
deleted file mode 100644
index 758c8e7..0000000
--- a/src/com/jsyn/unitgen/SpectralFilter.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.SpectralWindow;
-import com.jsyn.data.SpectralWindowFactory;
-import com.jsyn.data.Spectrum;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.ports.UnitSpectralInputPort;
-import com.jsyn.ports.UnitSpectralOutputPort;
-
-/**
- * Process a signal using multiple overlapping FFT and IFFT pairs. For passthrough, you can connect
- * the spectral outputs to the spectral inputs. Or you can connect one or more SpectralProcessors
- * between them.
- *
- * <pre>
- * for (int i = 0; i &lt; numFFTs; i++) {
- * filter.getSpectralOutput(i).connect(processors[i].input);
- * processors[i].output.connect(filter.getSpectralInput(i));
- * }
- * </pre>
- *
- * See the example program "HearSpectralFilter.java". Note that this spectral API is experimental
- * and may change at any time.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- * @see SpectralProcessor
- */
-public class SpectralFilter extends Circuit implements UnitSink, UnitSource {
- public UnitInputPort input;
- public UnitOutputPort output;
-
- private SpectralFFT[] ffts;
- private SpectralIFFT[] iffts;
- private PassThrough inlet; // fan out to FFTs
- private PassThrough sum; // mix output of IFFTs
-
- /**
- * Create a default sized filter with 2 FFT/IFFT pairs and a sizeLog2 of
- * Spectrum.DEFAULT_SIZE_LOG_2.
- */
- public SpectralFilter() {
- this(2, Spectrum.DEFAULT_SIZE_LOG_2);
- }
-
- /**
- * @param numFFTs number of FFT/IFFT pairs for the overlap and add
- * @param sizeLog2 for example, use 10 to get a 1024 bin FFT, 12 for 4096
- */
- public SpectralFilter(int numFFTs, int sizeLog2) {
- add(inlet = new PassThrough());
- add(sum = new PassThrough());
- ffts = new SpectralFFT[numFFTs];
- iffts = new SpectralIFFT[numFFTs];
- int offset = (1 << sizeLog2) / numFFTs;
- for (int i = 0; i < numFFTs; i++) {
- add(ffts[i] = new SpectralFFT(sizeLog2));
- inlet.output.connect(ffts[i].input);
- ffts[i].setOffset(i * offset);
-
- add(iffts[i] = new SpectralIFFT());
- iffts[i].output.connect(sum.input);
- }
- setWindow(SpectralWindowFactory.getHammingWindow(sizeLog2));
-
- addPort(input = inlet.input);
- addPort(output = sum.output);
- }
-
- public SpectralWindow getWindow() {
- return ffts[0].getWindow();
- }
-
- /**
- * Specify one window to be used for all FFTs and IFFTs. The window should be the same size as
- * the FFTs.
- *
- * @param window default is HammingWindow
- * @see SpectralWindowFactory
- */
- public void setWindow(SpectralWindow window) {
- // Use the same window everywhere.
- for (int i = 0; i < ffts.length; i++) {
- ffts[i].setWindow(window); // TODO review, both sides or just one
- iffts[i].setWindow(window);
- }
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-
- /**
- * @param i
- * @return the output of the indexed FFT
- */
- public UnitSpectralOutputPort getSpectralOutput(int i) {
- return ffts[i].output;
- }
-
- /**
- * @param i
- * @return the input of the indexed IFFT
- */
- public UnitSpectralInputPort getSpectralInput(int i) {
- return iffts[i].input;
- }
-}
diff --git a/src/com/jsyn/unitgen/SpectralIFFT.java b/src/com/jsyn/unitgen/SpectralIFFT.java
deleted file mode 100644
index c040e52..0000000
--- a/src/com/jsyn/unitgen/SpectralIFFT.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2013 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.SpectralWindow;
-import com.jsyn.data.Spectrum;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.ports.UnitSpectralInputPort;
-import com.softsynth.math.FourierMath;
-
-/**
- * Periodically transform the input signal using an Inverse FFT.
- *
- * @author Phil Burk (C) 2013 Mobileer Inc
- * @version 016
- * @see SpectralFFT
- */
-public class SpectralIFFT extends UnitGenerator {
- public UnitSpectralInputPort input;
- public UnitOutputPort output;
- private Spectrum localSpectrum;
- private double[] buffer;
- private int cursor;
- private SpectralWindow window = RectangularWindow.getInstance();
-
- /* Define Unit Ports used by connect() and set(). */
- public SpectralIFFT() {
- addPort(output = new UnitOutputPort());
- addPort(input = new UnitSpectralInputPort("Input"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] outputs = output.getValues();
-
- if (buffer == null) {
- if (input.isAvailable()) {
- Spectrum spectrum = input.getSpectrum();
- int size = spectrum.size();
- localSpectrum = new Spectrum(size);
- buffer = localSpectrum.getReal();
- cursor = 0;
- } else {
- for (int i = start; i < limit; i++) {
- outputs[i] = 0.0;
- }
- }
- }
-
- if (buffer != null) {
- for (int i = start; i < limit; i++) {
- if (cursor == 0) {
- Spectrum spectrum = input.getSpectrum();
- spectrum.copyTo(localSpectrum);
- FourierMath.ifft(buffer.length, localSpectrum.getReal(),
- localSpectrum.getImaginary());
- }
-
- outputs[i] = buffer[cursor] * window.get(cursor);
- cursor += 1;
- if (cursor == buffer.length) {
- cursor = 0;
- }
- }
- }
- }
-
- public SpectralWindow getWindow() {
- return window;
- }
-
- /**
- * Multiply output data by this window after doing the FFT. The default is a RectangularWindow.
- */
- public void setWindow(SpectralWindow window) {
- this.window = window;
- }
-}
diff --git a/src/com/jsyn/unitgen/SpectralProcessor.java b/src/com/jsyn/unitgen/SpectralProcessor.java
deleted file mode 100644
index de96877..0000000
--- a/src/com/jsyn/unitgen/SpectralProcessor.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.Spectrum;
-import com.jsyn.ports.UnitSpectralInputPort;
-import com.jsyn.ports.UnitSpectralOutputPort;
-
-/**
- * This is a base class for implementing your own spectral processing units. You need to implement
- * the processSpectrum() method.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- * @see Spectrum
- */
-public abstract class SpectralProcessor extends UnitGenerator {
- public UnitSpectralInputPort input;
- public UnitSpectralOutputPort output;
- private int counter;
-
- /* Define Unit Ports used by connect() and set(). */
- public SpectralProcessor() {
- addPort(output = new UnitSpectralOutputPort());
- addPort(input = new UnitSpectralInputPort());
- }
-
- /* Define Unit Ports used by connect() and set(). */
- public SpectralProcessor(int size) {
- addPort(output = new UnitSpectralOutputPort(size));
- addPort(input = new UnitSpectralInputPort());
- }
-
- @Override
- public void generate(int start, int limit) {
- for (int i = start; i < limit; i++) {
- if (counter == 0) {
- if (input.isAvailable()) {
- Spectrum inputSpectrum = input.getSpectrum();
- Spectrum outputSpectrum = output.getSpectrum();
- processSpectrum(inputSpectrum, outputSpectrum);
-
- output.advance();
- counter = inputSpectrum.size() - 1;
- }
- } else {
- counter--;
- }
- }
- }
-
- /**
- * Define this method to implement your own processor.
- *
- * @param inputSpectrum
- * @param outputSpectrum
- */
- public abstract void processSpectrum(Spectrum inputSpectrum, Spectrum outputSpectrum);
-
-}
diff --git a/src/com/jsyn/unitgen/SquareOscillator.java b/src/com/jsyn/unitgen/SquareOscillator.java
deleted file mode 100644
index aaca2d0..0000000
--- a/src/com/jsyn/unitgen/SquareOscillator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Simple square wave oscillator.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SquareOscillator extends UnitOscillator {
-
- @Override
- public void generate(int start, int limit) {
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for square generation. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
-
- double ampl = amplitudes[i];
- // Either full negative or positive amplitude.
- outputs[i] = (currentPhase < 0.0) ? -ampl : ampl;
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/SquareOscillatorBL.java b/src/com/jsyn/unitgen/SquareOscillatorBL.java
deleted file mode 100644
index cb9e141..0000000
--- a/src/com/jsyn/unitgen/SquareOscillatorBL.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.engine.MultiTable;
-
-/**
- * Band-limited square wave oscillator. This requires more CPU than a SquareOscillator but is less
- * noisy at high frequencies.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class SquareOscillatorBL extends SawtoothOscillatorBL {
- @Override
- protected double generateBL(MultiTable multiTable, double currentPhase,
- double positivePhaseIncrement, double flevel, int i) {
- double val1 = multiTable.calculateSawtooth(currentPhase, positivePhaseIncrement, flevel);
-
- /* Generate second sawtooth so we can add them together. */
- double phase2 = currentPhase + 1.0; /* 180 degrees out of phase. */
- if (phase2 >= 1.0) {
- phase2 -= 2.0;
- }
- double val2 = multiTable.calculateSawtooth(phase2, positivePhaseIncrement, flevel);
-
- /*
- * Need to adjust amplitude based on positive phaseInc. little less than half at
- * Nyquist/2.0!
- */
- final double STARTAMP = 0.92; /* Derived by viewing waveforms with TJ_SEEOSC */
- double scale = STARTAMP - positivePhaseIncrement;
- return scale * (val1 - val2);
- }
-}
diff --git a/src/com/jsyn/unitgen/StereoStreamWriter.java b/src/com/jsyn/unitgen/StereoStreamWriter.java
deleted file mode 100644
index b387836..0000000
--- a/src/com/jsyn/unitgen/StereoStreamWriter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import java.io.IOException;
-
-import com.jsyn.io.AudioOutputStream;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Write two samples per audio frame to an AudioOutputStream as interleaved samples.
- *
- * Note that you must call start() on this unit because it does not have an output for pulling data.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class StereoStreamWriter extends UnitStreamWriter {
- public StereoStreamWriter() {
- addPort(input = new UnitInputPort(2, "Input"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] leftInputs = input.getValues(0);
- double[] rightInputs = input.getValues(1);
- AudioOutputStream output = outputStream;
- if (output != null) {
- try {
- for (int i = start; i < limit; i++) {
- output.write(leftInputs[i]);
- output.write(rightInputs[i]);
- }
- } catch (IOException e) {
- e.printStackTrace();
- output = null;
- }
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/StochasticGrainScheduler.java b/src/com/jsyn/unitgen/StochasticGrainScheduler.java
deleted file mode 100644
index 1f79877..0000000
--- a/src/com/jsyn/unitgen/StochasticGrainScheduler.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.util.PseudoRandom;
-
-/**
- * Use a random function to schedule grains.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- */
-public class StochasticGrainScheduler implements GrainScheduler {
- PseudoRandom pseudoRandom = new PseudoRandom();
-
- @Override
- public double nextDuration(double duration) {
- return duration;
- }
-
- @Override
- public double nextGap(double duration, double density) {
- if (density < 0.00000001) {
- density = 0.00000001;
- }
- double gapRange = duration * (1.0 - density) / density;
- return pseudoRandom.random() * gapRange;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/Subtract.java b/src/com/jsyn/unitgen/Subtract.java
deleted file mode 100644
index d9ca035..0000000
--- a/src/com/jsyn/unitgen/Subtract.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * This unit performs a signed subtraction on its two inputs.
- *
- * <pre>
- * output = inputA - inputB
- * </pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @version 016
- * @see MultiplyAdd
- * @see Subtract
- */
-public class Subtract extends UnitBinaryOperator {
- @Override
- public void generate(int start, int limit) {
- double[] aValues = inputA.getValues();
- double[] bValues = inputB.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = aValues[i] - bValues[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/TriangleOscillator.java b/src/com/jsyn/unitgen/TriangleOscillator.java
deleted file mode 100644
index ada2d6e..0000000
--- a/src/com/jsyn/unitgen/TriangleOscillator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Simple triangle wave oscillator.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class TriangleOscillator extends UnitOscillator {
- int frame;
-
- public TriangleOscillator() {
- super();
- phase.setValue(-0.5);
- }
-
- @Override
- public void generate(int start, int limit) {
-
- double[] frequencies = frequency.getValues();
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- // Variables have a single value.
- double currentPhase = phase.getValue();
-
- for (int i = start; i < limit; i++) {
- /* Generate sawtooth phasor to provide phase for triangle generation. */
- double phaseIncrement = convertFrequencyToPhaseIncrement(frequencies[i]);
- currentPhase = incrementWrapPhase(currentPhase, phaseIncrement);
-
- /* Map phase to triangle waveform. */
- /* 0 - 0.999 => 0.5-p => +0.5 - -0.5 */
- /* -1.0 - 0.0 => 0.5+p => -0.5 - +0.5 */
- double triangle = (currentPhase >= 0.0) ? (0.5 - currentPhase) : (0.5 + currentPhase);
-
- outputs[i] = triangle * 2.0 * amplitudes[i];
- }
-
- // Value needs to be saved for next time.
- phase.setValue(currentPhase);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/TunableFilter.java b/src/com/jsyn/unitgen/TunableFilter.java
deleted file mode 100644
index d2c9f66..0000000
--- a/src/com/jsyn/unitgen/TunableFilter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Aug 26, 2009
- * com.jsyn.engine.units.TunableFilter.java
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * A UnitFilter with a frequency port.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc Translated from 'C' to Java by Lisa
- * Tolentino.
- */
-public abstract class TunableFilter extends UnitFilter {
-
- static final double DEFAULT_FREQUENCY = 400;
- public UnitInputPort frequency;
-
- public TunableFilter() {
- addPort(frequency = new UnitInputPort("Frequency"));
- frequency.setup(40.0, DEFAULT_FREQUENCY, 6000.0);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/TwoInDualOut.java b/src/com/jsyn/unitgen/TwoInDualOut.java
deleted file mode 100644
index a8fea48..0000000
--- a/src/com/jsyn/unitgen/TwoInDualOut.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2004 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * This unit combines two discrete inputs into a dual (stereo) output.
- *
- * <pre>
- * output[0] = inputA
- * output[1] = inputB
- * </pre>
- *
- * @author (C) 2004-2009 Phil Burk, SoftSynth.com
- */
-
-public class TwoInDualOut extends UnitGenerator {
- public UnitInputPort inputA;
- public UnitInputPort inputB;
- public UnitOutputPort output;
-
- public TwoInDualOut() {
- addPort(inputA = new UnitInputPort("InputA"));
- addPort(inputB = new UnitInputPort("InputB"));
- addPort(output = new UnitOutputPort(2, "OutputB"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputAs = inputA.getValues();
- double[] inputBs = inputB.getValues();
- double[] output0s = output.getValues(0);
- double[] output1s = output.getValues(1);
-
- for (int i = start; i < limit; i++) {
- output0s[i] = inputAs[i];
- output1s[i] = inputBs[i];
- }
- }
-}
diff --git a/src/com/jsyn/unitgen/UnitBinaryOperator.java b/src/com/jsyn/unitgen/UnitBinaryOperator.java
deleted file mode 100644
index c5675ff..0000000
--- a/src/com/jsyn/unitgen/UnitBinaryOperator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2010 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Base class for binary arithmetic operators like Add and Compare.
- *
- * @author Phil Burk (C) 2010 Mobileer Inc
- */
-public abstract class UnitBinaryOperator extends UnitGenerator {
- public UnitInputPort inputA;
- public UnitInputPort inputB;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public UnitBinaryOperator() {
- addPort(inputA = new UnitInputPort("InputA"));
- addPort(inputB = new UnitInputPort("InputB"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public abstract void generate(int start, int limit);
-}
diff --git a/src/com/jsyn/unitgen/UnitFilter.java b/src/com/jsyn/unitgen/UnitFilter.java
deleted file mode 100644
index 49976ba..0000000
--- a/src/com/jsyn/unitgen/UnitFilter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Base class for all filters.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class UnitFilter extends UnitGenerator implements UnitSink, UnitSource {
- public UnitInputPort input;
- public UnitOutputPort output;
-
- /* Define Unit Ports used by connect() and set(). */
- public UnitFilter() {
- addPort(input = new UnitInputPort("Input"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
-}
diff --git a/src/com/jsyn/unitgen/UnitGate.java b/src/com/jsyn/unitgen/UnitGate.java
deleted file mode 100644
index 59144c2..0000000
--- a/src/com/jsyn/unitgen/UnitGate.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2012 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitGatePort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Base class for other envelopes.
- *
- * @author Phil Burk (C) 2012 Mobileer Inc
- */
-public abstract class UnitGate extends UnitGenerator implements UnitSource {
- /**
- * Input that triggers the envelope. Use amplitude port if you want to connect a signal to be
- * modulated by the envelope.
- */
- public UnitGatePort input;
- public UnitOutputPort output;
-
- public UnitGate() {
- addPort(input = new UnitGatePort("Input"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
- /**
- * Specify a unit to be disabled when the envelope finishes.
- *
- * @param unit
- */
- public void setupAutoDisable(UnitGenerator unit) {
- input.setupAutoDisable(unit);
- }
-
-}
diff --git a/src/com/jsyn/unitgen/UnitGenerator.java b/src/com/jsyn/unitgen/UnitGenerator.java
deleted file mode 100644
index 1e87ae6..0000000
--- a/src/com/jsyn/unitgen/UnitGenerator.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import java.io.PrintStream;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.logging.Logger;
-
-import com.jsyn.Synthesizer;
-import com.jsyn.engine.SynthesisEngine;
-import com.jsyn.ports.ConnectableInput;
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.ports.UnitPort;
-import com.softsynth.shared.time.TimeStamp;
-
-/**
- * Base class for all unit generators.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class UnitGenerator {
- protected static final double VERY_SMALL_FLOAT = 1.0e-26;
-
- // Some common port names.
- public static final String PORT_NAME_INPUT = "Input";
- public static final String PORT_NAME_OUTPUT = "Output";
- public static final String PORT_NAME_PHASE = "Phase";
- public static final String PORT_NAME_FREQUENCY = "Frequency";
- public static final String PORT_NAME_FREQUENCY_SCALER = "FreqScaler";
- public static final String PORT_NAME_AMPLITUDE = "Amplitude";
- public static final String PORT_NAME_PAN = "Pan";
- public static final String PORT_NAME_TIME = "Time";
- public static final String PORT_NAME_CUTOFF = "Cutoff";
- public static final String PORT_NAME_PRESSURE = "Pressure";
- public static final String PORT_NAME_TIMBRE = "Timbre";
-
- public static final double FALSE = 0.0;
- public static final double TRUE = 1.0;
- protected SynthesisEngine synthesisEngine;
- private final LinkedHashMap<String, UnitPort> ports = new LinkedHashMap<String, UnitPort>();
- private Circuit circuit;
- private long lastFrameCount;
- private boolean enabled = true;
- private static int nextId;
- private final int id = nextId++;
-
- static Logger logger = Logger.getLogger(UnitGenerator.class.getName());
-
- public int getId() {
- return id;
- }
-
- public int getFrameRate() {
- // return frameRate;
- return synthesisEngine.getFrameRate();
- }
-
- public double getFramePeriod() {
- // return framePeriod; // TODO - Why does OldJSynTestSuite fail if I use this!
- return synthesisEngine.getFramePeriod();
- }
-
- public void addPort(UnitPort port) {
- port.setUnitGenerator(this);
- // Store in a hash table by name.
- ports.put(port.getName().toLowerCase(), port);
- }
-
- public void addPort(UnitPort port, String name) {
- port.setName(name);
- addPort(port);
- }
-
- /**
- * Case-insensitive search for a port by name.
- * @param portName
- * @return matching port or null
- */
- public UnitPort getPortByName(String portName) {
- return ports.get(portName.toLowerCase());
- }
-
- public Collection<UnitPort> getPorts() {
- return ports.values();
- }
-
- /**
- * Perform essential synthesis function.
- *
- * @param start offset into port buffers
- * @param limit limit offset into port buffers for loop
- */
- public abstract void generate(int start, int limit);
-
- /**
- * Generate a full block.
- */
- public void generate() {
- generate(0, Synthesizer.FRAMES_PER_BLOCK);
- }
-
- /**
- * @return the synthesisEngine
- */
- public SynthesisEngine getSynthesisEngine() {
- return synthesisEngine;
- }
-
- /**
- * @return the Synthesizer
- */
- public Synthesizer getSynthesizer() {
- return synthesisEngine;
- }
-
- /**
- * @param synthesisEngine the synthesisEngine to set
- */
- public void setSynthesisEngine(SynthesisEngine synthesisEngine) {
- if ((this.synthesisEngine != null) && (this.synthesisEngine != synthesisEngine)) {
- throw new RuntimeException("Unit synthesisEngine already set.");
- }
- this.synthesisEngine = synthesisEngine;
- }
-
- public UnitGenerator getTopUnit() {
- UnitGenerator unit = this;
- // Climb to top of circuit hierarchy.
- while (unit.circuit != null) {
- unit = unit.circuit;
- }
- logger.fine("getTopUnit " + this + " => " + unit);
- return unit;
- }
-
- protected void autoStop() {
- synthesisEngine.autoStopUnit(getTopUnit());
- }
-
- /** Calculate signal based on halflife of an exponential decay. */
- public double convertHalfLifeToMultiplier(double halfLife) {
- if (halfLife < (2.0 * getFramePeriod())) {
- return 1.0;
- } else {
- // Oddly enough, this code is valid for both PeakFollower and AsymptoticRamp.
- return 1.0 - Math.pow(0.5, 1.0 / (halfLife * getSynthesisEngine().getFrameRate()));
- }
- }
-
- protected double incrementWrapPhase(double currentPhase, double phaseIncrement) {
- currentPhase += phaseIncrement;
-
- if (currentPhase >= 1.0) {
- currentPhase -= 2.0;
- } else if (currentPhase < -1.0) {
- currentPhase += 2.0;
- }
- return currentPhase;
- }
-
- /** Calculate rate based on phase going from 0.0 to 1.0 in time. */
- protected double convertTimeToRate(double time) {
- double period2X = synthesisEngine.getInverseNyquist();
- if (time < period2X) {
- return 1.0;
- } else {
- return getFramePeriod() / time;
- }
- }
-
- /** Flatten output ports so we don't output a changing signal when stopped. */
- public void flattenOutputs() {
- for (UnitPort port : ports.values()) {
- if (port instanceof UnitOutputPort) {
- ((UnitOutputPort) port).flatten();
- }
- }
- }
-
- public void setCircuit(Circuit circuit) {
- if ((this.circuit != null) && (circuit != null)) {
- throw new RuntimeException("Unit is already in a circuit.");
- }
- // logger.info( "setCircuit in unit " + this + " with circuit " + circuit );
- this.circuit = circuit;
- }
-
- public Circuit getCircuit() {
- return circuit;
- }
-
- public void pullData(long frameCount, int start, int limit) {
- // Don't generate twice in case the paths merge.
- if (enabled && (frameCount > lastFrameCount)) {
- // Do this first to block recursion when there is a feedback loop.
- lastFrameCount = frameCount;
- // Then pull from all the units that are upstream.
- for (UnitPort port : ports.values()) {
- if (port instanceof ConnectableInput) {
- ((ConnectableInput) port).pullData(frameCount, start, limit);
- }
- }
- // Finally generate using outputs of the upstream units.
- generate(start, limit);
- }
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- /**
- * If enabled, then a unit will execute if its output is connected to another unit that is
- * executed. If not enabled then it will not execute and will not pull data from units that are
- * connected to its inputs. Disabling a unit at the output of a tree of units can be used to
- * turn off the entire tree, thus saving CPU cycles.
- *
- * @param enabled
- * @see UnitGate#setupAutoDisable(UnitGenerator)
- * @see start
- */
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- if (!enabled) {
- flattenOutputs();
- }
- }
-
- /**
- * Some units, for example LineOut and FixedRateMonoWriter, will only work if
- * started explicitly. Other units will run when downstream units are started.
- *
- * @return true if you should call start() for this unit
- */
- public boolean isStartRequired() {
- return false;
- }
-
- /**
- * Start executing this unit directly by adding it to a "run list" of units in the synthesis
- * engine. This method is normally only called for the final unit in a chain, for example a
- * LineOut. When that final unit executes it will "pull" data from any units connected to its
- * inputs. Those units will then pull data their inputs until the entire chain is executed. If
- * units are connected in a circle then this will be detected and the infinite recursion will be
- * blocked.
- *
- * @see setEnabled
- */
- public void start() {
- if (getSynthesisEngine() == null) {
- throw new RuntimeException("This " + this.getClass().getName()
- + " was not add()ed to a Synthesizer.");
- }
- getSynthesisEngine().startUnit(this);
- }
-
- /**
- * Start a unit at the specified time.
- *
- * @param time
- * @see start
- */
- public void start(double time) {
- start(new TimeStamp(time));
- }
-
- /**
- * Start a unit at the specified time.
- *
- * @param timeStamp
- * @see start
- */
- public void start(TimeStamp timeStamp) {
- if (getSynthesisEngine() == null) {
- throw new RuntimeException("This " + this.getClass().getName()
- + " was not add()ed to a Synthesizer.");
- }
- getSynthesisEngine().startUnit(this, timeStamp);
- }
-
- /**
- * Stop a unit at the specified time.
- *
- * @param time
- * @see start
- */
- public void stop(double time) {
- stop(new TimeStamp(time));
- }
-
- public void stop() {
- getSynthesisEngine().stopUnit(this);
- }
-
- public void stop(TimeStamp timeStamp) {
- getSynthesisEngine().stopUnit(this, timeStamp);
- }
-
- /**
- * @deprecated ignored, frameRate comes from the SynthesisEngine
- * @param rate
- */
- @Deprecated
- public void setFrameRate(int rate) {
- }
-
- /** Needed by UnitSink */
- public UnitGenerator getUnitGenerator() {
- return this;
- }
-
- /** Needed by UnitVoice */
- public void setPort(String portName, double value, TimeStamp timeStamp) {
- UnitInputPort port = (UnitInputPort) getPortByName(portName);
- // System.out.println("setPort " + port );
- if (port == null) {
- logger.warning("port was null for name " + portName + ", " + this.getClass().getName());
- } else {
- port.set(value, timeStamp);
- }
- }
-
- public void printConnections() {
- printConnections(System.out);
- }
-
- public void printConnections(PrintStream out) {
- printConnections(out, 0);
- }
-
- public void printConnections(PrintStream out, int level) {
- for (UnitPort port : getPorts()) {
- if (port instanceof UnitInputPort) {
- ((UnitInputPort) port).printConnections(out, level);
- }
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/UnitOscillator.java b/src/com/jsyn/unitgen/UnitOscillator.java
deleted file mode 100644
index 5d4c6fa..0000000
--- a/src/com/jsyn/unitgen/UnitOscillator.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.ports.UnitVariablePort;
-import com.softsynth.shared.time.TimeStamp;
-
-/**
- * Base class for all oscillators.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class UnitOscillator extends UnitGenerator implements UnitVoice {
- /** Frequency in Hertz. */
- public UnitInputPort frequency;
- public UnitInputPort amplitude;
- public UnitVariablePort phase;
- public UnitOutputPort output;
-
- public static final double DEFAULT_FREQUENCY = 440.0;
- public static final double DEFAULT_AMPLITUDE = 1.0;
-
- /* Define Unit Ports used by connect() and set(). */
- public UnitOscillator() {
- addPort(frequency = new UnitInputPort(PORT_NAME_FREQUENCY));
- frequency.setup(40.0, DEFAULT_FREQUENCY, 8000.0);
- addPort(amplitude = new UnitInputPort(PORT_NAME_AMPLITUDE, DEFAULT_AMPLITUDE));
- addPort(phase = new UnitVariablePort(PORT_NAME_PHASE));
- addPort(output = new UnitOutputPort(PORT_NAME_OUTPUT));
- }
-
- /**
- * Convert a frequency in Hertz to a phaseIncrement in the range -1.0 to +1.0
- */
- public double convertFrequencyToPhaseIncrement(double freq) {
- double phaseIncrement;
- try {
- phaseIncrement = freq * synthesisEngine.getInverseNyquist();
- } catch (NullPointerException e) {
- throw new NullPointerException(
- "Null Synth! You probably forgot to add this unit to the Synthesizer!");
- }
- // Clip to range.
- phaseIncrement = (phaseIncrement > 1.0) ? 1.0 : ((phaseIncrement < -1.0) ? -1.0
- : phaseIncrement);
- return phaseIncrement;
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-
- public void noteOn(double freq, double ampl) {
- frequency.set(freq);
- amplitude.set(ampl);
- }
-
- public void noteOff() {
- amplitude.set(0.0);
- }
-
- @Override
- public void noteOff(TimeStamp timeStamp) {
- amplitude.set(0.0, timeStamp);
- }
-
- @Override
- public void noteOn(double freq, double ampl, TimeStamp timeStamp) {
- frequency.set(freq, timeStamp);
- amplitude.set(ampl, timeStamp);
- }
-
- @Override
- public void usePreset(int presetIndex) {
- }
-}
diff --git a/src/com/jsyn/unitgen/UnitSink.java b/src/com/jsyn/unitgen/UnitSink.java
deleted file mode 100644
index 3e0f55e..0000000
--- a/src/com/jsyn/unitgen/UnitSink.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.softsynth.shared.time.TimeStamp;
-
-/**
- * Interface for unit generators that have an input.
- *
- * @author Phil Burk, (C) 2009 Mobileer Inc
- */
-public interface UnitSink {
- public UnitInputPort getInput();
-
- /**
- * Begin execution of this unit by the Synthesizer. The input will pull data from any output
- * port that is connected from it.
- */
- public void start();
-
- public void start(TimeStamp timeStamp);
-
- public void stop();
-
- public void stop(TimeStamp timeStamp);
-
- public UnitGenerator getUnitGenerator();
-}
diff --git a/src/com/jsyn/unitgen/UnitSource.java b/src/com/jsyn/unitgen/UnitSource.java
deleted file mode 100644
index 5ee8134..0000000
--- a/src/com/jsyn/unitgen/UnitSource.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Interface for things that have that have an output and an associated UnitGenerator.
- *
- * @author Phil Burk, (C) 2009 Mobileer Inc
- */
-public interface UnitSource {
- public UnitOutputPort getOutput();
-
- public UnitGenerator getUnitGenerator();
-}
diff --git a/src/com/jsyn/unitgen/UnitStreamWriter.java b/src/com/jsyn/unitgen/UnitStreamWriter.java
deleted file mode 100644
index 0c5bd8b..0000000
--- a/src/com/jsyn/unitgen/UnitStreamWriter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.io.AudioOutputStream;
-import com.jsyn.ports.UnitInputPort;
-
-/**
- * Base class for writing to an AudioOutputStream.
- *
- * Note that you must call start() on subclasses of this unit because it does not have an output for pulling data.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public abstract class UnitStreamWriter extends UnitGenerator implements UnitSink {
- protected AudioOutputStream outputStream;
- public UnitInputPort input;
-
- public AudioOutputStream getOutputStream() {
- return outputStream;
- }
-
- public void setOutputStream(AudioOutputStream outputStream) {
- this.outputStream = outputStream;
- }
-
- /**
- * This unit won't do anything unless you start() it.
- */
- @Override
- public boolean isStartRequired() {
- return true;
- }
-
- @Override
- public UnitInputPort getInput() {
- return input;
- }
-}
diff --git a/src/com/jsyn/unitgen/UnitVoice.java b/src/com/jsyn/unitgen/UnitVoice.java
deleted file mode 100644
index 3f5e6ef..0000000
--- a/src/com/jsyn/unitgen/UnitVoice.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2011 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.util.Instrument;
-import com.jsyn.util.VoiceDescription;
-import com.softsynth.shared.time.TimeStamp;
-
-/**
- * A voice that can be allocated and played by the VoiceAllocator.
- *
- * @author Phil Burk (C) 2011 Mobileer Inc
- * @see VoiceDescription
- * @see Instrument
- */
-public interface UnitVoice extends UnitSource {
- /**
- * Play whatever you consider to be a note on this voice. Do not be constrained by traditional
- * definitions of notes or music.
- *
- * @param frequency in Hz related to the perceived pitch of the note.
- * @param amplitude generally between 0.0 and 1.0
- * @param timeStamp when to play the note
- */
- void noteOn(double frequency, double amplitude, TimeStamp timeStamp);
-
- void noteOff(TimeStamp timeStamp);
-
- /**
- * Typically a UnitVoice will be a subclass of UnitGenerator, which just returns "this".
- */
- @Override
- public UnitGenerator getUnitGenerator();
-
- /**
- * Looks up a port using its name and sets the value.
- *
- * @param portName
- * @param value
- * @param timeStamp
- */
- void setPort(String portName, double value, TimeStamp timeStamp);
-
- void usePreset(int presetIndex);
-}
diff --git a/src/com/jsyn/unitgen/Unzipper.java b/src/com/jsyn/unitgen/Unzipper.java
deleted file mode 100644
index c776ffb..0000000
--- a/src/com/jsyn/unitgen/Unzipper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2014 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-/**
- * Used inside UnitGenerators for fast smoothing of inputs.
- *
- * @author Phil Burk (C) 2014 Mobileer Inc
- */
-public class Unzipper {
- private double target;
- private double delta;
- private double current;
- private int counter;
- // About 30 msec. Power of 2 so divide should be faster.
- private static final int NUM_STEPS = 1024;
-
- public double smooth(double input) {
- if (input != target) {
- target = input;
- delta = (target - current) / NUM_STEPS;
- counter = NUM_STEPS;
- }
- if (counter > 0) {
- if (--counter == 0) {
- current = target;
- } else {
- current += delta;
- }
- }
- return current;
- }
-}
diff --git a/src/com/jsyn/unitgen/VariableRateDataReader.java b/src/com/jsyn/unitgen/VariableRateDataReader.java
deleted file mode 100644
index 2ef163c..0000000
--- a/src/com/jsyn/unitgen/VariableRateDataReader.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-
-public abstract class VariableRateDataReader extends SequentialDataReader {
- /** A scaler for playback rate. Nominally 1.0. */
- public UnitInputPort rate;
-
- public VariableRateDataReader() {
- super();
- addPort(rate = new UnitInputPort("Rate", 1.0));
- }
-}
diff --git a/src/com/jsyn/unitgen/VariableRateMonoReader.java b/src/com/jsyn/unitgen/VariableRateMonoReader.java
deleted file mode 100644
index 52b7f1e..0000000
--- a/src/com/jsyn/unitgen/VariableRateMonoReader.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.data.FloatSample;
-import com.jsyn.data.SegmentedEnvelope;
-import com.jsyn.data.ShortSample;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * This reader can play any SequentialData and will interpolate between adjacent values. It can play
- * both {@link SegmentedEnvelope envelopes} and {@link FloatSample samples}.
- *
- * <pre><code>
- // Queue an envelope to the dataQueue port.
- ampEnv.dataQueue.queue(ampEnvelope);
-</code></pre>
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- * @see FloatSample
- * @see ShortSample
- * @see SegmentedEnvelope
- */
-public class VariableRateMonoReader extends VariableRateDataReader {
- private double phase; // ranges from 0.0 to 1.0
- private double baseIncrement;
- private double source;
- private double current;
- private double target;
- private boolean starved;
- private boolean ranout;
-
- public VariableRateMonoReader() {
- super();
- addPort(output = new UnitOutputPort("Output"));
- starved = true;
- baseIncrement = 1.0;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] rates = rate.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- // Decrement phase and advance through queued data until phase back
- // in range.
- if (phase >= 1.0) {
- while (phase >= 1.0) {
- source = target;
- phase -= 1.0;
- baseIncrement = advanceToNextFrame();
- }
- } else if ((i == 0) && (starved || !dataQueue.isTargetValid())) {
- // A starved condition can only be cured at the beginning of a
- // block.
- source = target = current;
- phase = 0.0;
- baseIncrement = advanceToNextFrame();
- }
-
- // Interpolate along line segment.
- current = ((target - source) * phase) + source;
- outputs[i] = current * amplitudes[i];
-
- double phaseIncrement = baseIncrement * rates[i];
- phase += limitPhaseIncrement(phaseIncrement);
- }
-
- if (ranout) {
- ranout = false;
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- }
-
- public double limitPhaseIncrement(double phaseIncrement) {
- return phaseIncrement;
- }
-
- private double advanceToNextFrame() {
- // Fire callbacks before getting next value because we already got the
- // target value previously.
- dataQueue.firePendingCallbacks();
- if (dataQueue.hasMore()) {
- starved = false;
- target = dataQueue.readNextMonoDouble(getFramePeriod());
-
- // calculate phase increment;
- return getFramePeriod() * dataQueue.getNormalizedRate();
- } else {
- starved = true;
- ranout = true;
- phase = 0.0;
- return 0.0;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/VariableRateStereoReader.java b/src/com/jsyn/unitgen/VariableRateStereoReader.java
deleted file mode 100644
index 0f9fce8..0000000
--- a/src/com/jsyn/unitgen/VariableRateStereoReader.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2009 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * This reader can play any SequentialData and will interpolate between adjacent values. It can play
- * both envelopes and samples.
- *
- * @author Phil Burk (C) 2009 Mobileer Inc
- */
-public class VariableRateStereoReader extends VariableRateDataReader {
- private double phase;
- private double baseIncrement;
- private double source0;
- private double current0;
- private double target0;
- private double source1;
- private double current1;
- private double target1;
- private boolean starved;
- private boolean ranout;
-
- public VariableRateStereoReader() {
- dataQueue.setNumChannels(2);
- addPort(output = new UnitOutputPort(2, "Output"));
- starved = true;
- baseIncrement = 1.0;
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] rates = rate.getValues();
- double[] output0s = output.getValues(0);
- double[] output1s = output.getValues(1);
-
- for (int i = start; i < limit; i++) {
- // Decrement phase and advance through queued data until phase back
- // in range.
- if (phase >= 1.0) {
- while (phase >= 1.0) {
- source0 = target0;
- source1 = target1;
- phase -= 1.0;
- baseIncrement = advanceToNextFrame();
- }
- } else if ((i == 0) && (starved || !dataQueue.isTargetValid())) {
- // A starved condition can only be cured at the beginning of a block.
- source0 = target0 = current0;
- source1 = target1 = current1;
- phase = 0.0;
- baseIncrement = advanceToNextFrame();
- }
-
- // Interpolate along line segment.
- current0 = ((target0 - source0) * phase) + source0;
- output0s[i] = current0 * amplitudes[i];
- current1 = ((target1 - source1) * phase) + source1;
- output1s[i] = current1 * amplitudes[i];
-
- double phaseIncrement = baseIncrement * rates[i];
- phase += limitPhaseIncrement(phaseIncrement);
- }
-
- if (ranout) {
- ranout = false;
- if (dataQueue.testAndClearAutoStop()) {
- autoStop();
- }
- }
- }
-
- public double limitPhaseIncrement(double phaseIncrement) {
- return phaseIncrement;
- }
-
- private double advanceToNextFrame() {
- dataQueue.firePendingCallbacks();
- if (dataQueue.hasMore()) {
- starved = false;
-
- dataQueue.beginFrame(getFramePeriod());
- target0 = dataQueue.readCurrentChannelDouble(0);
- target1 = dataQueue.readCurrentChannelDouble(1);
- dataQueue.endFrame();
-
- // calculate phase increment;
- return synthesisEngine.getFramePeriod() * dataQueue.getNormalizedRate();
- } else {
- starved = true;
- ranout = true;
- phase = 0.0;
- return 0.0;
- }
- }
-
-}
diff --git a/src/com/jsyn/unitgen/WhiteNoise.java b/src/com/jsyn/unitgen/WhiteNoise.java
deleted file mode 100644
index b708e92..0000000
--- a/src/com/jsyn/unitgen/WhiteNoise.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-import com.jsyn.util.PseudoRandom;
-
-/**
- * WhiteNoise unit. This unit uses a pseudo-random number generator to produce white noise. The
- * energy in a white noise signal is distributed evenly across the spectrum. A new random number is
- * generated every frame.
- *
- * @author (C) 1997-2011 Phil Burk, Mobileer Inc
- * @see RedNoise
- */
-public class WhiteNoise extends UnitGenerator implements UnitSource {
- private PseudoRandom randomNum;
- public UnitInputPort amplitude;
- public UnitOutputPort output;
-
- public WhiteNoise() {
- randomNum = new PseudoRandom();
- addPort(amplitude = new UnitInputPort("Amplitude", UnitOscillator.DEFAULT_AMPLITUDE));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] amplitudes = amplitude.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- outputs[i] = randomNum.nextRandomDouble() * amplitudes[i];
- }
- }
-
- @Override
- public UnitOutputPort getOutput() {
- return output;
- }
-}
diff --git a/src/com/jsyn/unitgen/ZeroCrossingCounter.java b/src/com/jsyn/unitgen/ZeroCrossingCounter.java
deleted file mode 100644
index 6cd36ea..0000000
--- a/src/com/jsyn/unitgen/ZeroCrossingCounter.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 1997 Phil Burk, Mobileer Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.jsyn.unitgen;
-
-import com.jsyn.ports.UnitInputPort;
-import com.jsyn.ports.UnitOutputPort;
-
-/**
- * Count zero crossings. Handy for unit tests.
- *
- * @author (C) 1997-2011 Phil Burk, Mobileer Inc
- */
-public class ZeroCrossingCounter extends UnitGenerator {
- private static final double THRESHOLD = 0.0001;
- public UnitInputPort input;
- public UnitOutputPort output;
-
- private long count;
- private boolean armed;
-
- /* Define Unit Ports used by connect() and set(). */
- public ZeroCrossingCounter() {
- addPort(input = new UnitInputPort("Input"));
- addPort(output = new UnitOutputPort("Output"));
- }
-
- @Override
- public void generate(int start, int limit) {
- double[] inputs = input.getValues();
- double[] outputs = output.getValues();
-
- for (int i = start; i < limit; i++) {
- double value = inputs[i];
- if (value < -THRESHOLD) {
- armed = true;
- } else if (armed & (value > THRESHOLD)) {
- ++count;
- armed = false;
- }
- outputs[i] = value;
- }
- }
-
- public long getCount() {
- return count;
- }
-}