aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/jsyn
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2015-01-02 13:23:30 -0800
committerPhil Burk <[email protected]>2015-04-29 08:11:10 -0700
commit7aec269a333d43cc226a0c9c30986e4b50bafa28 (patch)
tree8029f57340ef5211586ea21d8a63614cfb1a9ae9 /tests/com/jsyn
parentd3c74876db36598813068ce0bb8ea887e41a1c71 (diff)
Use AudioMath for pitch to frequency conversion.
Fix ListDevices default. Cleanup interpolator in AutoCorrelator. Remove empty string from SubtractiveSynth library.
Diffstat (limited to 'tests/com/jsyn')
-rw-r--r--tests/com/jsyn/benchmarks/BenchJSyn.java52
-rw-r--r--tests/com/jsyn/examples/ListAudioDevices.java2
-rw-r--r--tests/com/jsyn/examples/PlayChords.java12
3 files changed, 50 insertions, 16 deletions
diff --git a/tests/com/jsyn/benchmarks/BenchJSyn.java b/tests/com/jsyn/benchmarks/BenchJSyn.java
index 51e09a4..5b8d128 100644
--- a/tests/com/jsyn/benchmarks/BenchJSyn.java
+++ b/tests/com/jsyn/benchmarks/BenchJSyn.java
@@ -22,9 +22,13 @@ package com.jsyn.benchmarks;
import com.jsyn.JSyn;
import com.jsyn.Synthesizer;
import com.jsyn.unitgen.PassThrough;
+import com.jsyn.unitgen.PitchDetector;
import com.jsyn.unitgen.SawtoothOscillator;
import com.jsyn.unitgen.SawtoothOscillatorBL;
import com.jsyn.unitgen.SawtoothOscillatorDPW;
+import com.jsyn.unitgen.SineOscillator;
+import com.jsyn.unitgen.SquareOscillator;
+import com.jsyn.unitgen.SquareOscillatorBL;
import com.jsyn.unitgen.UnitOscillator;
import com.softsynth.math.FourierMath;
@@ -57,11 +61,18 @@ public class BenchJSyn {
double realTime = 10.0;
int count = 40;
- benchFFTDouble();
- benchFFTFloat();
- benchmarkOscillator(SawtoothOscillator.class, count, realTime);
- benchmarkOscillator(SawtoothOscillatorDPW.class, count, realTime);
- benchmarkOscillator(SawtoothOscillatorBL.class, count, realTime);
+ // benchFFTDouble();
+ // benchFFTFloat();
+ /*
+ * realTime = 20.0; benchmarkOscillator(SawtoothOscillator.class, count, realTime);
+ * benchmarkOscillator(SawtoothOscillatorDPW.class, count, realTime);
+ * benchmarkOscillator(SawtoothOscillatorBL.class, count, realTime);
+ */
+ benchmarkOscillator(SquareOscillator.class, count, realTime);
+ benchmarkOscillator(SquareOscillatorBL.class, count, realTime);
+
+ benchmarkOscillator(SineOscillator.class, count, realTime);
+ benchmarkPitchDetector(count, realTime);
}
@@ -164,6 +175,37 @@ public class BenchJSyn {
stopSynth();
}
+ private void benchmarkPitchDetector(int count, double realTime) throws InstantiationException,
+ IllegalAccessException, InterruptedException {
+ startSynth();
+
+ PitchDetector detector = new PitchDetector();
+ synth.add(detector);
+ double frequency = 198.0;
+ double period = synth.getFrameRate() / frequency;
+ // simple harmonic synthesis
+ for (int i = 0; i < count; i++) {
+ SineOscillator osc = new SineOscillator();
+ synth.add(osc);
+ osc.frequency.set(frequency * (i + 1));
+ osc.amplitude.set(0.5 * (1.0 - (i * 0.2)));
+ osc.output.connect(detector.input);
+ }
+ detector.start();
+ startTiming();
+ synth.sleepFor(realTime);
+ endTiming(PitchDetector.class, count, realTime);
+
+ double measuredPeriod = detector.period.getValue();
+ double confidence = detector.confidence.getValue();
+ System.out.println("period = " + period + ", measured = " + measuredPeriod
+ + ", confidence = " + confidence);
+ if (confidence > 0.1) {
+ assert (Math.abs(measuredPeriod - period) < 0.1);
+ }
+ stopSynth();
+ }
+
private void endTiming(Class<?> clazz, int count, double realTime) {
endTime = System.nanoTime();
double elapsedTime = (endTime - startTime) * 1E-9;
diff --git a/tests/com/jsyn/examples/ListAudioDevices.java b/tests/com/jsyn/examples/ListAudioDevices.java
index 6c5372d..dceaa0d 100644
--- a/tests/com/jsyn/examples/ListAudioDevices.java
+++ b/tests/com/jsyn/examples/ListAudioDevices.java
@@ -33,7 +33,7 @@ public class ListAudioDevices {
int maxInputs = audioManager.getMaxInputChannels(i);
int maxOutputs = audioManager.getMaxInputChannels(i);
boolean isDefaultInput = (i == audioManager.getDefaultInputDeviceID());
- boolean isDefaultOutput = (i == audioManager.getDefaultInputDeviceID());
+ boolean isDefaultOutput = (i == audioManager.getDefaultOutputDeviceID());
System.out.println("#" + i + " : " + deviceName);
System.out.println(" max inputs : " + maxInputs
+ (isDefaultInput ? " (default)" : ""));
diff --git a/tests/com/jsyn/examples/PlayChords.java b/tests/com/jsyn/examples/PlayChords.java
index 0b1ae2e..28cab5f 100644
--- a/tests/com/jsyn/examples/PlayChords.java
+++ b/tests/com/jsyn/examples/PlayChords.java
@@ -22,6 +22,7 @@ import com.jsyn.instruments.SubtractiveSynthVoice;
import com.jsyn.unitgen.LineOut;
import com.jsyn.unitgen.UnitVoice;
import com.jsyn.util.VoiceAllocator;
+import com.softsynth.math.AudioMath;
import com.softsynth.shared.time.TimeStamp;
/**
@@ -167,21 +168,12 @@ public class PlayChords {
}
private void noteOn(double time, int noteNumber) {
- double frequency = convertPitchToFrequency(noteNumber);
+ double frequency = AudioMath.pitchToFrequency(noteNumber);
double amplitude = 0.2;
TimeStamp timeStamp = new TimeStamp(time);
allocator.noteOn(noteNumber, frequency, amplitude, timeStamp);
}
- /**
- * Calculate frequency in Hertz based on MIDI pitch. Middle C is 60.0. You can use fractional
- * pitches so 60.5 would give you a pitch half way between C and C#.
- */
- double convertPitchToFrequency(double pitch) {
- final double concertA = 440.0;
- return concertA * Math.pow(2.0, ((pitch - 69) * (1.0 / 12.0)));
- }
-
public static void main(String[] args) {
new PlayChords().test();
}