Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- #include "math.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- beat.loadSound("sounds/DrivingSpaceShipsProdByARZA1990.wav");
- fftSmoothed = new float[8192];
- for (int i = 0; i < 8192; i++){
- fftSmoothed[i] = 0;
- }
- nBandsToGet = 16;
- beat.play();
- ofSetVerticalSync(false);
- ofEnableAlphaBlending();
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- ofSoundUpdate();
- // (5) grab the fft, and put in into a "smoothed" array,
- // by taking maximums, as peaks and then smoothing downward
- float *val = ofSoundGetSpectrum(nBandsToGet); // request 128 values for fft
- for (int i = 0;i < nBandsToGet; i++){
- // let the smoothed calue sink to zero:
- fftSmoothed[i] *= 0.96f;
- // take the max, either the smoothed or the incoming:
- if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw()
- {
- float curTimeSecs = ofGetElapsedTimeMicros() / 1000000.0f;
- float cR = 255.0f,
- cG = 255.0f,
- cB = 255.0f;
- ofBackground(255 - cG, 255 - cB, 255 - cR);
- float circleRadius = ofGetHeight() / 2.0f;
- for(int h=0; h<nBandsToGet; h++)
- {
- ofSetColor(cR, cG, cB);
- ofCircle((h * (ofGetWidth() - (circleRadius * 2.0f))/ nBandsToGet) + circleRadius, (ofGetHeight() / 2.0f), fftSmoothed[h] * circleRadius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement