mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
AudioInput works now
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Be Careful with your speaker volume, you might produce a painful
|
||||
feedback. We recommend to wear headphones for this example.
|
||||
|
||||
*/
|
||||
|
||||
import processing.sound.*;
|
||||
|
||||
AudioIn input;
|
||||
Amplitude rms;
|
||||
|
||||
int scale=1;
|
||||
|
||||
void setup() {
|
||||
size(640,360);
|
||||
background(255);
|
||||
|
||||
//Create an Audio input and grab the 1st channel
|
||||
input = new AudioIn(this, 0);
|
||||
|
||||
// start the Audio Input
|
||||
input.play();
|
||||
|
||||
// create a new Amplitude analyzer
|
||||
rms = new Amplitude(this);
|
||||
|
||||
// Patch the input to an volume analyzer
|
||||
rms.input(input);
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(125,255,125);
|
||||
|
||||
// adjust the volume of the audio input
|
||||
input.amp(map(mouseY, 0, height, 0.0, 1.0));
|
||||
|
||||
// rms.analyze() return a value between 0 and 1. To adjust
|
||||
// the scaling and mapping of an ellipse we scale from 0 to 0.5
|
||||
scale=int(map(rms.analyze(), 0, 0.5, 1, 350));
|
||||
noStroke();
|
||||
|
||||
fill(255,0,150);
|
||||
// We draw an ellispe coupled to the audio analysis
|
||||
ellipse(width/2, height/2, 1*scale, 1*scale);
|
||||
}
|
||||
@@ -114,10 +114,10 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pulseSet
|
||||
/*
|
||||
* Class: processing_sound_MethClaInterface
|
||||
* Method: audioInPlay
|
||||
* Signature: (FFFZ)[I
|
||||
* Signature: (FFFI)[I
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay
|
||||
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jboolean);
|
||||
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jint);
|
||||
|
||||
/*
|
||||
* Class: processing_sound_MethClaInterface
|
||||
@@ -295,6 +295,14 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_reverbPlay
|
||||
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_reverbSet
|
||||
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jint);
|
||||
|
||||
/*
|
||||
* Class: processing_sound_MethClaInterface
|
||||
* Method: out
|
||||
* Signature: (I[I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_out
|
||||
(JNIEnv *, jobject, jint, jintArray);
|
||||
|
||||
/*
|
||||
* Class: processing_sound_MethClaInterface
|
||||
* Method: amplitude
|
||||
|
||||
@@ -451,13 +451,12 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pulseSet(JNIEnv *e
|
||||
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
|
||||
};
|
||||
|
||||
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos, jboolean out){
|
||||
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos, jint in){
|
||||
|
||||
jintArray nodeId = env->NewIntArray(2);
|
||||
jint *m_nodeId = env->GetIntArrayElements(nodeId, NULL);
|
||||
|
||||
Methcla::AudioBusId bus = m_engine->audioBusId().alloc();
|
||||
Methcla::AudioBusId in = m_engine->audioBusId().alloc();
|
||||
|
||||
Methcla::Request request(engine());
|
||||
request.openBundle(Methcla::immediately);
|
||||
@@ -471,11 +470,11 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay(J
|
||||
auto pan = request.synth(
|
||||
METHCLA_PLUGINS_PAN2_URI,
|
||||
engine().root(),
|
||||
{pos, 0},
|
||||
{pos, 1.f},
|
||||
{Methcla::Value(1.f)}
|
||||
);
|
||||
|
||||
request.mapInput(synth.id(), 0, in, Methcla::kBusMappingExternal);
|
||||
request.mapInput(synth.id(), 0, Methcla::AudioBusId(in), Methcla::kBusMappingExternal);
|
||||
request.mapOutput(synth.id(), 0, bus);
|
||||
request.mapInput(pan.id(), 0, bus);
|
||||
|
||||
@@ -490,7 +489,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay(J
|
||||
request.send();
|
||||
|
||||
m_nodeId[0]=synth.id();
|
||||
m_nodeId[1]=pan.id();
|
||||
m_nodeId[1]= pan.id();
|
||||
|
||||
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
|
||||
|
||||
@@ -1027,6 +1026,7 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_delayPlay(JNI
|
||||
|
||||
Methcla::Request request(engine());
|
||||
request.openBundle(Methcla::immediately);
|
||||
|
||||
auto synth = request.synth(
|
||||
METHCLA_PLUGINS_DELAY_URI,
|
||||
Methcla::NodePlacement::after(m_nodeId[0]),
|
||||
@@ -1053,7 +1053,6 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_delayPlay(JNI
|
||||
return returnId;
|
||||
};
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_delaySet(JNIEnv *env, jobject object, jfloat delayTime, jfloat feedBack, jint nodeId){
|
||||
Methcla::Request request(engine());
|
||||
request.openBundle(Methcla::immediately);
|
||||
@@ -1293,3 +1292,18 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_out(JNIEnv *env, j
|
||||
};
|
||||
*/
|
||||
|
||||
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_out(JNIEnv *env, jobject object, jint out, jintArray nodeId){
|
||||
|
||||
jint* m_nodeId = env->GetIntArrayElements(nodeId, 0);
|
||||
|
||||
Methcla::Request request(engine());
|
||||
request.openBundle(Methcla::immediately);
|
||||
|
||||
request.mapOutput(m_nodeId[0], 0, Methcla::AudioBusId(out), Methcla::kBusMappingExternal);
|
||||
|
||||
request.closeBundle();
|
||||
request.send();
|
||||
|
||||
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,25 +2,26 @@ package processing.sound;
|
||||
|
||||
import processing.core.PApplet;
|
||||
|
||||
public class AudioIn {
|
||||
public class AudioIn implements SoundObject{
|
||||
|
||||
PApplet parent;
|
||||
private Engine m_engine;
|
||||
private int[] m_nodeId = {-1,-1};
|
||||
private float m_amp = 1.f;
|
||||
private float m_add = 0;
|
||||
private boolean m_out = true;
|
||||
private int m_in = 0;
|
||||
private float m_pos = 0;
|
||||
|
||||
public AudioIn(PApplet theParent) {
|
||||
public AudioIn (PApplet theParent, int in) {
|
||||
this.parent = theParent;
|
||||
parent.registerMethod("dispose", this);
|
||||
m_engine.setPreferences(theParent, 512, 44100);
|
||||
m_engine.start();
|
||||
m_in = in;
|
||||
}
|
||||
|
||||
public void play(){
|
||||
m_nodeId = m_engine.audioInPlay(m_amp, m_add, m_pos, m_out);
|
||||
m_nodeId = m_engine.audioInPlay(m_amp, m_add, m_pos, m_in);
|
||||
}
|
||||
|
||||
public void play(float amp, float add, float pos){
|
||||
|
||||
@@ -105,8 +105,8 @@ public class Engine {
|
||||
|
||||
// AudioIn
|
||||
|
||||
public static int[] audioInPlay(float amp, float add, float pos, boolean out){
|
||||
return methCla.audioInPlay(amp, add, pos, out);
|
||||
public static int[] audioInPlay(float amp, float add, float pos, int in){
|
||||
return methCla.audioInPlay(amp, add, pos, in);
|
||||
};
|
||||
|
||||
public static void audioInSet(float amp, float add, float pos, int[] nodeId){
|
||||
@@ -241,6 +241,13 @@ public class Engine {
|
||||
methCla.destroy_fft(ptr);
|
||||
};
|
||||
|
||||
// Out
|
||||
|
||||
public static void out(int out, int[] nodeId){
|
||||
methCla.out(out, nodeId);
|
||||
};
|
||||
|
||||
|
||||
public static void engineStop() {
|
||||
methCla.engineStop();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MethClaInterface
|
||||
|
||||
// Audio In
|
||||
|
||||
public native int[] audioInPlay(float amp, float add, float pos, boolean out);
|
||||
public native int[] audioInPlay(float amp, float add, float pos, int in);
|
||||
|
||||
public native void audioInSet(float amp, float add, float pos, int[] nodeId);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class MethClaInterface
|
||||
|
||||
// Pan + Out
|
||||
|
||||
// public native int out(float pos, int nodeId);
|
||||
public native void out(int out, int[] nodeId);
|
||||
|
||||
// connect
|
||||
|
||||
|
||||
@@ -6,18 +6,7 @@ public interface Oscillator extends SoundObject {
|
||||
public void play(float freq, float amp, float add);
|
||||
public void play(float freq, float amp);
|
||||
public void play();
|
||||
/* for modulation
|
||||
public void play(Oscillator freq, float amp, float add);
|
||||
public void play(Oscillator freq, float amp);
|
||||
public void play(float freq, Oscillator amp, float add);
|
||||
public void play(float freq, Oscillator amp);
|
||||
public void play(float freq, float amp, Oscillator add);
|
||||
public void play(Oscillator freq, Oscillator amp, float add);
|
||||
public void play(Oscillator freq, Oscillator amp);
|
||||
public void play(float freq, Oscillator amp, Oscillator add);
|
||||
public void play(Oscillator freq, float amp, Oscillator add);
|
||||
public void play(Oscillator freq, Oscillator amp, Oscillator add);
|
||||
*/
|
||||
|
||||
public void freq(float freq);
|
||||
public void amp(float amp);
|
||||
public void add(float add);
|
||||
|
||||
@@ -61,7 +61,11 @@ public class PinkNoise implements SoundObject{
|
||||
m_pos=pos;
|
||||
this.set();
|
||||
}
|
||||
|
||||
/*
|
||||
public void out(int out){
|
||||
m_engine.out(out, m_nodeId);
|
||||
}
|
||||
*/
|
||||
public void stop(){
|
||||
m_engine.synthStop(m_nodeId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user