diff options
author | Phil Burk <[email protected]> | 2015-04-29 08:15:04 -0700 |
---|---|---|
committer | Phil Burk <[email protected]> | 2015-04-29 08:15:04 -0700 |
commit | 3c25b6415d4a6fa3d719815c45ad6e98de57d744 (patch) | |
tree | 8029f57340ef5211586ea21d8a63614cfb1a9ae9 /src/com/jsyn | |
parent | d3c74876db36598813068ce0bb8ea887e41a1c71 (diff) | |
parent | 7aec269a333d43cc226a0c9c30986e4b50bafa28 (diff) |
Merge pull request #5 from philburk/examples
Use AudioMath for pitch to frequency conversion. Cleanup PitchDetector.
Diffstat (limited to 'src/com/jsyn')
-rw-r--r-- | src/com/jsyn/instruments/SubtractiveSynthVoice.java | 3 | ||||
-rw-r--r-- | src/com/jsyn/unitgen/PitchDetector.java | 2 | ||||
-rw-r--r-- | src/com/jsyn/util/AutoCorrelator.java | 42 |
3 files changed, 6 insertions, 41 deletions
diff --git a/src/com/jsyn/instruments/SubtractiveSynthVoice.java b/src/com/jsyn/instruments/SubtractiveSynthVoice.java index 9ea593e..af3329e 100644 --- a/src/com/jsyn/instruments/SubtractiveSynthVoice.java +++ b/src/com/jsyn/instruments/SubtractiveSynthVoice.java @@ -135,6 +135,7 @@ public class SubtractiveSynthVoice extends Circuit implements UnitVoice { cutoffRange.set(500.0); filter.Q.set(3.0); break; + case 2: default: ampEnv.attack.set(0.1); ampEnv.decay.set(0.3); @@ -147,7 +148,7 @@ public class SubtractiveSynthVoice extends Circuit implements UnitVoice { } static String[] presetNames = { - "FastSaw", "SlowSaw", "BrightSaw", "" + "FastSaw", "SlowSaw", "BrightSaw" }; static class MyVoiceDescription extends VoiceDescription { diff --git a/src/com/jsyn/unitgen/PitchDetector.java b/src/com/jsyn/unitgen/PitchDetector.java index 59bba69..da6a0e3 100644 --- a/src/com/jsyn/unitgen/PitchDetector.java +++ b/src/com/jsyn/unitgen/PitchDetector.java @@ -42,7 +42,7 @@ public class PitchDetector extends UnitGenerator { protected SignalCorrelator signalCorrelator; private double lastFrequency = 440.0; - private double lastPeriod = 44100.0 / lastFrequency; // result of analysis + 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; diff --git a/src/com/jsyn/util/AutoCorrelator.java b/src/com/jsyn/util/AutoCorrelator.java index 5512abb..2996036 100644 --- a/src/com/jsyn/util/AutoCorrelator.java +++ b/src/com/jsyn/util/AutoCorrelator.java @@ -193,42 +193,9 @@ public class AutoCorrelator implements SignalCorrelator { return interpolatePeak(d1, d2, d3) + indexMax; } - // return offset between -1.0 and +1.0 from center + // Use quadratic fit to return offset between -0.5 and +0.5 from center. protected static double interpolatePeak(double d1, double d2, double d3) { - // System.out.println( " d1 = " + d1 + ", d2 = " + d2 + ", d3 = " - // + d3 ); - // Make sure d2 is a maximum or result will blow up. - if (d1 > d2) - return -1.0; - else if (d3 > d2) - return 1.0; - - // The interpolated maximum should be the same - // point where the line between slopes crosses zero. - double y2 = d3 - d2; - double y1 = d2 - d1; - // System.out.println(" y1 = " + y1 + ", y2 = " + y2 ); - // Derive equations for interpolated maximum. - // y = ax + b - // when y is zero, x = -b/a - // y2 = a*x2 + b - // y1 = a*x1 + b - // b = y2-a*x2 - // y1 = a*x1 + (y2 - a*x2) - // y1 - y2 = a*(x1 - x2) ; x1 and x2 are one from each other - // y1 - y2 = a*(-1) - // a = y2 - y1 - // for zero crossing: - // 0 = ax+b - // -ax = b - // x = -b / a - // = -(y2-a*x2)/a - // = (a*x2 -y2)/a - // = x2 - y2/a - // = x2 - (y2/(y2-y1)) - double x2 = 0.5; - double precise = x2 - (y2 / (y2 - y1)); - return precise; + return 0.5 * (d1 - d3) / (d1 - (2.0 * d2) + d3); } // Calculate a little more for each sample. @@ -293,7 +260,6 @@ public class AutoCorrelator implements SignalCorrelator { @Override public boolean addSample(double value) { - boolean updated = false; double average = (value + previousSample) * 0.5; previousSample = value; @@ -304,9 +270,7 @@ public class AutoCorrelator implements SignalCorrelator { } buffer[cursor] = (float) average; - updated = incrementalAnalysis(); - - return updated; + return incrementalAnalysis(); } @Override |