Generating sound upon the collision of objects
In this recipe, we will learn how to apply simple physics to object particles and generate sound upon the collision of two objects.
Getting ready
In this example, we are using code described in the recipe Generating a sine oscillator in this chapter, so please refer to that recipe.
How to do it…
We will create a Cinder application to illustrate the mechanism:
Include the following necessary header files:
#include "cinder/audio/Output.h" #include "cinder/audio/Callback.h" #include "cinder/Rand.h" #include "cinder/CinderMath.h" #include "ParticleSystem.h"
Add members to the application's
main
class for particle simulation:ParticleSystem mParticleSystem; Vec2fattrPosition; float attrFactor; float attrRadius;
Add members to the application's
main
class to make the particles interactive:bool dragging; Particle *dragParticle;
Add members for the generation of sound:
void audioCallback( uint64_t inSampleOffset, uint32_t ioSampleCount,audio::Buffer32f *buffer...