aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/jsyn/examples
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2016-11-30 22:13:22 -0800
committerPhil Burk <[email protected]>2016-11-30 22:13:44 -0800
commit265381fa6d885f7fa7fdb76c0e6bf0c9511c63b4 (patch)
tree583b57862b4d24162dd8b095f874b0fdd44f068e /tests/com/jsyn/examples
parent9fc77bbf87bea398dedfa76e2ab71933169ef5ad (diff)
Added evaluate() to FloatSample.
Diffstat (limited to 'tests/com/jsyn/examples')
-rw-r--r--tests/com/jsyn/examples/PlaySampleWaveShaper.java34
1 files changed, 6 insertions, 28 deletions
diff --git a/tests/com/jsyn/examples/PlaySampleWaveShaper.java b/tests/com/jsyn/examples/PlaySampleWaveShaper.java
index c282028..73758dd 100644
--- a/tests/com/jsyn/examples/PlaySampleWaveShaper.java
+++ b/tests/com/jsyn/examples/PlaySampleWaveShaper.java
@@ -38,26 +38,6 @@ public class PlaySampleWaveShaper {
private Synthesizer synth;
private LineOut lineOut;
- static class FloatSampleTable implements Function {
- private FloatSample mSample;
-
- FloatSampleTable(FloatSample sample) {
- mSample = sample;
- }
-
- @Override
- public double evaluate(double input) {
- // Input ranges from -1 to +1
- // Map it to range of sample with guard point.
- double normalizedInput = (input + 1.0) * 0.5;
- // Clip so it does not go out of range of the sample.
- if (normalizedInput < 0.0) normalizedInput = 0.0;
- else if (normalizedInput > 1.0) normalizedInput = 1.0;
- double fractionalIndex = (mSample.getNumFrames() - 1.01) * normalizedInput;
- return mSample.interpolate(fractionalIndex);
- }
- }
-
private void test() {
URL sampleFile;
@@ -89,16 +69,14 @@ public class PlaySampleWaveShaper {
throw new RuntimeException("Can only use mono samples.");
}
- FloatSampleTable sampleTable = new FloatSampleTable(sample);
-
- System.out.println("eval -1.1 = " + sampleTable.evaluate(-1.1));
- System.out.println("eval -1.0 = " + sampleTable.evaluate(-1.0));
- System.out.println("eval 0.3 = " + sampleTable.evaluate(0.3));
- System.out.println("eval 1.0 = " + sampleTable.evaluate(1.0));
- System.out.println("eval 1.1 = " + sampleTable.evaluate(1.1));
+ System.out.println("eval -1.1 = " + sample.evaluate(-1.1));
+ System.out.println("eval -1.0 = " + sample.evaluate(-1.0));
+ System.out.println("eval 0.3 = " + sample.evaluate(0.3));
+ System.out.println("eval 1.0 = " + sample.evaluate(1.0));
+ System.out.println("eval 1.1 = " + sample.evaluate(1.1));
FunctionEvaluator shaper = new FunctionEvaluator();
- shaper.function.set(sampleTable);
+ shaper.function.set(sample);
synth.add(shaper);
shaper.output.connect(0, lineOut.input, 0);