O'Reilly logo

Mastering Android NDK by Viktor Latypov, Sergey Kosarevsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stringed musical instrument model

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required