From f4b2b36e0d78e034025317ebacb7e8c4a063f5a3 Mon Sep 17 00:00:00 2001 From: wirsing Date: Tue, 1 Jul 2014 18:47:40 -0700 Subject: [PATCH] Removed Sound class, added Engine + Audio Device. No need to start a stream anymore. --- .../Analysis/AmplitudeRMS/AmplitudeRMS.pde | 6 +- .../Analysis/FFTSpectrum/FFTSpectrum.pde | 4 - .../examples/Demos/Envelopes/Envelopes.pde | 4 - .../examples/Demos/Keyboard/Keyboard.pde | 5 +- .../sound/examples/Demos/Sampler/Sampler.pde | 4 +- .../Demos/SineCluster/SineCluster.pde | 4 - .../examples/Demos/Spectrum/Spectrum.pde | 6 +- .../Effects/Filter/BandPass/BandPass.pde | 4 +- .../Effects/Filter/HighPass/HighPass.pde | 4 +- .../Effects/Filter/LowPass/LowPass.pde | 9 +- .../Effects/Variable_Delay/Variable_Delay.pde | 6 +- .../sound/examples/Noise/White/White.pde | 4 +- .../Oscillators/PulseWidth/PulseWidth.pde | 4 +- .../examples/Oscillators/SawWave/SawWave.pde | 6 +- .../Oscillators/SineWave/SineWave.pde | 7 +- .../examples/Oscillators/SqrWave/SqrWave.pde | 7 +- .../examples/Oscillators/TriWave/TriWave.pde | 7 +- .../examples/Soundfile/Sample/Sample.pde | 6 +- .../sound/src/processing/sound/Amplitude.java | 5 +- .../sound/{Sound.java => AudioDevice.java} | 45 ++-- .../sound/src/processing/sound/AudioIn.java | 7 +- .../sound/src/processing/sound/BPF.java | 7 +- .../sound/src/processing/sound/Delay.java | 7 +- .../sound/src/processing/sound/Engine.java | 211 ++++++++++++++++++ .../sound/src/processing/sound/Env.java | 7 +- .../sound/src/processing/sound/FFT.java | 7 +- .../sound/src/processing/sound/HPF.java | 7 +- .../sound/src/processing/sound/LPF.java | 7 +- .../sound/src/processing/sound/Pulse.java | 7 +- .../sound/src/processing/sound/SawOsc.java | 8 +- .../sound/src/processing/sound/SinOsc.java | 5 +- .../sound/src/processing/sound/SoundFile.java | 18 +- .../sound/src/processing/sound/SqrOsc.java | 5 +- .../sound/src/processing/sound/TriOsc.java | 6 +- .../src/processing/sound/WhiteNoise.java | 5 +- 35 files changed, 307 insertions(+), 154 deletions(-) rename java/libraries/sound/src/processing/sound/{Sound.java => AudioDevice.java} (55%) create mode 100644 java/libraries/sound/src/processing/sound/Engine.java diff --git a/java/libraries/sound/examples/Analysis/AmplitudeRMS/AmplitudeRMS.pde b/java/libraries/sound/examples/Analysis/AmplitudeRMS/AmplitudeRMS.pde index 46b2fee98..8dfcb284f 100644 --- a/java/libraries/sound/examples/Analysis/AmplitudeRMS/AmplitudeRMS.pde +++ b/java/libraries/sound/examples/Analysis/AmplitudeRMS/AmplitudeRMS.pde @@ -6,7 +6,6 @@ the mean as a float between 0 and 1. import processing.sound.*; -Sound stream; SoundFile sample; Amplitude rms; @@ -14,10 +13,7 @@ int scale=1; public void setup() { size(640,360); - - // Create and start the sound renderer - stream = new Sound(this, 44100, 512); - + //Load and play a soundfile and loop it sample = new SoundFile(this, "beat.aiff"); sample.loop(); diff --git a/java/libraries/sound/examples/Analysis/FFTSpectrum/FFTSpectrum.pde b/java/libraries/sound/examples/Analysis/FFTSpectrum/FFTSpectrum.pde index 5945f923d..56de63aa1 100644 --- a/java/libraries/sound/examples/Analysis/FFTSpectrum/FFTSpectrum.pde +++ b/java/libraries/sound/examples/Analysis/FFTSpectrum/FFTSpectrum.pde @@ -7,7 +7,6 @@ two times that size) and a float array with the same size. import processing.sound.*; -Sound stream; SoundFile sample; FFT fft; @@ -19,9 +18,6 @@ public void setup() { size(bands,360); background(255); - // Create and start the sound renderer - stream = new Sound(this, 44100, 256); - //Load and play a soundfile and loop it. This has to be called // before the FFT is created. sample = new SoundFile(this, "beat.aiff"); diff --git a/java/libraries/sound/examples/Demos/Envelopes/Envelopes.pde b/java/libraries/sound/examples/Demos/Envelopes/Envelopes.pde index 0dc0379e4..6d2f4e1fb 100644 --- a/java/libraries/sound/examples/Demos/Envelopes/Envelopes.pde +++ b/java/libraries/sound/examples/Demos/Envelopes/Envelopes.pde @@ -14,7 +14,6 @@ depending on pre defined time segments. import processing.sound.*; -Sound stream; TriOsc triOsc; Env env; @@ -37,9 +36,6 @@ void setup() { size(640, 360); background(255); - //Create and start the Sound renderer - stream = new Sound(this); - // Create triangle wave and start it triOsc = new TriOsc(this); //triOsc.play(); diff --git a/java/libraries/sound/examples/Demos/Keyboard/Keyboard.pde b/java/libraries/sound/examples/Demos/Keyboard/Keyboard.pde index 765470079..d0b3e63c0 100644 --- a/java/libraries/sound/examples/Demos/Keyboard/Keyboard.pde +++ b/java/libraries/sound/examples/Demos/Keyboard/Keyboard.pde @@ -7,7 +7,7 @@ Each time a sound is played a colored rect with a random color is displayed. import processing.sound.*; -Sound stream; +AudioDevice device; SoundFile[] file; // Define the number of samples @@ -15,13 +15,12 @@ int numsounds = 5; int value[] = {0,0,0}; - void setup(){ size(640, 360); background(255); // Create a Sound renderer and an array of empty soundfiles - stream = new Sound(this, 44100, 32); + device = new AudioDevice(this, 48000, 32); file = new SoundFile[numsounds]; // Load 5 soundfiles from a folder in a for loop. By naming the files 1., 2., 3., n.aif it is easy to iterate diff --git a/java/libraries/sound/examples/Demos/Sampler/Sampler.pde b/java/libraries/sound/examples/Demos/Sampler/Sampler.pde index ecc7c5eae..3ef5a3054 100644 --- a/java/libraries/sound/examples/Demos/Sampler/Sampler.pde +++ b/java/libraries/sound/examples/Demos/Sampler/Sampler.pde @@ -7,7 +7,6 @@ Each time a sound is played a colored rect with a random color is displayed. import processing.sound.*; -Sound stream; SoundFile[] file; // Define the number of samples @@ -31,8 +30,7 @@ void setup(){ size(640, 360); background(255); - // Create a Sound renderer and an array of empty soundfiles - stream = new Sound(this); + // Create an array of empty soundfiles file = new SoundFile[numsounds]; // Load 5 soundfiles from a folder in a for loop. By naming the files 1., 2., 3., n.aif it is easy to iterate diff --git a/java/libraries/sound/examples/Demos/SineCluster/SineCluster.pde b/java/libraries/sound/examples/Demos/SineCluster/SineCluster.pde index 7d5f701e3..730b85c9a 100644 --- a/java/libraries/sound/examples/Demos/SineCluster/SineCluster.pde +++ b/java/libraries/sound/examples/Demos/SineCluster/SineCluster.pde @@ -7,7 +7,6 @@ frequency of the oscillator and X the detuning of the oscillator. The basic freq import processing.sound.*; -Sound stream; SinOsc[] sineWaves; // The number of oscillators @@ -20,9 +19,6 @@ void setup() { size(500, 500); background(255); - //Create and start the Sound renderer - stream = new Sound(this); - // Create the oscillators and amplitudes sineWaves = new SinOsc[numSines]; sineVolume = new float[numSines]; diff --git a/java/libraries/sound/examples/Demos/Spectrum/Spectrum.pde b/java/libraries/sound/examples/Demos/Spectrum/Spectrum.pde index a355e056b..296e4ad80 100644 --- a/java/libraries/sound/examples/Demos/Spectrum/Spectrum.pde +++ b/java/libraries/sound/examples/Demos/Spectrum/Spectrum.pde @@ -7,7 +7,6 @@ two times that size) and a float array with the same size. import processing.sound.*; -Sound stream; SoundFile sample; FFT fft; @@ -18,14 +17,11 @@ float[] spec = new float[bands]; public void setup() { size(bands,360); background(255); - - // Create and start the sound renderer - stream = new Sound(this, 44100, 256); //Load and play a soundfile and loop it. This has to be called // before the FFT is created. sample = new SoundFile(this, "beat.aiff"); - sample.play(true); + sample.loop(); // Create and patch the rms tracker fft = new FFT(this); diff --git a/java/libraries/sound/examples/Effects/Filter/BandPass/BandPass.pde b/java/libraries/sound/examples/Effects/Filter/BandPass/BandPass.pde index 8abd9af06..3bdd78e06 100644 --- a/java/libraries/sound/examples/Effects/Filter/BandPass/BandPass.pde +++ b/java/libraries/sound/examples/Effects/Filter/BandPass/BandPass.pde @@ -5,7 +5,6 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; -Sound stream; WhiteNoise noise; BPF bandPass; @@ -15,8 +14,7 @@ void setup() { size(640,360); background(255); - // Create and start the sound renderer and the noise generator - stream = new Sound(this); + // Create the noise generator + Filter noise = new WhiteNoise(this); bandPass = new BPF(this); noise.play(0.5); diff --git a/java/libraries/sound/examples/Effects/Filter/HighPass/HighPass.pde b/java/libraries/sound/examples/Effects/Filter/HighPass/HighPass.pde index 18a4089ba..6a99e5f97 100644 --- a/java/libraries/sound/examples/Effects/Filter/HighPass/HighPass.pde +++ b/java/libraries/sound/examples/Effects/Filter/HighPass/HighPass.pde @@ -5,7 +5,6 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; -Sound stream; WhiteNoise noise; HPF highPass; @@ -15,8 +14,7 @@ void setup() { size(640,360); background(255); - // Create and start the sound renderer and the noise generator - stream = new Sound(this); + // Create the noise generator + filter noise = new WhiteNoise(this); highPass = new HPF(this); noise.play(0.5); diff --git a/java/libraries/sound/examples/Effects/Filter/LowPass/LowPass.pde b/java/libraries/sound/examples/Effects/Filter/LowPass/LowPass.pde index 42a248002..8d499f10d 100644 --- a/java/libraries/sound/examples/Effects/Filter/LowPass/LowPass.pde +++ b/java/libraries/sound/examples/Effects/Filter/LowPass/LowPass.pde @@ -5,25 +5,22 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; -Sound stream; WhiteNoise noise; LPF lowPass; - float amp=0.0; void setup() { size(640,360); background(255); - // Create and start the sound renderer and the noise generator - stream = new Sound(this); + // Create the noise generator + filter noise = new WhiteNoise(this); lowPass = new LPF(this); noise.play(0.5); - lowPass.process(noise, 100); + lowPass.process(noise, 800); } void draw() { - lowPass.freq(map(mouseX, 0, 350, 20, 10000)); + lowPass.freq(map(mouseX, 0, 350, 800, 10000)); } diff --git a/java/libraries/sound/examples/Effects/Variable_Delay/Variable_Delay.pde b/java/libraries/sound/examples/Effects/Variable_Delay/Variable_Delay.pde index 12ddd9844..c00c84e3e 100644 --- a/java/libraries/sound/examples/Effects/Variable_Delay/Variable_Delay.pde +++ b/java/libraries/sound/examples/Effects/Variable_Delay/Variable_Delay.pde @@ -4,17 +4,13 @@ This is a sound file player. import processing.sound.*; -Sound stream; SoundFile soundfile; Delay delay; void setup() { size(640,360); background(255); - - // Create and start the sound renderer - stream = new Sound(this); - + //Load a soundfile soundfile = new SoundFile(this, "vibraphon.aiff"); diff --git a/java/libraries/sound/examples/Noise/White/White.pde b/java/libraries/sound/examples/Noise/White/White.pde index 06277cdbc..ab8a9be86 100644 --- a/java/libraries/sound/examples/Noise/White/White.pde +++ b/java/libraries/sound/examples/Noise/White/White.pde @@ -5,7 +5,6 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; -Sound stream; WhiteNoise noise; float amp=0.0; @@ -14,8 +13,7 @@ void setup() { size(640, 360); background(255); - // Create and start the sound renderer and the noise generator - stream = new Sound(this); + // Create the noise generator noise = new WhiteNoise(this); noise.play(); } diff --git a/java/libraries/sound/examples/Oscillators/PulseWidth/PulseWidth.pde b/java/libraries/sound/examples/Oscillators/PulseWidth/PulseWidth.pde index 4a3027646..80529d5f6 100644 --- a/java/libraries/sound/examples/Oscillators/PulseWidth/PulseWidth.pde +++ b/java/libraries/sound/examples/Oscillators/PulseWidth/PulseWidth.pde @@ -7,15 +7,13 @@ If you want to set all of them at the same time use import processing.sound.*; -Sound stream; Pulse pulse; void setup() { size(640,360); background(255); - // Create and start the sound renderer and the pulse wave oscillator - stream = new Sound(this); + // Create and start the pulse wave oscillator pulse = new Pulse(this); pulse.play(); } diff --git a/java/libraries/sound/examples/Oscillators/SawWave/SawWave.pde b/java/libraries/sound/examples/Oscillators/SawWave/SawWave.pde index 92f7034c9..885127c86 100644 --- a/java/libraries/sound/examples/Oscillators/SawWave/SawWave.pde +++ b/java/libraries/sound/examples/Oscillators/SawWave/SawWave.pde @@ -6,17 +6,13 @@ the same time use .set(float freq, float amp, float add, float pan) import processing.sound.*; -Sound stream; SawOsc saw; void setup() { size(640, 360); background(255); - // Create and start the sound renderer and the sine oscillator. - // Second and Third arguments are optional, default is 44100 / 512 - // for Sample Rate and Buffer Size - stream = new Sound(this, 44100, 256); + // Create the sine oscillator. saw = new SawOsc(this); //Start the Sine Oscillator. There will be no sound in the beginning diff --git a/java/libraries/sound/examples/Oscillators/SineWave/SineWave.pde b/java/libraries/sound/examples/Oscillators/SineWave/SineWave.pde index e07ed3b6d..d0c0f577e 100644 --- a/java/libraries/sound/examples/Oscillators/SineWave/SineWave.pde +++ b/java/libraries/sound/examples/Oscillators/SineWave/SineWave.pde @@ -6,7 +6,6 @@ the same time use .set(float freq, float amp, float add, float pan) import processing.sound.*; -Sound stream; SinOsc sine; float freq=400; @@ -17,10 +16,8 @@ void setup() { size(640, 360); background(255); - // Create and start the sound renderer and the sine oscillator. - // Second and Third arguments are optional, default is 44100 / 512 - // for Sample Rate and Buffer Size - stream = new Sound(this, 44100, 256); + // Create and start the sine oscillator. + sine = new SinOsc(this); //Start the Sine Oscillator. diff --git a/java/libraries/sound/examples/Oscillators/SqrWave/SqrWave.pde b/java/libraries/sound/examples/Oscillators/SqrWave/SqrWave.pde index ac4ae9229..1a568dea2 100644 --- a/java/libraries/sound/examples/Oscillators/SqrWave/SqrWave.pde +++ b/java/libraries/sound/examples/Oscillators/SqrWave/SqrWave.pde @@ -6,17 +6,14 @@ the same time use .set(float freq, float amp, float add, float pan) import processing.sound.*; -Sound stream; SqrOsc sqr; void setup() { size(640,360); background(255); - // Create and start the sound renderer and the sine oscillator. - // Second and Third arguments are optional, default is 44100 / 512 - // for Sample Rate and Buffer Size - stream = new Sound(this, 44100, 256); + // Create and start the sine oscillator. + sqr = new SqrOsc(this); //Start the Sine Oscillator. There will be no sound in the beginning diff --git a/java/libraries/sound/examples/Oscillators/TriWave/TriWave.pde b/java/libraries/sound/examples/Oscillators/TriWave/TriWave.pde index ee75a735b..e2d55620f 100644 --- a/java/libraries/sound/examples/Oscillators/TriWave/TriWave.pde +++ b/java/libraries/sound/examples/Oscillators/TriWave/TriWave.pde @@ -6,17 +6,14 @@ the same time use .set(float freq, float amp, float add, float pan) import processing.sound.*; -Sound stream; TriOsc tri; void setup() { size(640,360); background(255); - // Create and start the sound renderer and the sine oscillator. - // Second and Third arguments are optional, default is 44100 / 512 - // for Sample Rate and Buffer Size - stream = new Sound(this, 44100, 256); + // Create and start the triangle wave oscillator. + tri = new TriOsc(this); //Start the Sine Oscillator. There will be no sound in the beginning diff --git a/java/libraries/sound/examples/Soundfile/Sample/Sample.pde b/java/libraries/sound/examples/Soundfile/Sample/Sample.pde index 57cb58879..4d8caa67c 100644 --- a/java/libraries/sound/examples/Soundfile/Sample/Sample.pde +++ b/java/libraries/sound/examples/Soundfile/Sample/Sample.pde @@ -5,16 +5,12 @@ This is a sound file player. import processing.sound.*; -Sound stream; SoundFile soundfile; void setup() { size(640,360); background(255); - - // Create and start the sound renderer - stream = new Sound(this); - + //Load a soundfile soundfile = new SoundFile(this, "vibraphon.aiff"); diff --git a/java/libraries/sound/src/processing/sound/Amplitude.java b/java/libraries/sound/src/processing/sound/Amplitude.java index 56c8f010c..40f864440 100644 --- a/java/libraries/sound/src/processing/sound/Amplitude.java +++ b/java/libraries/sound/src/processing/sound/Amplitude.java @@ -4,13 +4,14 @@ import processing.core.*; public class Amplitude { PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private long ptr; public Amplitude(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void input(SoundObject input){ diff --git a/java/libraries/sound/src/processing/sound/Sound.java b/java/libraries/sound/src/processing/sound/AudioDevice.java similarity index 55% rename from java/libraries/sound/src/processing/sound/Sound.java rename to java/libraries/sound/src/processing/sound/AudioDevice.java index aac05a198..fa4d66ad5 100644 --- a/java/libraries/sound/src/processing/sound/Sound.java +++ b/java/libraries/sound/src/processing/sound/AudioDevice.java @@ -18,47 +18,30 @@ * Boston, MA 02111-1307 USA * * @author ##Wilm Thoben## - * @modified ##10/23/2013## + * */ package processing.sound; -import processing.core.*; +import processing.core.PApplet; + + +public class AudioDevice { -public class Sound{ - - // myParent is a reference to the parent sketch PApplet parent; - MethClaInterface methCla; - - public final static String VERSION = "##library.prettyVersion##"; - - public Sound(PApplet parent, int sampleRate, int bufferSize) { - this.parent = parent; - parent.registerMethod("dispose", this); - welcome(); - methCla = new MethClaInterface(); - methCla.engineNew(sampleRate, bufferSize); - methCla.engineStart(); - } + static int m_test; + private Engine m_engine; - public Sound(PApplet theParent) { - this(theParent, 44100, 512); - } - - private void welcome() { - System.out.println("##library.name## ##library.prettyVersion## by ##author##"); - } + public AudioDevice(PApplet theParent, int sampleRate, int bufferSize) { + m_engine.setPreferences(theParent, bufferSize, sampleRate); + m_engine.start(); + } public void engineStop() { - methCla.engineStop(); - } - - public static String version() { - return VERSION; + m_engine.engineStop(); } public void dispose() { - methCla.engineStop(); + m_engine.engineStop(); } -} +} \ No newline at end of file diff --git a/java/libraries/sound/src/processing/sound/AudioIn.java b/java/libraries/sound/src/processing/sound/AudioIn.java index e1f231408..75b2e9e2e 100644 --- a/java/libraries/sound/src/processing/sound/AudioIn.java +++ b/java/libraries/sound/src/processing/sound/AudioIn.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class AudioIn { PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 0; private float m_amp = 0; @@ -15,8 +15,9 @@ public class AudioIn { public AudioIn(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void play(float freq, float amp, float add, float pos){ m_freq=freq; m_amp=amp; m_add=add; m_pos=pos; diff --git a/java/libraries/sound/src/processing/sound/BPF.java b/java/libraries/sound/src/processing/sound/BPF.java index d1ba09486..37d80f0f0 100644 --- a/java/libraries/sound/src/processing/sound/BPF.java +++ b/java/libraries/sound/src/processing/sound/BPF.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class BPF implements SoundObject{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int m_nodeId; private int[] m_m = {0,0}; private float m_freq = 100; @@ -14,8 +14,9 @@ public class BPF implements SoundObject{ public BPF(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void process(SoundObject input, float freq, float res){ m_freq=freq; m_res=res; diff --git a/java/libraries/sound/src/processing/sound/Delay.java b/java/libraries/sound/src/processing/sound/Delay.java index 653b79728..f2540f9a6 100644 --- a/java/libraries/sound/src/processing/sound/Delay.java +++ b/java/libraries/sound/src/processing/sound/Delay.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class Delay implements SoundObject{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int m_nodeId; private int[] m_m = {0,0}; private float m_maxDelayTime = 2; @@ -15,8 +15,9 @@ public class Delay implements SoundObject{ public Delay(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void process(SoundObject input, float maxDelayTime, float delayTime, float feedBack){ m_maxDelayTime=maxDelayTime; m_delayTime=delayTime; m_feedBack=feedBack; diff --git a/java/libraries/sound/src/processing/sound/Engine.java b/java/libraries/sound/src/processing/sound/Engine.java new file mode 100644 index 000000000..114d5579d --- /dev/null +++ b/java/libraries/sound/src/processing/sound/Engine.java @@ -0,0 +1,211 @@ +/** + * + * Copyright ##copyright## ##author## + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * @author ##Wilm Thoben## + * + */ + +package processing.sound; +import processing.core.PApplet; + +public class Engine { + + private static PApplet parent; + static MethClaInterface methCla; + private static int m_sampleRate=44100; + private static int m_bufferSize=512; + + private Engine() { + welcome(); + methCla = new MethClaInterface(); + methCla.engineNew(m_sampleRate, m_bufferSize); + methCla.engineStart(); + } + + private static class LazyHolder { + private static final Engine INSTANCE = new Engine(); + } + + public static Engine start() { + return LazyHolder.INSTANCE; + } + + public static void setPreferences(PApplet theParent, int bufferSize, int sampleRate){ + parent = theParent; + m_bufferSize = bufferSize; + m_sampleRate = sampleRate; + } + + // general Synth methods + public static void synthStop(int[] nodeId){ + methCla.synthStop(nodeId); + } + + // general Oscillator methods + + public static void oscSet(float freq, float amp, float add, float pos, int[] nodeId){ + methCla.oscSet(freq, amp, add, pos, nodeId); + }; + + // Sine Wave Oscillator + + public static int[] sinePlay(float freq, float amp, float add, float pos){ + return methCla.sinePlay(freq, amp, add, pos); + }; + + //Saw Wave Oscillator + + public static int[] sawPlay(float freq, float amp, float add, float pos){ + return methCla.sawPlay(freq, amp, add, pos); + }; + + //Square Wave Oscillator + + public static int[] sqrPlay(float freq, float amp, float add, float pos){ + return methCla.sqrPlay(freq, amp, add, pos); + }; + + public static void sqrSet(float freq, float amp, float add, float pos, int[] nodeId){ + methCla.sqrSet(freq, amp, add, pos, nodeId); + }; + + // Triangle Wave Oscillator + + public static int[] triPlay(float freq, float amp, float add, float pos){ + return methCla.triPlay(freq, amp, add, pos); + }; + + public static int[] pulsePlay(float freq, float width, float amp, float add, float pos){ + return methCla.pulsePlay(freq, width, amp, add, pos); + }; + + public static void pulseSet(float freq, float width, float amp, float add, float pos, int[] nodeId){ + methCla.pulseSet(freq, width, amp, add, pos, nodeId); + }; + + // SoundFile + + public static int[] soundFileInfo(String path){ + return methCla.soundFileInfo(path); + }; + + public static int[] soundFilePlayMono(float rate, float pos, float amp, float add, boolean loop, String path, float dur, int cue){ + return soundFilePlayMono(rate, pos, amp, add, loop, path, dur, cue); + }; + + public static int[] soundFilePlayMulti(float rate, float amp, float add, boolean loop, String path, float dur, int cue){ + return methCla.soundFilePlayMulti(rate, amp, add, loop, path, dur, cue); + }; + + public static void soundFileSetMono(float rate, float pos, float amp, float add, int[] nodeId){ + methCla.soundFileSetMono(rate, pos, amp, add, nodeId); + }; + + public static void soundFileSetStereo(float rate, float amp, float add, int[] nodeId){ + methCla.soundFileSetStereo(rate, amp, add, nodeId); + }; + + // Noise + + public static int[] whiteNoisePlay(float amp, float add, float pos){ + return methCla.whiteNoisePlay(amp, add, pos); + }; + + public static void whiteNoiseSet(float amp, float add, float pos, int[] nodeId){ + methCla.whiteNoiseSet(amp, add, pos, nodeId); + }; + + // Envelope + + public static int envelopePlay(int[] input, float attackTime, float sustainTime, float sustainLevel, float releaseTime){ + return methCla.envelopePlay(input, attackTime, sustainTime, sustainLevel, releaseTime); + }; + + public static int doneAfter(float seconds){ + return methCla.doneAfter(seconds); + }; + + // Filters + + public static int highPassPlay(int[] input, float freq, float res){ + return methCla.highPassPlay(input, freq, res); + }; + + public static int lowPassPlay(int[] input, float freq, float res){ + return methCla.lowPassPlay(input, freq, res); + }; + + public static int bandPassPlay(int[] input, float freq, float res){ + return methCla.bandPassPlay(input, freq, res); + }; + + public static void filterSet(float freq, float res, int nodeId){ + methCla.filterSet(freq, res, nodeId); + }; + + // Delay + + public static int delayPlay(int[] input, float maxDelayTime, float delayTime, float feedBack){ + return methCla.delayPlay(input, maxDelayTime, delayTime, feedBack); + }; + + public static void delaySet(float delayTime, float feedBack, int nodeId){ + methCla.delaySet(delayTime, feedBack, nodeId); + }; + + // Amplitude Follower + + public static long amplitude(int[] nodeId){ + return methCla.amplitude(nodeId); + }; + + public static float poll_amplitude(long ptr){ + return methCla.poll_amplitude(ptr); + }; + + public static void destroy_amplitude(long ptr){ + methCla.destroy_amplitude(ptr); + }; + + // FFT + + public static long fft(int[] nodeId, int fftSize){ + return methCla.fft(nodeId, fftSize); + }; + + public static float[] poll_fft(long ptr){ + return methCla.poll_fft(ptr); + }; + + public static void destroy_fft(long ptr){ + methCla.destroy_fft(ptr); + }; + + public static void engineStop() { + methCla.engineStop(); + } + + public void dispose() { + methCla.engineStop(); + } + + private void welcome() { + System.out.println("processing.sound v.09 by Wilm Thoben"); + } +} \ No newline at end of file diff --git a/java/libraries/sound/src/processing/sound/Env.java b/java/libraries/sound/src/processing/sound/Env.java index 9e72f2c10..3f0533cdd 100644 --- a/java/libraries/sound/src/processing/sound/Env.java +++ b/java/libraries/sound/src/processing/sound/Env.java @@ -4,14 +4,15 @@ import processing.core.*; public class Env { PApplet parent; - MethClaInterface m_engine; + private Engine m_engine; int m_nodeId; public Env (PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void play(SoundObject input, float attackTime, float sustainTime, float sustainLevel, float releaseTime){ m_nodeId = m_engine.envelopePlay(input.returnId(), attackTime, sustainTime, sustainLevel, releaseTime); diff --git a/java/libraries/sound/src/processing/sound/FFT.java b/java/libraries/sound/src/processing/sound/FFT.java index cbf5baa30..30d1df8e4 100644 --- a/java/libraries/sound/src/processing/sound/FFT.java +++ b/java/libraries/sound/src/processing/sound/FFT.java @@ -4,14 +4,15 @@ import processing.core.*; public class FFT { PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private long ptr; public FFT(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void input(SoundObject input, int fftSize){ ptr = m_engine.fft(input.returnId(), fftSize); diff --git a/java/libraries/sound/src/processing/sound/HPF.java b/java/libraries/sound/src/processing/sound/HPF.java index 179990392..d0bdc9161 100644 --- a/java/libraries/sound/src/processing/sound/HPF.java +++ b/java/libraries/sound/src/processing/sound/HPF.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class HPF implements SoundObject{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int m_nodeId; private int[] m_m = {0,0}; private float m_freq = 100; @@ -14,8 +14,9 @@ public class HPF implements SoundObject{ public HPF(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void process(SoundObject input, float freq, float res){ m_freq=freq; m_res=res; diff --git a/java/libraries/sound/src/processing/sound/LPF.java b/java/libraries/sound/src/processing/sound/LPF.java index 7476cb031..89140a7b0 100644 --- a/java/libraries/sound/src/processing/sound/LPF.java +++ b/java/libraries/sound/src/processing/sound/LPF.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class LPF implements SoundObject{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int m_nodeId; private int[] m_m = {0,0}; private float m_freq = 100; @@ -14,8 +14,9 @@ public class LPF implements SoundObject{ public LPF(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void process(SoundObject input, float freq, float res){ m_freq=freq; m_res=res; diff --git a/java/libraries/sound/src/processing/sound/Pulse.java b/java/libraries/sound/src/processing/sound/Pulse.java index 2fed96f46..4a19214cd 100644 --- a/java/libraries/sound/src/processing/sound/Pulse.java +++ b/java/libraries/sound/src/processing/sound/Pulse.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class Pulse implements SoundObject { PApplet parent; - MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 440; private float m_width = 0.5f; @@ -16,8 +16,9 @@ public class Pulse implements SoundObject { public Pulse(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); - } + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } public void play(){ m_nodeId = m_engine.pulsePlay(m_freq, m_width, m_amp, m_add, m_pos); diff --git a/java/libraries/sound/src/processing/sound/SawOsc.java b/java/libraries/sound/src/processing/sound/SawOsc.java index 387e9ecf2..365580a3a 100644 --- a/java/libraries/sound/src/processing/sound/SawOsc.java +++ b/java/libraries/sound/src/processing/sound/SawOsc.java @@ -1,11 +1,10 @@ package processing.sound; - -import processing.core.PApplet; +import processing.core.*; public class SawOsc implements Oscillator{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 440; private float m_amp = 0.5f; @@ -15,7 +14,8 @@ public class SawOsc implements Oscillator{ public SawOsc(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void play(float freq, float amp, float add, float pos){ diff --git a/java/libraries/sound/src/processing/sound/SinOsc.java b/java/libraries/sound/src/processing/sound/SinOsc.java index 7bf8a1134..218eff1ec 100644 --- a/java/libraries/sound/src/processing/sound/SinOsc.java +++ b/java/libraries/sound/src/processing/sound/SinOsc.java @@ -4,7 +4,7 @@ import processing.core.*; public class SinOsc implements Oscillator { PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 440; private float m_amp = 0.5f; @@ -14,7 +14,8 @@ public class SinOsc implements Oscillator { public SinOsc(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void play(float freq, float amp, float add, float pos){ diff --git a/java/libraries/sound/src/processing/sound/SoundFile.java b/java/libraries/sound/src/processing/sound/SoundFile.java index dcd33fbf4..d88b9d46c 100644 --- a/java/libraries/sound/src/processing/sound/SoundFile.java +++ b/java/libraries/sound/src/processing/sound/SoundFile.java @@ -4,7 +4,8 @@ import processing.core.*; public class SoundFile implements SoundObject { PApplet parent; - MethClaInterface m_engine; + private Engine m_engine; + private MethClaInterface methCla; private int[] m_nodeId = {-1,-1}; int[] m_info; String m_filePath; @@ -18,8 +19,9 @@ public class SoundFile implements SoundObject { public SoundFile(PApplet theParent, String path) { this.parent = theParent; parent.registerMethod("dispose", this); - - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + methCla = new MethClaInterface(); m_filePath=theParent.dataPath(path); m_info = m_engine.soundFileInfo(m_filePath); } @@ -41,11 +43,11 @@ public class SoundFile implements SoundObject { } public void play(){ - if(this.channels() < 2){ - m_nodeId = m_engine.soundFilePlayMono(m_rate, m_pos, m_amp, m_add, false, m_filePath, this.duration()*(1/m_rate), m_cue); + if(this.channels() == 1){ + m_nodeId = methCla.soundFilePlayMono(m_rate, m_pos, m_amp, m_add, false, m_filePath, this.duration()*(1/m_rate), m_cue); } else if(this.channels() == 2){ - m_nodeId = m_engine.soundFilePlayMulti(m_rate, m_amp, m_add, false, m_filePath, this.duration()*(1/m_rate), m_cue); + m_nodeId = methCla.soundFilePlayMulti(m_rate, m_amp, m_add, false, m_filePath, this.duration()*(1/m_rate), m_cue); } } @@ -76,10 +78,10 @@ public class SoundFile implements SoundObject { public void loop(){ if(this.channels() < 2){ - m_nodeId = m_engine.soundFilePlayMono(m_rate, m_pos, m_amp, m_add, true, m_filePath, this.duration()*(1/m_rate), m_cue); + m_nodeId = methCla.soundFilePlayMono(m_rate, m_pos, m_amp, m_add, true, m_filePath, this.duration()*(1/m_rate), m_cue); } else if(this.channels() == 2){ - m_nodeId = m_engine.soundFilePlayMulti(m_rate, m_amp, m_add, true, m_filePath, this.duration()*(1/m_rate), m_cue); + m_nodeId = methCla.soundFilePlayMulti(m_rate, m_amp, m_add, true, m_filePath, this.duration()*(1/m_rate), m_cue); } } diff --git a/java/libraries/sound/src/processing/sound/SqrOsc.java b/java/libraries/sound/src/processing/sound/SqrOsc.java index ec370208b..68d56e5b3 100644 --- a/java/libraries/sound/src/processing/sound/SqrOsc.java +++ b/java/libraries/sound/src/processing/sound/SqrOsc.java @@ -5,7 +5,7 @@ import processing.core.PApplet; public class SqrOsc implements SoundObject { PApplet parent; - MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 440; private float m_amp = 0.5f; @@ -15,7 +15,8 @@ public class SqrOsc implements SoundObject { public SqrOsc(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void play(){ diff --git a/java/libraries/sound/src/processing/sound/TriOsc.java b/java/libraries/sound/src/processing/sound/TriOsc.java index 90ba239f4..7e0c3ecdc 100644 --- a/java/libraries/sound/src/processing/sound/TriOsc.java +++ b/java/libraries/sound/src/processing/sound/TriOsc.java @@ -1,11 +1,10 @@ package processing.sound; - import processing.core.PApplet; public class TriOsc implements Oscillator{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 440; private float m_amp = 0.5f; @@ -15,7 +14,8 @@ public class TriOsc implements Oscillator{ public TriOsc(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void play(float freq, float amp, float add, float pos){ diff --git a/java/libraries/sound/src/processing/sound/WhiteNoise.java b/java/libraries/sound/src/processing/sound/WhiteNoise.java index 7757bc04a..4143b5399 100644 --- a/java/libraries/sound/src/processing/sound/WhiteNoise.java +++ b/java/libraries/sound/src/processing/sound/WhiteNoise.java @@ -4,7 +4,7 @@ import processing.core.*; public class WhiteNoise implements SoundObject{ PApplet parent; - private MethClaInterface m_engine; + private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_amp=0.5f; private float m_add=0; @@ -13,7 +13,8 @@ public class WhiteNoise implements SoundObject{ public WhiteNoise(PApplet theParent) { this.parent = theParent; parent.registerMethod("dispose", this); - m_engine = new MethClaInterface(); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); } public void play(){