Skip to content

Commit 402e324

Browse files
committed
Added Brown Noise
1 parent 03bf453 commit 402e324

File tree

13 files changed

+217
-4
lines changed

13 files changed

+217
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
This is a simple brownian noise generator. It can be started with .play(float amp).
3+
In this example it is started and stopped by clicking into the renderer window.
4+
*/
5+
6+
import processing.sound.*;
7+
8+
BrownNoise noise;
9+
10+
float amp=0.0;
11+
12+
void setup() {
13+
size(640, 360);
14+
background(255);
15+
16+
// Create the noise generator
17+
noise = new BrownNoise(this);
18+
noise.play();
19+
}
20+
21+
void draw() {
22+
// Map mouseX from 0.0 to 1.0 for amplitude
23+
noise.amp(map(mouseX, 0, width, 0.0, 1.0));
24+
25+
// Map mouseY from -1.0 to 1.0 for left to right
26+
noise.pan(map(mouseY, 0, width, -1.0, 1.0));
27+
}

java/libraries/sound/examples/Noise/Pink/Pink.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
This is a simple WhiteNoise generator. It can be started with .play(float amp).
2+
This is a simple pink noise generator. It can be started with .play(float amp).
33
In this example it is started and stopped by clicking into the renderer window.
44
*/
55

java/libraries/sound/examples/Noise/White/White.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
This is a simple WhiteNoise generator. It can be started with .play(float amp).
2+
This is a simple white noise generator. It can be started with .play(float amp).
33
In this example it is started and stopped by clicking into the renderer window.
44
*/
55

4.64 KB
Binary file not shown.
1.13 KB
Binary file not shown.
-1.49 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// whitenoise.h
3+
//
4+
//
5+
// Created by wirsing on 13.12.13.
6+
//
7+
//
8+
9+
10+
#ifndef METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED
11+
#define METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED
12+
13+
#include <methcla/plugin.h>
14+
15+
METHCLA_EXPORT const Methcla_Library* methcla_plugins_brown_noise(const Methcla_Host*, const char*);
16+
17+
#define METHCLA_PLUGINS_BROWN_NOISE_URI METHCLA_PLUGINS_URI "/brown_noise"
18+
19+
#endif // METHCLA_PLUGINS_BROWN_NOISE_H_INCLUDED

java/libraries/sound/src/cpp/include/processing_sound_MethClaInterface.h

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
4.64 KB
Binary file not shown.

java/libraries/sound/src/cpp/processing_sound_MethClaInterface.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "methcla/plugins/sampler.h"
2020
#include "methcla/plugins/whitenoise.h"
2121
#include "methcla/plugins/pinknoise.h"
22+
#include "methcla/plugins/brownnoise.h"
2223
#include "methcla/plugins/node-control.h"
2324
#include "methcla/plugins/pan2.h"
2425
#include "methcla/plugins/soundfile_api_mpg123.h"
@@ -32,7 +33,7 @@
3233
#define OUTPUT_BUFFER_SIZE 1024
3334
#define SNDF_BUFFER_LEN 1024
3435

35-
#define MAX_CHANNELS 2
36+
#define MAX_CHANNELS 4
3637

3738
Methcla::Engine* m_engine;
3839
Methcla::Engine& engine() { return *m_engine; }
@@ -58,6 +59,7 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_engineNew (JNIEnv
5859

5960
Methcla::EngineOptions options;
6061
options.audioDriver.bufferSize = bufferSize;
62+
options.audioDriver.numInputs = 2;
6163
options.realtimeMemorySize = 1024 * 1024 * 20;
6264
options.maxNumNodes = 1024 * 20;
6365
options.addLibrary(methcla_plugins_sine)
@@ -68,7 +70,8 @@ JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_engineNew (JNIEnv
6870
.addLibrary(methcla_plugins_patch_cable)
6971
.addLibrary(methcla_plugins_sampler)
7072
.addLibrary(methcla_plugins_white_noise)
71-
.addLibrary(methcla_plugins_pink_noise)
73+
.addLibrary(methcla_plugins_pink_noise)
74+
.addLibrary(methcla_plugins_brown_noise)
7275
.addLibrary(methcla_plugins_node_control)
7376
.addLibrary(methcla_plugins_pan2)
7477
.addLibrary(methcla_plugins_amplitude_follower)
@@ -717,6 +720,61 @@ JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_pinkNoiseSet(JNIEn
717720
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
718721
};
719722

723+
JNIEXPORT jintArray JNICALL Java_processing_sound_MethClaInterface_brownNoisePlay(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos){
724+
jintArray nodeId = env->NewIntArray(2);
725+
jint *m_nodeId = env->GetIntArrayElements(nodeId, NULL);
726+
727+
Methcla::AudioBusId bus = m_engine->audioBusId().alloc();
728+
Methcla::Request request(engine());
729+
730+
request.openBundle(Methcla::immediately);
731+
732+
auto synth = request.synth(
733+
METHCLA_PLUGINS_BROWN_NOISE_URI,
734+
engine().root(),
735+
{ amp, add },
736+
{}
737+
);
738+
739+
auto pan = request.synth(
740+
METHCLA_PLUGINS_PAN2_URI,
741+
engine().root(),
742+
{pos, 1.f},
743+
{Methcla::Value(1.f)}
744+
);
745+
746+
request.mapOutput(synth.id(), 0, bus);
747+
request.mapInput(pan.id(), 0, bus);
748+
request.mapOutput(pan.id(), 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal);
749+
request.mapOutput(pan.id(), 1, Methcla::AudioBusId(1), Methcla::kBusMappingExternal);
750+
751+
request.activate(synth.id());
752+
request.activate(pan.id());
753+
754+
request.closeBundle();
755+
request.send();
756+
757+
m_nodeId[0]=synth.id();
758+
m_nodeId[1]=pan.id();
759+
760+
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
761+
762+
return nodeId;
763+
};
764+
765+
JNIEXPORT void JNICALL Java_processing_sound_MethClaInterface_brownNoiseSet(JNIEnv *env, jobject object, jfloat amp, jfloat add, jfloat pos, jintArray nodeId){
766+
767+
jint* m_nodeId = env->GetIntArrayElements(nodeId, 0);
768+
769+
Methcla::Request request(engine());
770+
request.openBundle(Methcla::immediately);
771+
request.set(m_nodeId[0], 0, amp);
772+
request.set(m_nodeId[1], 0, pos);
773+
request.closeBundle();
774+
request.send();
775+
776+
env->ReleaseIntArrayElements(nodeId, m_nodeId, 0);
777+
};
720778

721779

722780
JNIEXPORT jint JNICALL Java_processing_sound_MethClaInterface_envelopePlay(JNIEnv *env, jobject object, jintArray nodeId, jfloat attackTime, jfloat sustainTime, jfloat sustainLevel, jfloat releaseTime){

0 commit comments

Comments
 (0)