added PinkNoise + changed filter Classes to long names

This commit is contained in:
wirsing
2014-07-03 23:38:44 -07:00
parent e955f26c99
commit c7feaa1bbf
14 changed files with 376 additions and 37 deletions

View File

@@ -0,0 +1,27 @@
/*
This is a simple WhiteNoise generator. It can be started with .play(float amp).
In this example it is started and stopped by clicking into the renderer window.
*/
import processing.sound.*;
PinkNoise noise;
float amp=0.0;
void setup() {
size(640, 360);
background(255);
// Create and start noise generator
noise = new PinkNoise(this);
noise.play();
}
void draw() {
// Map mouseX from 0.0 to 1.0 for amplitude
noise.amp(map(mouseX, 0, width, 0.0, 1.0));
// Map mouseY from -1.0 to 1.0 for left to right
noise.pan(map(mouseY, 0, width, -1.0, 1.0));
}

View File

@@ -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_AUDIOIN_H_INCLUDED
#define METHCLA_PLUGINS_AUDIOIN_H_INCLUDED
#include <methcla/plugin.h>
METHCLA_EXPORT const Methcla_Library* methcla_plugins_audioin(const Methcla_Host*, const char*);
#define METHCLA_PLUGINS_AUDIOIN_URI METHCLA_PLUGINS_URI "/audioin"
#endif /* METHCLA_PLUGINS_AUDIOIN_H_INCLUDED */

View File

@@ -0,0 +1,19 @@
//
// whitenoise.h
//
//
// Created by wirsing on 13.12.13.
//
//
#ifndef METHCLA_PLUGINS_PINK_NOISE_H_INCLUDED
#define METHCLA_PLUGINS_PINK_NOISE_H_INCLUDED
#include <methcla/plugin.h>
METHCLA_EXPORT const Methcla_Library* methcla_plugins_pink_noise(const Methcla_Host*, const char*);
#define METHCLA_PLUGINS_PINK_NOISE_URI METHCLA_PLUGINS_URI "/pink_noise"
#endif // METHCLA_PLUGINS_PINK_NOISE_H_INCLUDED

View File

@@ -103,6 +103,22 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_pulsePlay
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pulseSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: audioInPlay
* Signature: (FFFZ)[I
*/
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_audioInPlay
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jboolean);
/*
* Class: processing_sound_MethClaInterface
* Method: audioInSet
* Signature: (FFF[I)V
*/
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_audioInSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: soundFileInfo
@@ -159,6 +175,22 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_whiteNoisePla
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_whiteNoiseSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: pinkNoisePlay
* Signature: (FFF)[I
*/
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_pinkNoisePlay
(JNIEnv *, jobject, jfloat, jfloat, jfloat);
/*
* Class: processing_sound_MethClaInterface
* Method: pinkNoiseSet
* Signature: (FFF[I)V
*/
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pinkNoiseSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: envelopePlay

View File

@@ -18,6 +18,7 @@
#include "methcla/plugins/soundfile_api_libsndfile.h"
#include "methcla/plugins/sampler.h"
#include "methcla/plugins/whitenoise.h"
#include "methcla/plugins/pinknoise.h"
#include "methcla/plugins/node-control.h"
#include "methcla/plugins/pan2.h"
#include "methcla/plugins/soundfile_api_mpg123.h"
@@ -26,6 +27,7 @@
#include "methcla/plugins/hpf.h"
#include "methcla/plugins/lpf.h"
#include "methcla/plugins/delay.h"
#include "methcla/plugins/audio_in.h"
#define OUTPUT_BUFFER_SIZE 1024
#define SNDF_BUFFER_LEN 1024
@@ -66,13 +68,15 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_engineNew (JNIEnv
.addLibrary(methcla_plugins_patch_cable)
.addLibrary(methcla_plugins_sampler)
.addLibrary(methcla_plugins_white_noise)
.addLibrary(methcla_plugins_pink_noise)
.addLibrary(methcla_plugins_node_control)
.addLibrary(methcla_plugins_pan2)
.addLibrary(methcla_plugins_amplitude_follower)
.addLibrary(methcla_plugins_hpf)
.addLibrary(methcla_plugins_lpf)
.addLibrary(methcla_plugins_delay)
.addLibrary(methcla_plugins_fft);
.addLibrary(methcla_plugins_fft)
.addLibrary(methcla_plugins_audioin);
m_engine = new Methcla::Engine(options);
@@ -371,6 +375,68 @@ 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){
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);
auto synth = request.synth(
METHCLA_PLUGINS_AUDIOIN_URI,
engine().root(),
{amp, add, pos}
);
auto pan = request.synth(
METHCLA_PLUGINS_PAN2_URI,
engine().root(),
{pos, 0},
{Methcla::Value(1.f)}
);
request.mapInput(synth.id(), 0, in, Methcla::kBusMappingExternal);
request.mapOutput(synth.id(), 0, bus);
request.mapInput(pan.id(), 0, bus);
request.mapOutput(pan.id(), 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal);
request.mapOutput(pan.id(), 1, Methcla::AudioBusId(1), Methcla::kBusMappingExternal);
request.activate(synth.id());
request.activate(pan.id());
request.closeBundle();
request.send();
m_nodeId[0]=synth.id();
m_nodeId[1]=pan.id();
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
return nodeId;
};
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_audioInSet(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos, jintArray nodeId){
jint* m_nodeId = env->GetIntArrayElements(nodeId, 0);
Methcla::Request request(engine());
request.openBundle(Methcla::immediately);
request.set(m_nodeId[0], 0 , amp);
request.set(m_nodeId[0], 1 , add);
request.set(m_nodeId[1], 0 , pos);
request.closeBundle();
request.send();
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
};
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_soundFileInfo(JNIEnv *env, jobject object, jstring path){
const char *str = env->GetStringUTFChars(path, 0);
@@ -595,6 +661,64 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_whiteNoiseSet(JNIE
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
};
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_pinkNoisePlay(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos){
jintArray nodeId = env->NewIntArray(2);
jint *m_nodeId = env->GetIntArrayElements(nodeId, NULL);
Methcla::AudioBusId bus = m_engine->audioBusId().alloc();
Methcla::Request request(engine());
request.openBundle(Methcla::immediately);
auto synth = request.synth(
METHCLA_PLUGINS_PINK_NOISE_URI,
engine().root(),
{ amp, add },
{}
);
auto pan = request.synth(
METHCLA_PLUGINS_PAN2_URI,
engine().root(),
{pos, 1.f},
{Methcla::Value(1.f)}
);
request.mapOutput(synth.id(), 0, bus);
request.mapInput(pan.id(), 0, bus);
request.mapOutput(pan.id(), 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal);
request.mapOutput(pan.id(), 1, Methcla::AudioBusId(1), Methcla::kBusMappingExternal);
request.activate(synth.id());
request.activate(pan.id());
request.closeBundle();
request.send();
m_nodeId[0]=synth.id();
m_nodeId[1]=pan.id();
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
return nodeId;
};
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pinkNoiseSet(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos, jintArray nodeId){
jint* m_nodeId = env->GetIntArrayElements(nodeId, 0);
Methcla::Request request(engine());
request.openBundle(Methcla::immediately);
request.set(m_nodeId[0], 0, amp);
request.set(m_nodeId[1], 0, pos);
request.closeBundle();
request.send();
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
};
JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_envelopePlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat attackTime, jfloat sustainTime, jfloat sustainLevel, jfloat releaseTime){
jint* m_nodeId = env->GetIntArrayElements(nodeId, 0);
@@ -932,7 +1056,6 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_destroy_1fft(JNIEn
free(fft_ptr);
};
/* OLD VARIABLE IN OUT FUNCTION
JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_out(JNIEnv *env, jobject object, jint in, jint out, jfloatArray pos){

View File

@@ -7,9 +7,9 @@ public class AudioIn {
PApplet parent;
private Engine m_engine;
private int[] m_nodeId = {-1,-1};
private float m_freq = 0;
private float m_amp = 0;
private float m_amp = 1.f;
private float m_add = 0;
private boolean m_out = true;
private float m_pos = 0;
public AudioIn(PApplet theParent) {
@@ -19,36 +19,31 @@ public class AudioIn {
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;
m_nodeId = m_engine.sawPlay(m_freq, m_amp, m_add, m_pos);
}
public void play(float freq, float amp, float add){
m_freq=freq; m_amp=amp; m_add=add;
m_nodeId = m_engine.sawPlay(m_freq, m_amp, m_add, m_pos);
}
public void play(float freq, float amp){
m_freq=freq; m_amp=amp;
m_nodeId = m_engine.sawPlay(m_freq, m_amp, m_add, m_pos);
}
public void play(){
m_nodeId = m_engine.sawPlay(m_freq, m_amp, m_add, m_pos);
m_nodeId = m_engine.audioInPlay(m_amp, m_add, m_pos, m_out);
}
public void play(float amp, float add, float pos){
m_amp=amp; m_add=add; m_pos=pos;
this.play();
}
public void play(float amp, float add){
m_amp=amp; m_add=add;
this.play();
}
public void play(float amp){
m_amp=amp;
this.play();
}
private void set(){
m_engine.oscSet(m_freq, m_amp, m_add, m_pos, m_nodeId);
m_engine.audioInSet(m_amp, m_add, m_pos, m_nodeId);
}
public void set(float freq, float amp, float add, float pos){
m_freq=freq; m_amp=amp; m_add=add; m_pos=pos;
this.set();
}
public void freq(float freq){
m_freq=freq;
public void set(float amp, float add, float pos){
m_amp=amp; m_add=add; m_pos=pos;
this.set();
}

View File

@@ -2,7 +2,7 @@ package processing.sound;
import processing.core.PApplet;
public class BPF implements SoundObject{
public class BandPass implements SoundObject{
PApplet parent;
private Engine m_engine;
@@ -11,7 +11,7 @@ public class BPF implements SoundObject{
private float m_freq = 100;
private float m_res = 1;
public BPF(PApplet theParent) {
public BandPass(PApplet theParent) {
this.parent = theParent;
parent.registerMethod("dispose", this);
m_engine.setPreferences(theParent, 512, 44100);

View File

@@ -98,7 +98,17 @@ public class Engine {
public static void pulseSet(float freq, float width, float amp, float add, float pos, int[] nodeId){
methCla.pulseSet(freq, width, amp, add, pos, nodeId);
};
// AudioIn
public static int[] audioInPlay(float amp, float add, float pos, boolean out){
return methCla.audioInPlay(amp, add, pos, out);
};
public static void audioInSet(float amp, float add, float pos, int[] nodeId){
methCla.audioInSet(amp, add, pos, nodeId);
};
// SoundFile
public static int[] soundFileInfo(String path){
@@ -121,7 +131,7 @@ public class Engine {
methCla.soundFileSetStereo(rate, amp, add, nodeId);
};
// Noise
// White Noise
public static int[] whiteNoisePlay(float amp, float add, float pos){
return methCla.whiteNoisePlay(amp, add, pos);
@@ -130,6 +140,16 @@ public class Engine {
public static void whiteNoiseSet(float amp, float add, float pos, int[] nodeId){
methCla.whiteNoiseSet(amp, add, pos, nodeId);
};
// Pink Noise
public static int[] pinkNoisePlay(float amp, float add, float pos){
return methCla.pinkNoisePlay(amp, add, pos);
};
public static void pinkNoiseSet(float amp, float add, float pos, int[] nodeId){
methCla.pinkNoiseSet(amp, add, pos, nodeId);
};
// Envelope

View File

@@ -2,7 +2,7 @@ package processing.sound;
import processing.core.PApplet;
public class HPF implements SoundObject{
public class HighPass implements SoundObject{
PApplet parent;
private Engine m_engine;
@@ -11,7 +11,7 @@ public class HPF implements SoundObject{
private float m_freq = 100;
private float m_res = 1;
public HPF(PApplet theParent) {
public HighPass(PApplet theParent) {
this.parent = theParent;
parent.registerMethod("dispose", this);
m_engine.setPreferences(theParent, 512, 44100);

View File

@@ -2,7 +2,7 @@ package processing.sound;
import processing.core.PApplet;
public class LPF implements SoundObject{
public class LowPass implements SoundObject{
PApplet parent;
private Engine m_engine;
@@ -11,7 +11,7 @@ public class LPF implements SoundObject{
private float m_freq = 100;
private float m_res = 1;
public LPF(PApplet theParent) {
public LowPass(PApplet theParent) {
this.parent = theParent;
parent.registerMethod("dispose", this);
m_engine.setPreferences(theParent, 512, 44100);

View File

@@ -48,6 +48,12 @@ public class MethClaInterface
public native void pulseSet(float freq, float width, float amp, float add, float pos, int[] nodeId);
// Audio In
public native int[] audioInPlay(float amp, float add, float pos, boolean out);
public native void audioInSet(float amp, float add, float pos, int[] nodeId);
// SoundFile
public native int[] soundFileInfo(String path);
@@ -60,12 +66,18 @@ public class MethClaInterface
public native void soundFileSetStereo(float rate, float amp, float add, int[] nodeId);
// Noise
// White Noise
public native int[] whiteNoisePlay(float amp, float add, float pos);
public native void whiteNoiseSet(float amp, float add, float pos, int[] nodeId);
// Pink Noise
public native int[] pinkNoisePlay(float amp, float add, float pos);
public native void pinkNoiseSet(float amp, float add, float pos, int[] nodeId);
// Envelope
public native int envelopePlay(int[] input, float attackTime, float sustainTime, float sustainLevel, float releaseTime);

View File

@@ -0,0 +1,77 @@
package processing.sound;
import processing.core.*;
public class PinkNoise implements SoundObject{
PApplet parent;
private Engine m_engine;
private int[] m_nodeId = {-1,-1};
private float m_amp=0.5f;
private float m_add=0;
private float m_pos=0;
public PinkNoise(PApplet theParent) {
this.parent = theParent;
parent.registerMethod("dispose", this);
m_engine.setPreferences(theParent, 512, 44100);
m_engine.start();
}
public void play(){
m_nodeId = m_engine.pinkNoisePlay(m_amp, m_add, m_pos);
}
public void play(float amp, float add, float pos){
m_amp=amp; m_add=add; m_pos=pos;
this.play();
}
public void play(float amp, float add){
m_amp=amp; m_add=add;
this.play();
}
public void play(float amp){
m_amp=amp;
this.play();
}
private void set(){
if(m_nodeId[0] != -1 ) {
m_engine.pinkNoiseSet(m_amp, m_add, m_pos, m_nodeId);
}
}
public void set(float amp, float add, float pos){
m_amp=amp;
this.set();
}
public void amp(float amp){
m_amp=amp;
this.set();
}
public void add(float add){
m_add=add;
this.set();
}
public void pan(float pos){
m_pos=pos;
this.set();
}
public void stop(){
m_engine.synthStop(m_nodeId);
}
public int[] returnId(){
return m_nodeId;
}
public void dispose() {
m_engine.synthStop(m_nodeId);
}
};

View File

@@ -0,0 +1,9 @@
#!/bin/bash
# this is a small script to create the .h file for the JNIlib and put it into the right directory.
cd ../processing/sound
javac MethClaInterface.java
cd ../../
javah processing.sound.MethClaInterface
mv processing_sound_MethClaInterface.h cpp/include
rm processing/sound/MethClaInterface.class