Added Brown Noise

This commit is contained in:
wirsing
2014-07-05 21:04:35 -07:00
parent c7feaa1bbf
commit 969328b342
9 changed files with 217 additions and 4 deletions
@@ -0,0 +1,27 @@
/*
This is a simple brownian noise 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.*;
BrownNoise noise;
float amp=0.0;
void setup() {
size(640, 360);
background(255);
// Create the noise generator
noise = new BrownNoise(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));
}
@@ -1,5 +1,5 @@
/*
This is a simple WhiteNoise generator. It can be started with .play(float amp).
This is a simple pink noise generator. It can be started with .play(float amp).
In this example it is started and stopped by clicking into the renderer window.
*/
@@ -1,5 +1,5 @@
/*
This is a simple WhiteNoise generator. It can be started with .play(float amp).
This is a simple white noise generator. It can be started with .play(float amp).
In this example it is started and stopped by clicking into the renderer window.
*/
@@ -0,0 +1,19 @@
//
// whitenoise.h
//
//
// Created by wirsing on 13.12.13.
//
//
#ifndef METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED
#define METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED
#include <methcla/plugin.h>
METHCLA_EXPORT const Methcla_Library* methcla_plugins_brown_noise(const Methcla_Host*, const char*);
#define METHCLA_PLUGINS_BROWN_NOISE_URI METHCLA_PLUGINS_URI "/brown_noise"
#endif // METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED
@@ -191,6 +191,22 @@ JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_pinkNoisePlay
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pinkNoiseSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: brownNoisePlay
* Signature: (FFF)[I
*/
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_brownNoisePlay
(JNIEnv *, jobject, jfloat, jfloat, jfloat);
/*
* Class: processing_sound_MethClaInterface
* Method: brownNoiseSet
* Signature: (FFF[I)V
*/
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_brownNoiseSet
(JNIEnv *, jobject, jfloat, jfloat, jfloat, jintArray);
/*
* Class: processing_sound_MethClaInterface
* Method: envelopePlay
@@ -19,6 +19,7 @@
#include "methcla/plugins/sampler.h"
#include "methcla/plugins/whitenoise.h"
#include "methcla/plugins/pinknoise.h"
#include "methcla/plugins/brownnoise.h"
#include "methcla/plugins/node-control.h"
#include "methcla/plugins/pan2.h"
#include "methcla/plugins/soundfile_api_mpg123.h"
@@ -32,7 +33,7 @@
#define OUTPUT_BUFFER_SIZE 1024
#define SNDF_BUFFER_LEN 1024
#define MAX_CHANNELS 2
#define MAX_CHANNELS 4
Methcla::Engine* m_engine;
Methcla::Engine& engine() { return *m_engine; }
@@ -58,6 +59,7 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_engineNew (JNIEnv
Methcla::EngineOptions options;
options.audioDriver.bufferSize = bufferSize;
options.audioDriver.numInputs = 2;
options.realtimeMemorySize = 1024 * 1024 * 20;
options.maxNumNodes = 1024 * 20;
options.addLibrary(methcla_plugins_sine)
@@ -68,7 +70,8 @@ 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_pink_noise)
.addLibrary(methcla_plugins_brown_noise)
.addLibrary(methcla_plugins_node_control)
.addLibrary(methcla_plugins_pan2)
.addLibrary(methcla_plugins_amplitude_follower)
@@ -717,6 +720,61 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pinkNoiseSet(JNIEn
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
};
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_brownNoisePlay(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_BROWN_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_brownNoiseSet(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){
@@ -0,0 +1,77 @@
package processing.sound;
import processing.core.*;
public class BrownNoise 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 BrownNoise(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.brownNoisePlay(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.brownNoiseSet(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);
}
};
@@ -151,6 +151,16 @@ public class Engine {
methCla.pinkNoiseSet(amp, add, pos, nodeId);
};
// Brown Noise
public static int[] brownNoisePlay(float amp, float add, float pos){
return methCla.brownNoisePlay(amp, add, pos);
};
public static void brownNoiseSet(float amp, float add, float pos, int[] nodeId){
methCla.brownNoiseSet(amp, add, pos, nodeId);
};
// Envelope
public static int envelopePlay(int[] input, float attackTime, float sustainTime, float sustainLevel, float releaseTime){
@@ -77,7 +77,13 @@ public class MethClaInterface
public native int[] pinkNoisePlay(float amp, float add, float pos);
public native void pinkNoiseSet(float amp, float add, float pos, int[] nodeId);
// Brown Noise
public native int[] brownNoisePlay(float amp, float add, float pos);
public native void brownNoiseSet(float amp, float add, float pos, int[] nodeId);
// Envelope
public native int envelopePlay(int[] input, float attackTime, float sustainTime, float sustainLevel, float releaseTime);