Cornell University ECE4760
Karplus_Strong string synthesis

Pi Pico RP2040

Karplus-Strong with periodic input, spectrogram output, and user interface
The is algorithm is a shortcut method for solving the difference equation of a string. If you can solve it fast enough, you can play the solution through a DAC to make sounds. Since you are solving a string, if you give it a non-zero initial condition then it should sound like a plucked string. Adding an approximate bowing function to drive the string approximates adding periodic energy to the string.

The Karplus-Strong Algorithm (KSA) for plucked string synthesis is a special case of the digital waveguide technique for musical instrument synthesis. The KSA is particularly well suited for implementation on a microcontroller, and was originally programmed on an Intel 8080 running at 1 MHz! The simplest version hardly needs fixed point arithmetic(see next example), but better approximations do require some more sophisticated digital filters. The basic algorithm fills a circular buffer (delay line) with white noise, then lowpass filters the shifted output of the buffer and adds it back into itself. The length of the buffer (along with an allpass fractional tuning filter and the sample rate) determine the fundamental of the simulated string. The type of lowpass filter in the feedback determines the timber. Prefiltering the white noise before loading the buffer changes the pluck transient timber. This version adds damping to shorten the response, if desired.

The system in this example allows for a pluck and/or periodic input (bowing). The pluck initial condition can be random noise, lowpass filtered noise, a gaussian pulse or a triangle pulse. You can turn off the the pluck and add a driving function with settable rise and fall times, frequency, and either sine or square wave functions. The string dynamics are controlled by a one-pole settable lowpass filter and simple linear damping coeifficient.

To use this program, you need to hook up a video mionitor, SPI DAC plus speakers, and a serial terminal. Versions of the algorithm with simpler interfaces are given below. Connections are given in the lengthy comment at the start of the source code. The parameter values are displayed on the VGA, along with a spectrogram of the sounds. The serial input supports the settable parameters for a sound, plus help, play, and stop commands:

An example is shown below. The top of the frame are the parameters, the bottom the spectrograms.

Example sounds:

Code, Project ZIP


Karplus_Strong -- minimum with no user interface
This is just the basic algorithm, which produces a twangy string sound.
All the parameters are setable in the C code, but there is no user interface.
It uses the original, two-tap, FIR, lowpass filter.

sound sample

Code
Drop this code into the same folder as the unzipped project above, change the cmakelist file to point to this source.


Karplus_Strong -- with serial only user interface
To make the project memory footprint smaller, the video was eliminated, and replaced with a simple serial interface, with a little formating to make it look nice.
It is full screen, formatted, and has some color-control. Parameters at the top of the screen are updated with each command.
All commands are listed in green. After typing a command and hitting <enter>, the screen updates in less than 60 mSec.
A bad command gives a message and returns to the command prompt.
The actual synthesis is the same as the full video version above.

Code.
Drop this code into the same folder as the unzipped project above, change the cmakelist file to point to this source.


Copyright Cornell University February 3, 2024