Advertisement
Guest User

Untitled

a guest
May 30th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include "ofApp.h"
  2. #include "math.h"
  3.  
  4. //--------------------------------------------------------------
  5. void ofApp::setup(){
  6. beat.loadSound("sounds/DrivingSpaceShipsProdByARZA1990.wav");
  7. fftSmoothed = new float[8192];
  8. for (int i = 0; i < 8192; i++){
  9. fftSmoothed[i] = 0;
  10. }
  11. nBandsToGet = 16;
  12. beat.play();
  13. ofSetVerticalSync(false);
  14. ofEnableAlphaBlending();
  15. }
  16.  
  17. //--------------------------------------------------------------
  18. void ofApp::update(){
  19. ofSoundUpdate();
  20. // (5) grab the fft, and put in into a "smoothed" array,
  21. // by taking maximums, as peaks and then smoothing downward
  22. float *val = ofSoundGetSpectrum(nBandsToGet); // request 128 values for fft
  23. for (int i = 0;i < nBandsToGet; i++){
  24.  
  25. // let the smoothed calue sink to zero:
  26. fftSmoothed[i] *= 0.96f;
  27.  
  28. // take the max, either the smoothed or the incoming:
  29. if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i];
  30.  
  31. }
  32. }
  33.  
  34. //--------------------------------------------------------------
  35. void ofApp::draw()
  36. {
  37.  
  38. float curTimeSecs = ofGetElapsedTimeMicros() / 1000000.0f;
  39.  
  40. float cR = 255.0f,
  41. cG = 255.0f,
  42. cB = 255.0f;
  43. ofBackground(255 - cG, 255 - cB, 255 - cR);
  44. float circleRadius = ofGetHeight() / 2.0f;
  45. for(int h=0; h<nBandsToGet; h++)
  46. {
  47. ofSetColor(cR, cG, cB);
  48. ofCircle((h * (ofGetWidth() - (circleRadius * 2.0f))/ nBandsToGet) + circleRadius, (ofGetHeight() / 2.0f), fftSmoothed[h] * circleRadius);
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement