Last active
May 19, 2016 11:35
-
-
Save joannecheng/09f1a6d3f1a753ecb4e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This sketch demonstrates how to use an FFT to analyze | |
* the audio being generated by an AudioPlayer. | |
* <p> | |
* FFT stands for Fast Fourier Transform, which is a | |
* method of analyzing audio that allows you to visualize | |
* the frequency content of a signal. You've seen | |
* visualizations like this before in music players | |
* and car stereos. | |
* <p> | |
* For more information about Minim and additional features, | |
* visit http://code.compartmental.net/minim/ | |
*/ | |
import ddf.minim.analysis.*; | |
import ddf.minim.*; | |
Minim minim; | |
AudioPlayer jingle; | |
FFT fft; | |
void setup() | |
{ | |
size(512, 200, P3D); | |
minim = new Minim(this); | |
// specify that we want the audio buffers of the AudioPlayer | |
// to be 1024 samples long because our FFT needs to have | |
// a power-of-two buffer size and this is a good size. | |
jingle = minim.loadFile("jingle.mp3", 1024); | |
// loop the file indefinitely | |
jingle.loop(); | |
// create an FFT object that has a time-domain buffer | |
// the same size as jingle's sample buffer | |
// note that this needs to be a power of two | |
// and that it means the size of the spectrum will be half as large. | |
fft = new FFT( jingle.bufferSize(), jingle.sampleRate() ); | |
} | |
void draw() | |
{ | |
background(0); | |
stroke(255); | |
// perform a forward FFT on the samples in jingle's mix buffer, | |
// which contains the mix of both the left and right channels of the file | |
fft.forward( jingle.mix ); | |
for(int i = 0; i < fft.specSize(); i++) | |
{ | |
// draw the line for frequency band i, scaling it up a bit so we can see it | |
line( i, height, i, height - fft.getBand(i)*8 ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns squid.core | |
(:use [quil.core]) | |
(:import [ddf.minim Minim] | |
[ddf.minim.analysis.*] | |
[ddf.minim.*]) | |
(:require [squid.dynamic :as dynamic])) | |
(defsketch example | |
:title "Sample sketch" | |
:setup dynamic/setup | |
:draw dynamic/draw | |
:size [600 600] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns squid.dynamic | |
(:import [ddf.minim Minim]) | |
(:require [quil.core :refer :all])) | |
(def max-diam 50) | |
(defn number-circles-across [] | |
(/ (width) (* 2 max-diam))) | |
(defn draw-circle [index diam] | |
(let [x (* (+ 1 index) max-diam) | |
y (/ (height) 2)] | |
(ellipse x y diam diam))) | |
(defn setup [] | |
(smooth) | |
(random-seed 1) | |
(frame-rate 2) | |
(background 140) | |
(fill 250 200 0) | |
(dotimes [n 25] (draw-circle n 5))) | |
(defn draw [] | |
(background 140) | |
(dotimes [n 25] (draw-circle n (random 10 (- max-diam 5)))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment