aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/jsyn/unitgen/ExponentialRamp.java18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main/java/com/jsyn/unitgen/ExponentialRamp.java b/src/main/java/com/jsyn/unitgen/ExponentialRamp.java
index 36159b4..6917126 100644
--- a/src/main/java/com/jsyn/unitgen/ExponentialRamp.java
+++ b/src/main/java/com/jsyn/unitgen/ExponentialRamp.java
@@ -4,9 +4,9 @@
* 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.
@@ -21,7 +21,7 @@ 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
@@ -35,10 +35,11 @@ public class ExponentialRamp extends UnitFilter {
private double target;
private double timeHeld = 0.0;
private double scaler = 1.0;
+ private double MIN_VALUE = 0.00001;
public ExponentialRamp() {
addPort(time = new UnitInputPort("Time"));
- input.setup(0.0001, 1.0, 1.0);
+ input.setup(MIN_VALUE, 1.0, 1.0);
addPort(current = new UnitVariablePort("Current", 1.0));
}
@@ -49,6 +50,10 @@ public class ExponentialRamp extends UnitFilter {
double currentTime = time.getValues()[0];
double currentValue = current.getValue();
+ // Clip input values to prevent illegal values close to zero or negative.
+ currentInput = Math.max(MIN_VALUE, currentInput);
+ currentValue = Math.max(MIN_VALUE, currentValue);
+
if (currentTime != timeHeld) {
scaler = convertTimeToExponentialScaler(currentTime, currentValue, currentInput);
timeHeld = currentTime;
@@ -92,11 +97,6 @@ public class ExponentialRamp extends UnitFilter {
}
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));