-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.cpp
102 lines (73 loc) · 2.42 KB
/
template.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
_____ _____ _____ _____ _____
| __ | __| __ | | | __|
| -| __| __ -| | |__ |
|__|__|_____|_____|_____|_____|
REBUS - Electromagnetic Interactions
Workshop Template = CODE SKELETHON
https://xname.cc/rebus
xname 2023
https://xname.cc/rebus
Originally created for a workshop helt at Goldsmiths University of London on 21 April 2023
There’s no escape from Him.
He’s so high you can’t get over Him.
He’s so low you can’t get under Him.
He’s so wide you can’t get around Him.
If you make your bed in Heaven He’s there.
If you make your bed in Hell He’s there.
He’s everywhere.
Eno and Byrne (1981)
*/
#include <Bela.h>
#include <libraries/Scope/Scope.h>
#include <cmath>
#include <vector>
//Istantiate the virtual oscilloscope
Scope gScope;
// SENSOR DATA >> EM GAIN and PHASE
float gMinPhase = 0.01;
float gMaxPhase = 0.44;
float gMidPhase = 0.2;
float gMinGain = 0.150467;
float gMaxGain = 0.3;
bool setup(BelaContext *context, void *userData)
{
// Set up the oscilloscope (n channels and samplerate)
gScope.setup(3, context->audioSampleRate);
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->audioFrames; n++) {
float out = 0;
// read GAIN (PIN_4) and PHASE (PIN_0)
float gainReading = analogRead(context, n/2, 4);
float phaseReading = analogRead(context, n/2, 0);
/* Mapping example
// map EM phase to frequency and keep it in range
float frequency = map(phaseReading, gMinPhase, gMaxPhase, 100, 1000);
frequency = constrain(frequency, 100.0, 1000.0);
// map EM gain to amplitude and keep it in range
float amplitude = map(gainReading, gMinGain, gMaxGain, 0, 1);
amplitude = constrain(amplitude, 0, 1);
*/
// use console to check kabbalah
if(counter == 900) {
rt_printf("gainReading is %f\n", gainReading);
//rt_printf("amplitude is %f\n", amplitude);
rt_printf("phaseReading is %f\n", phaseReading);
//rt_printf("frequency is %f\n", frequency);
counter = 0;
}
counter++;
// send EM and audio data to Scope
gScope.log(gainReading, phaseReading, out);
// your code here
// Write the sample to every audio output channel
for(unsigned int channel = 0; channel < context->audioOutChannels; channel++) {
audioWrite(context, n, channel, out);
}
}
void cleanup(BelaContext *context, void *userData)
{
}