Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- FFT fft;
- AudioIn in;
- Amplitude amp;
- int bands = 4096;
- float[] spectrum = new float[bands];
- int f = 1;
- static final int NUM_LINES = 10;
- float t;
- void setup() {
- background(20);
- size(500, 500);
- // Create an Input stream which is routed into the Amplitude analyzer
- fft = new FFT(this, bands);
- in = new AudioIn(this, 0);
- amp = new Amplitude(this);
- // start the Audio Input
- in.start();
- amp.input(in);
- // patch the AudioIn
- fft.input(in);
- }
- void draw() {
- fft.analyze(spectrum);
- background(20);
- stroke(255);
- strokeWeight(5);
- translate(width/2, height/2);
- int highestIndex = 0;
- for (int i = 0; i < bands / 4; i++) {
- if (spectrum[i] > spectrum[highestIndex]) {
- highestIndex = i;
- }
- }
- for (int i = 0; i < NUM_LINES; i++) {
- line(x1(t + i), y1(t + i), x2(t + i), y2(t + i));
- }
- println((int) (amp.analyze() * 100));
- f = (int) (amp.analyze() * 50);
- t += f;
- }
- float x1(float t) {
- return sin(t / 5) * 100 + sin(t / 5) * 20;
- }
- float y1(float t) {
- return cos(t / 10) * 100;
- }
- float x2(float t) {
- return sin(t / 10) * 200 + sin(t) * 2 + sin(t) * 2;
- }
- float y2(float t) {
- return cos(t / 20) * 200 + cos(t / 12) * 20;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement