Let's implement a simple physical model of a stringed musical instrument using the code from the previous example. Later you can use these routines to create a small interactive synthesizer for Android.
The string is modelled as a sequence of point masses oscillating vertically. Strictly speaking, we solve the linear one-dimensional wave equation with certain initial and boundary conditions. The sound is produced by taking values of the solution at the position of sound pickup.
We need the clGString
class to store all the model values and the final result. The method GenerateSound()
precalculates string parameters and resizes the data containers accordingly:
class clGString { public: void GenerateSound() { // 4 seconds, 1 channel, 16 bit FSoundLen = 44100 * 4 * 2; FStringLen = 200;
The Frc
value is the normalized fundamental frequency of the sound. Overtones are implicitly created by the physical model:
float Frc = 0.5f; InitString( Frc...