-
Notifications
You must be signed in to change notification settings - Fork 1
/
AudioInput.pde
61 lines (45 loc) · 1.23 KB
/
AudioInput.pde
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
import processing.sound.*;
final String FILENAME = "Thai elephant.wav";
SoundFile sample;
Waveform waveform;
//AMP
Amplitude rms;
float smoothingFactorAmp = 0.25;
float smoothingFactorFFT = 0.75;
float ampsum;
//FFT
FFT fft;
int FFT_NUM_BANDS = 512;
float[] fftsum = new float[FFT_NUM_BANDS];
int NUM_SAMPLES_WAVE = 64;
List FFTBPs;
Sound sound;
void initAudioInput() {
//sound = new Sound(this);
//sound.outputDevice(3);
//sound.volume(0.2);
sample = new SoundFile(this, FILENAME);
sample.loop();
rms = new Amplitude(this);
rms.input(sample);
fft = new FFT(this, FFT_NUM_BANDS);
fft.input(sample);
waveform = new Waveform(this, NUM_SAMPLES_WAVE);
waveform.input(sample);
}
void tickWave(){
waveform.analyze();
}
float tickAmp(){
// smooth the rms data by smoothing factor
ampsum += (rms.analyze() - ampsum) * smoothingFactorAmp;
return ampsum;
}
float[] tickFFT() {
fft.analyze();
for (int i = 0; i < FFT_NUM_BANDS; i++) {
// Smooth the FFT spectrum data by smoothing factor
fftsum[i] += (fft.spectrum[i] - fftsum[i]) * smoothingFactorFFT;
}
return fftsum;
}