Adding a delay effect
In this recipe, we will learn how to add a delay effect to the frequency modulation audio generated in the previous recipe.
Getting ready
We will use the source code from the previous recipe, Generating sound with frequency modulation.
How to do it…
We will store our audio values and play them after an interval to achieve a delay effect using the following steps:
Add the following member variables:
int mDelay; float mMix, mFeedback; vector<float> mDelayLine; int mDelayIndex; int mDelaySize;
Let's initialize the variables created above and initialize our delay line with zeros.
Then add the following in the
setup
method:mDelay = 200; mMix = 0.2f; mFeedback = 0.3f; mDelaySize = mDelay * 44.1f; for( int i=0; i<mDelaySize; i++ ){ mDelayLine.push_back( 0.0f ); }
In the implementation of our
audioCallback
method, we will read back from the buffer the values that were generated in the frequency modulation and calculate the delay.The final value is again passed into the buffer...