aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/jsyn/research
diff options
context:
space:
mode:
Diffstat (limited to 'tests/com/jsyn/research')
-rw-r--r--tests/com/jsyn/research/BenchMultiThreading.java143
-rw-r--r--tests/com/jsyn/research/RecordVariousRamps.java183
-rw-r--r--tests/com/jsyn/research/lambdas/LambdaUnits.java22
3 files changed, 0 insertions, 348 deletions
diff --git a/tests/com/jsyn/research/BenchMultiThreading.java b/tests/com/jsyn/research/BenchMultiThreading.java
deleted file mode 100644
index 79b20bb..0000000
--- a/tests/com/jsyn/research/BenchMultiThreading.java
+++ /dev/null
@@ -1,143 +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.research;
-
-import java.util.ArrayList;
-
-import junit.framework.TestCase;
-
-public class BenchMultiThreading extends TestCase {
- private static final int FRAMES_PER_BLOCK = 64;
- int numThreads = 4;
- int numLoops = 100000;
- private ArrayList<CustomThread> threadList;
-
- class CustomThread extends Thread {
- long frameCount = 0;
- long desiredFrame = 0;
- Object semaphore = new Object();
- Object goSemaphore = new Object();
- volatile boolean go = true;
- long startNano;
- long stopNano;
- long maxElapsed;
-
- @Override
- public void run() {
- try {
- startNano = System.nanoTime();
- while (go) {
- // Watch for long delays.
- stopNano = System.nanoTime();
- long elapsed = stopNano - startNano;
- startNano = System.nanoTime();
- if (elapsed > maxElapsed) {
- maxElapsed = elapsed;
- }
-
- synchronized (semaphore) {
- // Audio synthesis would occur here.
- frameCount += 1;
- // System.out.println( this + " generating frame " +
- // frameCount );
- semaphore.notify();
- }
- synchronized (goSemaphore) {
- while (desiredFrame <= frameCount) {
- goSemaphore.wait();
- }
- }
- long stopNano = System.nanoTime();
- }
- } catch (InterruptedException e) {
- System.out.println("CustomThread interrupted. ");
- }
- System.out.println("Finishing " + this);
- }
-
- public void abort() {
- go = false;
- interrupt();
- }
-
- public void waitForFrame(long targetFrame) throws InterruptedException {
- synchronized (semaphore) {
- while (frameCount < targetFrame) {
- semaphore.wait();
- }
- }
- }
-
- public void generateFrame(long desiredFrame) {
- synchronized (goSemaphore) {
- this.desiredFrame = desiredFrame;
- goSemaphore.notify();
- }
- }
-
- }
-
- public void testMultiThreads() {
- threadList = new ArrayList<CustomThread>();
- for (int i = 0; i < numThreads; i++) {
- CustomThread thread = new CustomThread();
- threadList.add(thread);
- thread.start();
- }
-
- long frameCount = 0;
- long startTime = System.currentTimeMillis();
- try {
- for (int i = 0; i < numLoops; i++) {
- frameCount += 1;
- waitForThreads(frameCount);
- // System.out.println("got frame " + frameCount );
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- long stopTime = System.currentTimeMillis();
- long elapsedTime = stopTime - startTime;
- double elapsedSeconds = 0.001 * elapsedTime;
- double blocksPerSecond = numLoops / elapsedSeconds;
- System.out.format("blocksPerSecond = %10.3f\n", blocksPerSecond);
- double framesPerSecond = blocksPerSecond * FRAMES_PER_BLOCK;
- System.out.format("audio framesPerSecond = %10.3f at %d frames per block\n",
- framesPerSecond, FRAMES_PER_BLOCK);
-
- for (CustomThread thread : threadList) {
- System.out.format("max elapsed time is %d nanos or %f msec\n", thread.maxElapsed,
- (thread.maxElapsed / 1000000.0));
- }
- for (CustomThread thread : threadList) {
- assertEquals("BlockCount must match ", frameCount, thread.frameCount);
- thread.abort();
- }
-
- }
-
- private void waitForThreads(long frameCount) throws InterruptedException {
- for (CustomThread thread : threadList) {
- // Ask threads to wake up and generate up to this frame.
- thread.generateFrame(frameCount);
- }
- for (CustomThread thread : threadList) {
- // Wait for all the threads to catch up.
- thread.waitForFrame(frameCount);
- }
- }
-}
diff --git a/tests/com/jsyn/research/RecordVariousRamps.java b/tests/com/jsyn/research/RecordVariousRamps.java
deleted file mode 100644
index c90ea9a..0000000
--- a/tests/com/jsyn/research/RecordVariousRamps.java
+++ /dev/null
@@ -1,183 +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.
- */
-/**
- * Generate steps, linear ramps and smooth ramps.
- *
- * @author (C) 2014 Phil Burk
- */
-
-package com.jsyn.research;
-
-import java.io.File;
-import java.io.IOException;
-
-import com.jsyn.JSyn;
-import com.jsyn.Synthesizer;
-import com.jsyn.unitgen.ContinuousRamp;
-import com.jsyn.unitgen.LineOut;
-import com.jsyn.unitgen.LinearRamp;
-import com.jsyn.unitgen.Multiply;
-import com.jsyn.unitgen.PassThrough;
-import com.jsyn.unitgen.PowerOfTwo;
-import com.jsyn.unitgen.SawtoothOscillatorBL;
-import com.jsyn.unitgen.UnitFilter;
-import com.jsyn.unitgen.UnitOscillator;
-import com.jsyn.util.WaveRecorder;
-
-public class RecordVariousRamps {
- private Synthesizer synth;
- private UnitOscillator osc;
- private Multiply multiplier;
- private UnitFilter ramp;
- private LinearRamp linearRamp;
- private ContinuousRamp continuousRamp;
- private LineOut lineOut;
- private WaveRecorder recorder;
- private PowerOfTwo powerOfTwo;
- private static final int MODE_STEP = 0;
- private static final int MODE_LINEAR = 1;
- private static final int MODE_SMOOTH = 2;
- private static final String[] modeNames = {
- "step", "linear", "smooth"
- };
-
- private RampEvent[] rampData = {
- new RampEvent(1.0, 1.5, 2.0), new RampEvent(-0.9, 0.5, 1.0),
- new RampEvent(0.9, 0.5, 0.8), new RampEvent(-0.3, 0.5, 0.8),
- new RampEvent(0.9, 0.5, 0.3), new RampEvent(-0.5, 0.5, 0.3),
- new RampEvent(0.8, 2.0, 1.0),
- };
-
- private static class RampEvent {
- double target;
- double eventDuration;
- double rampDuration;
-
- RampEvent(double target, double eventDuration, double rampDuration) {
- this.target = target;
- this.eventDuration = eventDuration;
- this.rampDuration = rampDuration;
- }
- }
-
- private void test(int mode) throws IOException {
- // Create a context for the synthesizer.
- synth = JSyn.createSynthesizer();
- synth.setRealTime(false);
-
- File waveFile = new File("ramp_pitch_" + modeNames[mode] + ".wav");
- // Mono 16 bits.
- recorder = new WaveRecorder(synth, waveFile, 1, 16);
- System.out.println("Writing to 16-bit WAV file " + waveFile.getAbsolutePath());
-
- // Add some tone generators.
- synth.add(osc = new SawtoothOscillatorBL());
-
- // Add a controller that will sweep up.
- synth.add(multiplier = new Multiply());
- synth.add(powerOfTwo = new PowerOfTwo());
- // Add an output unit.
- synth.add(lineOut = new LineOut());
- multiplier.inputB.set(660.0);
-
- switch (mode) {
- case MODE_STEP:
- synth.add(ramp = new PassThrough());
- break;
- case MODE_LINEAR:
- synth.add(ramp = linearRamp = new LinearRamp());
- linearRamp.current.set(-1.0);
- linearRamp.time.set(10.0);
- break;
- case MODE_SMOOTH:
- synth.add(ramp = continuousRamp = new ContinuousRamp());
- continuousRamp.current.set(-1.0);
- continuousRamp.time.set(10.0);
- break;
- }
-
- ramp.getInput().set(-1.0);
- ramp.getOutput().connect(powerOfTwo.input);
-
- powerOfTwo.output.connect(multiplier.inputA);
- multiplier.output.connect(osc.frequency);
-
- // Connect the oscillator to the left and right audio output.
- osc.output.connect(0, lineOut.input, 0);
- osc.output.connect(0, lineOut.input, 1);
-
- // Start synthesizer using default stereo output at 44100 Hz.
- synth.start();
-
- osc.output.connect(0, recorder.getInput(), 0);
- // When we start the recorder it will pull data from the oscillator
- // and sweeper.
- recorder.start();
-
- // We also need to start the LineOut if we want to hear it now.
- lineOut.start();
-
- // Get synthesizer time in seconds.
- double nextEventTime = synth.getCurrentTime() + 1.0;
- try {
- synth.sleepUntil(nextEventTime);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- for (RampEvent rampEvent : rampData) {
-
- switch (mode) {
- case MODE_STEP:
- break;
- case MODE_LINEAR:
- linearRamp.time.set(rampEvent.rampDuration);
- break;
- case MODE_SMOOTH:
- continuousRamp.time.set(rampEvent.rampDuration);
- break;
- }
- ramp.getInput().set(rampEvent.target);
-
- nextEventTime += rampEvent.eventDuration;
- System.out.println("target = " + rampEvent.target + ", rampDur = "
- + rampEvent.rampDuration + ", eventDur = " + rampEvent.eventDuration);
- try {
- synth.sleepUntil(nextEventTime);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- if (recorder != null) {
- recorder.stop();
- recorder.close();
- }
- // Stop everything.
- synth.stop();
- }
-
- public static void main(String[] args) {
- try {
- new RecordVariousRamps().test(MODE_STEP);
- new RecordVariousRamps().test(MODE_LINEAR);
- new RecordVariousRamps().test(MODE_SMOOTH);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/tests/com/jsyn/research/lambdas/LambdaUnits.java b/tests/com/jsyn/research/lambdas/LambdaUnits.java
deleted file mode 100644
index 42807ac..0000000
--- a/tests/com/jsyn/research/lambdas/LambdaUnits.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.jsyn.research.lambdas;
-
-import java.util.function.BinaryOperator;
-
-public class LambdaUnits {
-
-
- public static void main(String[] args) {
- test();
- }
-
- void tryLambda(BinaryOperator<Double> op) {
- double result = op.apply(3.0, 4.0);
- System.out.println("result = " + result);
- }
-
- private static void test() {
- System.out.println("Test Lambdas");
- // Need Java 8! tryLambda((x, y) -> (x * y));
- }
-
-}