#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
beat.load("sweetdreams.mp3");
ofSetCircleResolution(200);
fftSmooth = new float [8192];
for (int i = 0; i < 8192; i++) {
fftSmooth[i] = 0;
}
bands = 64;
beat.setLoop(true);
beat.setVolume(0.2);
}
//--------------------------------------------------------------
void ofApp::update(){
ofSoundUpdate();
float * value = ofSoundGetSpectrum(bands);
for (int i = 0; i < bands; i++){
fftSmooth[i] *= 0.99f;
if (fftSmooth[i] < value[i]) {
fftSmooth[i] = value[i];
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
for (int i = 0; i < bands; i++){
ofSetColor(ofRandom(255), ofRandom(50), ofRandom(130));
ofDrawCircle(ofGetWidth()/2, ofGetHeight()/2, -(fftSmooth[i]*200));
}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
switch (key) {
case '1':
beat.play();
break;
case '2':
beat.stop();
break;
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}