-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioInput Volume Control
49 lines (47 loc) · 1.39 KB
/
AudioInput Volume Control
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
import beads.*;
import org.jaudiolibs.beads.*;
import java.util.Arrays;
import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
import java.io.File;
AudioContext ac;
void setup() {
frameRate(200);
size(400,400);
ac = new AudioContext();
File inputFile = new File("/Users/johnwaldo/Downloads/2-11 Stop.wav");
Noise n = new Noise(ac);
String audioFileName = inputFile.getAbsolutePath();
SamplePlayer player = new SamplePlayer(ac, SampleManager.sample(audioFileName));
Gain g = new Gain(ac, 2,2);
g.addInput(player);
ac.out.addInput(g);
ac.start();
}
color fore = color(255, 102, 204);
color c = color(140, 200, 90);
color back = color(0,0,0);
void draw() {
loadPixels();
//set the background
Arrays.fill(pixels, back);
//scan across the pixels
for(int i = 0; i < width; i++) {
//for each pixel work out where in the current audio buffer we are
int buffIndex = i * 4 / width;
//then work out the pixel height of the audio data at that point
float vOff = ac.out.getValue(0,buffIndex);
if (vOff < .15) {
ac.out.setGain(ac.out.getGain()+.01);
ac.out.setValue(ac.out.getValue(0,buffIndex)+.01);
}
else if(vOff > .25) {
ac.out.setGain(ac.out.getGain()-.01);
ac.out.setValue(ac.out.getValue(0,buffIndex)-.01);
}
int vOffset = (int)((1 + ac.out.getValue(0,buffIndex)) * height / 2);
vOffset = min(vOffset, height);
}
updatePixels();
}