From 4a60bfbfd2e9a06273acff09debbcf1dc1d77ea0 Mon Sep 17 00:00:00 2001 From: wirsing Date: Fri, 25 Jul 2014 20:10:33 -0700 Subject: [PATCH] repaired Filter + took out res + introduced Bandwidth for BPass. fixed some public/private bugs --- .../sound/examples/Effects/Filter/BPF/BPF.pde | 11 ++-- .../sound/examples/Effects/Filter/HPF/HPF.pde | 3 +- .../sound/examples/Effects/Filter/LPF/LPF.pde | 8 +-- java/libraries/sound/src/cpp/Makefile | 1 + .../src/cpp/include/methcla/plugins/bpf.h | 25 +++++++++ .../processing_sound_MethClaInterface.h | 18 +++++-- .../cpp/processing_sound_MethClaInterface.cpp | 52 +++++++++++-------- .../sound/src/processing/sound/BandPass.java | 26 ++++++---- .../sound/src/processing/sound/Engine.java | 20 ++++--- .../sound/src/processing/sound/HighPass.java | 23 +++----- .../sound/src/processing/sound/LowPass.java | 23 +++----- .../processing/sound/MethClaInterface.java | 11 ++-- .../sound/src/processing/sound/Mix.java | 42 +++++++++++++++ .../sound/src/processing/sound/Noise.java | 1 - .../src/processing/sound/Oscillator.java | 1 - java/libraries/sound/todo.txt | 11 ++-- 16 files changed, 180 insertions(+), 96 deletions(-) create mode 100644 java/libraries/sound/src/cpp/include/methcla/plugins/bpf.h create mode 100644 java/libraries/sound/src/processing/sound/Mix.java diff --git a/java/libraries/sound/examples/Effects/Filter/BPF/BPF.pde b/java/libraries/sound/examples/Effects/Filter/BPF/BPF.pde index cac2334ec..30a1f0746 100644 --- a/java/libraries/sound/examples/Effects/Filter/BPF/BPF.pde +++ b/java/libraries/sound/examples/Effects/Filter/BPF/BPF.pde @@ -6,7 +6,7 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; WhiteNoise noise; -BandPass bPass; +BandPass bandPass; float amp=0.0; @@ -16,14 +16,15 @@ void setup() { // Create the noise generator + Filter noise = new WhiteNoise(this); - bPass = new BandPass(this); + bandPass = new BandPass(this); + noise.play(0.5); - bPass.process(noise, 100); + bandPass.process(noise, 100); } void draw() { - bPass.freq(map(mouseX, 0, 350, 20, 10000)); + bandPass.freq(map(mouseX, 0, width, 20, 10000)); - bPass.res(map(mouseY, 0, 350, 0.05, 1.0)); + bandPass.bw(map(mouseY, 0, height, 100, 1000)); } diff --git a/java/libraries/sound/examples/Effects/Filter/HPF/HPF.pde b/java/libraries/sound/examples/Effects/Filter/HPF/HPF.pde index 0ea52b2ae..d4a82cac9 100644 --- a/java/libraries/sound/examples/Effects/Filter/HPF/HPF.pde +++ b/java/libraries/sound/examples/Effects/Filter/HPF/HPF.pde @@ -17,10 +17,11 @@ void setup() { // Create the noise generator + filter noise = new WhiteNoise(this); highPass = new HighPass(this); + noise.play(0.5); highPass.process(noise, 100); } void draw() { - highPass.freq(map(mouseX, 0, 350, 20, 10000)); + highPass.freq(map(mouseX, 0, width, 80, 10000)); } diff --git a/java/libraries/sound/examples/Effects/Filter/LPF/LPF.pde b/java/libraries/sound/examples/Effects/Filter/LPF/LPF.pde index ab866be0c..070b280ed 100644 --- a/java/libraries/sound/examples/Effects/Filter/LPF/LPF.pde +++ b/java/libraries/sound/examples/Effects/Filter/LPF/LPF.pde @@ -6,7 +6,7 @@ In this example it is started and stopped by clicking into the renderer window. import processing.sound.*; WhiteNoise noise; -LowPass lPass; +LowPass lowPass; float amp=0.0; @@ -16,11 +16,11 @@ void setup() { // Create the noise generator + filter noise = new WhiteNoise(this); - lPass = new LowPass(this); + lowPass = new LowPass(this); noise.play(0.2); - lPass.process(noise, 800); + lowPass.process(noise, 800); } void draw() { - lPass.freq(map(mouseX, 0, 350, 800, 10000)); + lowPass.freq(map(mouseX, 0, width, 80, 10000)); } diff --git a/java/libraries/sound/src/cpp/Makefile b/java/libraries/sound/src/cpp/Makefile index 7ac3036da..7e866267d 100644 --- a/java/libraries/sound/src/cpp/Makefile +++ b/java/libraries/sound/src/cpp/Makefile @@ -8,3 +8,4 @@ clean: install: cp libMethClaInterface.jnilib ../../library/macosx + cp libMethClaInterface.jnilib /Users/wirsing/Documents/Processing/libraries/sound/library/macosx/ diff --git a/java/libraries/sound/src/cpp/include/methcla/plugins/bpf.h b/java/libraries/sound/src/cpp/include/methcla/plugins/bpf.h new file mode 100644 index 000000000..c58b8931c --- /dev/null +++ b/java/libraries/sound/src/cpp/include/methcla/plugins/bpf.h @@ -0,0 +1,25 @@ +/* + Copyright 2012-2013 Samplecount S.L. + + 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. +*/ + +#ifndef METHCLA_PLUGINS_BPF_H_INCLUDED +#define METHCLA_PLUGINS_BPF_H_INCLUDED + +#include + +METHCLA_EXPORT const Methcla_Library* methcla_plugins_bpf(const Methcla_Host*, const char*); +#define METHCLA_PLUGINS_BPF_URI METHCLA_PLUGINS_URI "/bpf" + +#endif /* METHCLA_PLUGINS_BPF_H_INCLUDED */ diff --git a/java/libraries/sound/src/cpp/include/processing_sound_MethClaInterface.h b/java/libraries/sound/src/cpp/include/processing_sound_MethClaInterface.h index 5fcfdd911..de571b3a0 100644 --- a/java/libraries/sound/src/cpp/include/processing_sound_MethClaInterface.h +++ b/java/libraries/sound/src/cpp/include/processing_sound_MethClaInterface.h @@ -234,18 +234,18 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_doneAfter /* * Class: processing_sound_MethClaInterface * Method: highPassPlay - * Signature: ([IFF)[I + * Signature: ([IF)[I */ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_highPassPlay - (JNIEnv *, jobject, jintArray, jfloat, jfloat); + (JNIEnv *, jobject, jintArray, jfloat); /* * Class: processing_sound_MethClaInterface * Method: lowPassPlay - * Signature: ([IFF)[I + * Signature: ([IF)[I */ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_lowPassPlay - (JNIEnv *, jobject, jintArray, jfloat, jfloat); + (JNIEnv *, jobject, jintArray, jfloat); /* * Class: processing_sound_MethClaInterface @@ -258,9 +258,17 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_bandPassPlay /* * Class: processing_sound_MethClaInterface * Method: filterSet - * Signature: (FFI)V + * Signature: (FI)V */ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_filterSet + (JNIEnv *, jobject, jfloat, jint); + +/* + * Class: processing_sound_MethClaInterface + * Method: filterBwSet + * Signature: (FFI)V + */ +JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_filterBwSet (JNIEnv *, jobject, jfloat, jfloat, jint); /* diff --git a/java/libraries/sound/src/cpp/processing_sound_MethClaInterface.cpp b/java/libraries/sound/src/cpp/processing_sound_MethClaInterface.cpp index 47a0dc166..796bb8593 100644 --- a/java/libraries/sound/src/cpp/processing_sound_MethClaInterface.cpp +++ b/java/libraries/sound/src/cpp/processing_sound_MethClaInterface.cpp @@ -27,6 +27,7 @@ #include "methcla/plugins/fft.h" #include "methcla/plugins/hpf.h" #include "methcla/plugins/lpf.h" +#include "methcla/plugins/bpf.h" #include "methcla/plugins/delay.h" #include "methcla/plugins/reverb.h" #include "methcla/plugins/audio_in.h" @@ -50,9 +51,7 @@ struct ServerValue{ ServerValue() : amp(0), id(-1) - { - - } + {} float amp; int id; }; @@ -62,9 +61,7 @@ struct ServerArray{ fftSize(512), fft(fftSize), id(-1) - { - - } + {} int fftSize; std::vector fft; int id; @@ -93,7 +90,8 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_engineNew (JNIEnv .addLibrary(methcla_plugins_pan2) .addLibrary(methcla_plugins_amplitude_follower) .addLibrary(methcla_plugins_hpf) - .addLibrary(methcla_plugins_lpf) + .addLibrary(methcla_plugins_lpf) + .addLibrary(methcla_plugins_bpf) .addLibrary(methcla_plugins_delay) .addLibrary(methcla_plugins_reverb) .addLibrary(methcla_plugins_fft) @@ -170,8 +168,8 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_oscAudioSet(JNIEnv if (m_freq[0] != -1) { Methcla::AudioBusId freq_bus = m_engine->audioBusId().alloc(); - request.set(m_nodeId[0], 0 , 0); - request.free(m_freq[1]); + //request.set(m_nodeId[0], 0 , 0); + //request.free(m_freq[1]); request.mapOutput(m_freq[0], 0, freq_bus); request.mapInput(m_nodeId[0], 0, freq_bus); @@ -179,15 +177,12 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_oscAudioSet(JNIEnv } if (m_amp[0] != -1) - { + { Methcla::AudioBusId amp_bus = m_engine->audioBusId().alloc(); //request.set(m_nodeId[0], 1 , 0); //request.free(m_amp[1]); request.mapOutput(m_amp[0], 0, amp_bus); - std::cout << m_amp[0] << std::endl; - request.set(m_amp[0], 0, 200); - request.mapInput(m_nodeId[0], 1, amp_bus); std::cout << "amp" << std::endl; @@ -272,7 +267,6 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_sinePlay(JNIE }; JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_sawPlay(JNIEnv *env, jobject object, jfloat freq, jfloat amp, jfloat add, jfloat pos){ - jintArray nodeId = env->NewIntArray(2); jint *m_nodeId = env->GetIntArrayElements(nodeId, NULL); @@ -293,6 +287,9 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_sawPlay(JNIEn {Methcla::Value(1.f)} ); + engine().addNotificationHandler(engine().freeNodeIdHandler(synth.id())); + engine().addNotificationHandler(engine().freeNodeIdHandler(pan.id())); + request.mapOutput(synth.id(), 0, bus); request.mapInput(pan.id(), 0, bus); request.mapOutput(pan.id(), 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal); @@ -910,7 +907,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_envelopePlay( return returnId; }; -JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_highPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq, jfloat res){ +JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_highPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq){ jint* m_nodeId = env->GetIntArrayElements(nodeId, 0); jintArray returnId = env->NewIntArray(2); @@ -924,7 +921,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_highPassPlay( auto synth = request.synth( METHCLA_PLUGINS_HPF_URI, Methcla::NodePlacement::after(m_nodeId[0]), - {freq, res}, + {freq}, {} ); @@ -947,7 +944,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_highPassPlay( return returnId; }; -JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_lowPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq, jfloat res){ +JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_lowPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq){ jint* m_nodeId = env->GetIntArrayElements(nodeId, 0); jintArray returnId = env->NewIntArray(2); @@ -961,7 +958,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_lowPassPlay(J auto synth = request.synth( METHCLA_PLUGINS_LPF_URI, Methcla::NodePlacement::after(m_nodeId[0]), - {freq, res}, + {freq}, {} ); @@ -984,7 +981,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_lowPassPlay(J return returnId; }; -JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_bandPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq, jfloat res){ +JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_bandPassPlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat freq, jfloat bw){ jint* m_nodeId = env->GetIntArrayElements(nodeId, 0); jintArray returnId = env->NewIntArray(2); @@ -996,9 +993,9 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_bandPassPlay( Methcla::Request request(engine()); request.openBundle(Methcla::immediately); auto synth = request.synth( - METHCLA_PLUGINS_HPF_URI, + METHCLA_PLUGINS_BPF_URI, Methcla::NodePlacement::after(m_nodeId[0]), - {freq, res}, + {freq, bw}, {} ); @@ -1021,12 +1018,21 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_bandPassPlay( return returnId; }; -JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_filterSet(JNIEnv *env, jobject object, jfloat freq, jfloat res, jint nodeId){ +JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_filterSet(JNIEnv *env, jobject object, jfloat freq, jint nodeId){ Methcla::Request request(engine()); request.openBundle(Methcla::immediately); request.set(nodeId, 0, freq); - request.set(nodeId, 1, res); + request.closeBundle(); + request.send(); +}; + +JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_filterBwSet(JNIEnv *env, jobject object, jfloat freq, jfloat bw, jint nodeId){ + + Methcla::Request request(engine()); + request.openBundle(Methcla::immediately); + request.set(nodeId, 0, freq); + request.set(nodeId, 1, bw); request.closeBundle(); request.send(); }; diff --git a/java/libraries/sound/src/processing/sound/BandPass.java b/java/libraries/sound/src/processing/sound/BandPass.java index 6fac50289..91d173f47 100644 --- a/java/libraries/sound/src/processing/sound/BandPass.java +++ b/java/libraries/sound/src/processing/sound/BandPass.java @@ -7,8 +7,8 @@ public class BandPass implements SoundObject{ PApplet parent; private Engine m_engine; private int[] m_nodeId = {-1,-1}; - private float m_freq = 100; - private float m_res = 1; + private float m_freq = 4000; + private float m_bw = 1000; public BandPass(PApplet theParent) { this.parent = theParent; @@ -17,22 +17,26 @@ public class BandPass implements SoundObject{ m_engine.start(); } - public void process(SoundObject input, float freq, float res){ - m_freq=freq; m_res=res; - m_nodeId = m_engine.bandPassPlay(input.returnId(), m_freq, m_res); + public void process(SoundObject input, float freq, float bw){ + m_freq=freq; m_bw=bw; + m_nodeId = m_engine.bandPassPlay(input.returnId(), m_freq, m_bw); } public void process(SoundObject input, float freq){ m_freq=freq; - m_nodeId = m_engine.bandPassPlay(input.returnId(), m_freq, m_res); + m_nodeId = m_engine.bandPassPlay(input.returnId(), m_freq, m_bw); } + public void process(SoundObject input){ + m_nodeId = m_engine.bandPassPlay(input.returnId(), m_freq, m_bw); + } + private void set(){ - m_engine.filterSet(m_freq, m_res, m_nodeId[0]); + m_engine.filterBwSet(m_freq, m_bw, m_nodeId[0]); } - public void set(float freq, float res){ - m_freq=freq; m_res=res; + public void set(float freq, float bw){ + m_freq=freq; m_bw=bw; this.set(); } @@ -41,8 +45,8 @@ public class BandPass implements SoundObject{ this.set(); } - public void res(float res){ - m_res=res; + public void bw(float bw){ + m_bw=bw; this.set(); } diff --git a/java/libraries/sound/src/processing/sound/Engine.java b/java/libraries/sound/src/processing/sound/Engine.java index 7052996b6..51a04a40f 100644 --- a/java/libraries/sound/src/processing/sound/Engine.java +++ b/java/libraries/sound/src/processing/sound/Engine.java @@ -177,20 +177,24 @@ public class Engine { // Filters - public static int[] highPassPlay(int[] input, float freq, float res){ - return methCla.highPassPlay(input, freq, res); + public static int[] highPassPlay(int[] input, float freq){ + return methCla.highPassPlay(input, freq); }; - public static int[] lowPassPlay(int[] input, float freq, float res){ - return methCla.lowPassPlay(input, freq, res); + public static int[] lowPassPlay(int[] input, float freq){ + return methCla.lowPassPlay(input, freq); }; - public static int[] bandPassPlay(int[] input, float freq, float res){ - return methCla.bandPassPlay(input, freq, res); + public static int[] bandPassPlay(int[] input, float freq, float bw){ + return methCla.bandPassPlay(input, freq, bw); }; - public static void filterSet(float freq, float res, int nodeId){ - methCla.filterSet(freq, res, nodeId); + public static void filterSet(float freq, int nodeId){ + methCla.filterSet(freq, nodeId); + }; + + public static void filterBwSet(float freq, float bw, int nodeId){ + methCla.filterBwSet(freq, bw, nodeId); }; // Delay diff --git a/java/libraries/sound/src/processing/sound/HighPass.java b/java/libraries/sound/src/processing/sound/HighPass.java index 2574f04b0..01e23f120 100644 --- a/java/libraries/sound/src/processing/sound/HighPass.java +++ b/java/libraries/sound/src/processing/sound/HighPass.java @@ -8,7 +8,6 @@ public class HighPass implements SoundObject{ private Engine m_engine; private int[] m_nodeId = {-1,-1}; private float m_freq = 100; - private float m_res = 1; public HighPass(PApplet theParent) { this.parent = theParent; @@ -17,22 +16,21 @@ public class HighPass implements SoundObject{ m_engine.start(); } - public void process(SoundObject input, float freq, float res){ - m_freq=freq; m_res=res; - m_nodeId = m_engine.highPassPlay(input.returnId(), m_freq, m_res); - } - public void process(SoundObject input, float freq){ m_freq=freq; - m_nodeId = m_engine.highPassPlay(input.returnId(), m_freq, m_res); + m_nodeId = m_engine.highPassPlay(input.returnId(), m_freq); } + public void process(SoundObject input){ + m_nodeId = m_engine.highPassPlay(input.returnId(), m_freq); + } + private void set(){ - m_engine.filterSet(m_freq, m_res, m_nodeId[0]); + m_engine.filterSet(m_freq, m_nodeId[0]); } - public void set(float freq, float res){ - m_freq=freq; m_res=res; + public void set(float freq){ + m_freq=freq; this.set(); } @@ -40,11 +38,6 @@ public class HighPass implements SoundObject{ m_freq=freq; this.set(); } - - public void res(float res){ - m_res=res; - this.set(); - } public int[] returnId(){ return m_nodeId; diff --git a/java/libraries/sound/src/processing/sound/LowPass.java b/java/libraries/sound/src/processing/sound/LowPass.java index bcb889e20..5f2a17a3d 100644 --- a/java/libraries/sound/src/processing/sound/LowPass.java +++ b/java/libraries/sound/src/processing/sound/LowPass.java @@ -8,7 +8,6 @@ public class LowPass implements SoundObject{ private Engine m_engine; private int[] m_nodeId = {-1, -1}; private float m_freq = 100; - private float m_res = 1; public LowPass(PApplet theParent) { this.parent = theParent; @@ -17,22 +16,21 @@ public class LowPass implements SoundObject{ m_engine.start(); } - public void process(SoundObject input, float freq, float res){ - m_freq=freq; m_res=res; - m_nodeId = m_engine.lowPassPlay(input.returnId(), m_freq, m_res); - } - public void process(SoundObject input, float freq){ m_freq=freq; - m_nodeId = m_engine.lowPassPlay(input.returnId(), m_freq, m_res); + m_nodeId = m_engine.lowPassPlay(input.returnId(), m_freq); + } + + public void process(SoundObject input){ + m_nodeId = m_engine.lowPassPlay(input.returnId(), m_freq); } private void set(){ - m_engine.filterSet(m_freq, m_res, m_nodeId[0]); + m_engine.filterSet(m_freq, m_nodeId[0]); } - public void set(float freq, float res){ - m_freq=freq; m_res=res; + public void set(float freq){ + m_freq=freq; this.set(); } @@ -41,11 +39,6 @@ public class LowPass implements SoundObject{ this.set(); } - public void res(float res){ - m_res=res; - this.set(); - } - public int[] returnId(){ return m_nodeId; } diff --git a/java/libraries/sound/src/processing/sound/MethClaInterface.java b/java/libraries/sound/src/processing/sound/MethClaInterface.java index 51e5078f9..bb1a7d4c7 100644 --- a/java/libraries/sound/src/processing/sound/MethClaInterface.java +++ b/java/libraries/sound/src/processing/sound/MethClaInterface.java @@ -94,13 +94,16 @@ public class MethClaInterface // Filters - public native int[] highPassPlay(int[] input, float freq, float res); + public native int[] highPassPlay(int[] input, float freq); - public native int[] lowPassPlay(int[] input, float freq, float res); + public native int[] lowPassPlay(int[] input, float freq); - public native int[] bandPassPlay(int[] input, float freq, float res); + public native int[] bandPassPlay(int[] input, float freq, float bw); + + public native void filterSet(float freq, int nodeId); + + public native void filterBwSet(float freq, float bw, int nodeId); - public native void filterSet(float freq, float res, int nodeId); // Delay diff --git a/java/libraries/sound/src/processing/sound/Mix.java b/java/libraries/sound/src/processing/sound/Mix.java new file mode 100644 index 000000000..1cc9e5a69 --- /dev/null +++ b/java/libraries/sound/src/processing/sound/Mix.java @@ -0,0 +1,42 @@ +package processing.sound; + +import processing.core.PApplet; + +public class Mix implements SoundObject{ + + PApplet parent; + private Engine m_engine; + private int m_nodeId[] = {-1,-1}; + private int[] m_nodeInIds; + private float[] m_amps; + + public Mix(PApplet theParent) { + this.parent = theParent; + parent.registerMethod("dispose", this); + m_engine.setPreferences(theParent, 512, 44100); + m_engine.start(); + } + + public void play(SoundObject[] input, float[] amps){ + m_amps=amps; + for (int i=0; i