Making sound-reactive particles
In this recipe, we will show an example of audio visualization based on audio-reactive particles.
Getting ready
Save your favorite music piece in assets folder with the name music.mp3
.
Please refer to Chapter 6, Adding a Tail to Our Particles, for instructions on how to draw particles with a tile.
How to do it…
We will create a sample audio-reactive visualization using the following steps:
Add the following necessary header files:
#include "cinder/Rand.h" #include "cinder/MayaCamUI.h" #include "cinder/audio/Io.h" #include "cinder/audio/Output.h" #include "cinder/audio/FftProcessor.h" #include "cinder/audio/PcmBuffer.h" #include "ParticleSystem.h"
Add the following members for audio playback and analysis:
audio::TrackRef mTrack; audio::PcmBuffer32fRef mPcmBuffer; float beatForce; float beatSensitivity; float avgLvlOld; float randAngle;
Add the following members for particle simulation:
ParticleSystem mParticleSystem; Vec3f attrPosition; float attrFactor; CameraPersp...