-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioInput File Frequency Reader
51 lines (49 loc) · 1.29 KB
/
AudioInput File Frequency Reader
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
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;
Frequency f;
PowerSpectrum ps;
Glide fGlide;
float averageFrequency = 400.0;
void setup() {
frameRate(200);
size(600,600);
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);
ShortFrameSegmenter sfs = new ShortFrameSegmenter(ac);
sfs.addInput(ac.out);
FFT fft = new FFT();
sfs.addListener(fft);
ps = new PowerSpectrum();
fft.addListener(ps);
ac.out.addDependent(sfs);
ac.start();
}
color fore = color(255, 102, 204);
color c = color(140, 200, 90);
color back = color(0,0,0);
void draw() {
background(back);
stroke(fore);
if(ps == null) return;
float[] features = ps.getFeatures();
if(features != null) {
//scan across the pixels
for(int i = 0; i < width; i++) {
int featureIndex = i * features.length / width;
int vOffset = height - 1 - Math.min((int)(features[featureIndex] * height), height - 1);
line(i,height,i,vOffset);
}
}
}