-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sampler.cpp
73 lines (66 loc) · 2.18 KB
/
Sampler.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
#include "Sampler.h"
void Sampler::setup(int bufferSize, int index){
myBufferSize=bufferSize;
list.setup();
for(int i=0; i<9; i++){
sound[i].load(ofToDataPath(list.url[index]+list.files[index][i]));
}
buffer = new float[bufferSize];
track=0;
//properties
speed=1;
amplitude=0.5;
touched=false;
looping=false;
recording=false;
//delay
size = 20000;
feedback = 0.75;
//filter
frequencyLoRes=5000;
frequencyLoPass=0.5;
resonance=50;
filterMix=0.5;
filterOn=false;
//
zone.setup();
}
void Sampler::trigger(float x, float y, int col){
sampleTrigger=1;
speed=ofMap(x,zone.rects[col][1].x,zone.rects[col][1].x+zone.rects[col][1].width,-2,2);
amplitude=ofMap(y,zone.rects[col][1].y,zone.rects[col][1].y+zone.rects[col][1].height,1,0.25);
}
void Sampler::filter(float x, float y){
frequencyLoRes=ofMap(x,0,1,200,20000);
frequencyLoPass=x;
filterMix = y;
}
void Sampler::delay(float x, float y){
feedback = ofMap(x,0,1,0.5,0.999);
size = ofMap(y,0,1,10000,40000);
}
void Sampler::play(int pos, double pan){
if(looping){
sampleOut=envelope.ar(sound[track].play(speed), 0.1, 1, 1, sampleTrigger);
}else{
sampleOut=envelope.ar(sound[track].play(speed), 0.1, 0.9999, 1, sampleTrigger);
}
if(filterOn&&!delayOn){
filtered=myFilterLoPass.lopass(sampleOut, frequencyLoPass)*filterMix+myFilterLoPass.lores(sampleOut, frequencyLoRes, resonance)*(1-filterMix);
buffer[pos]=filtered;
bus.stereo(filtered*amplitude, outputs, pan);
}else if(delayOn&&!filterOn){
delayed=myDelayLine.dl(sampleOut,size,feedback);
buffer[pos]=delayed;
bus.stereo(delayed*amplitude, outputs, pan);
}else if(delayOn&&filterOn){
delayed=myDelayLine.dl(sampleOut,size,feedback);
filtered=myFilterLoPass.lopass(delayed, frequencyLoPass)*filterMix+myFilterLoPass.lores(delayed, frequencyLoRes, resonance)*(1-filterMix);
buffer[pos]=filtered;
bus.stereo(filtered*amplitude, outputs, pan);
}else{
buffer[pos]=sampleOut;
bus.stereo(sampleOut*amplitude, outputs, pan);
}
sampleTrigger = 0;
}