We have already discussed, back in Chapter 4, 3D Audio, that DSP effects are algorithms that modify the audio data to achieve a certain goal. Now we will see an example of how to implement a simple delay effect. The way a basic delay effect works, is to keep a separate buffer of data, and store the audio data that has already played in it. The size of the buffer determines how long it takes between the original sound and its echo plays. Then, we simply need to mix the audio data that is playing, with a portion of the old signal that was stored in the buffer, which produces a delay. Let us examine the following MyDelay
class definition, which encapsulates the effect:
class MyDelay { public: MyDelay(float time, float decay); ~MyDelay(); void WriteSoundData(PCM16* data, int count); private: PCM16* buffer; int size; int position; float decay; };
The MyDelay
class constructor takes two parameters, time
and decay
. The first parameter controls how many seconds...