Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 2d35aca

Browse files
committed
bela resonator noise input
1 parent f0b9778 commit 2d35aca

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

examples/bela/cpp/cpp-osc-resonator/render.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdlib.h>
12
#include <Bela.h>
23
#include <libraries/OscSender/OscSender.h>
34
#include <libraries/OscReceiver/OscReceiver.h>
@@ -10,6 +11,11 @@ const int localPort = 7562;
1011
Resonator res;
1112
ResonatorOptions options; // will initialise to default
1213

14+
bool audioInput = false;
15+
float impulseInterval = 44100;
16+
float impulseWidth = 0.125;
17+
float impulseCount = 0;
18+
1319
void onReceive(oscpkt::Message* msg, const char* addr, void* arg) {
1420

1521
if(msg->match("/resonator")) {
@@ -67,7 +73,14 @@ void render (BelaContext *context, void *userData) {
6773

6874
for (unsigned int n = 0; n < context->audioFrames; ++n) {
6975

70-
float in = audioRead(context, n, 0); // an excitation signal
76+
float in = 0.0f;
77+
if (audioInput)
78+
in = audioRead(context, n, 0); // an excitation signal
79+
else {
80+
if (++impulseCount >= impulseInterval * (1-impulseWidth))
81+
in = 1.0f * ( rand() / (float)RAND_MAX * 2.f - 1.f ); // noise
82+
if (impulseCount >= impulseInterval) impulseCount = 0;
83+
}
7184
float out = 0.0f;
7285

7386
out = res.render(in);

0 commit comments

Comments
 (0)