Cornell University ECE4760
Karplus_Strong string synthesis
Pi Pico RP2350
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. On the rp2350, the floating point version produces a new audio sample in two uSec. The high speed makes 40 Ksample/second work with serveral simultaneous strings.
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 (crude approximation of 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 noise 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 an SPI DAC plus speakers, and a serial terminal. Connections are given in the lengthy comment at the start of the source code. The serial input supports the settable parameters for a sound, plus help, play, and stop commands:
Example sounds:
Copyright Cornell University January 15, 2025