A Physical Model of the Piano for Sound Synthesis
Source Code

C. Otey
December 12, 2007

The code linked to this page is part of a report submitted as coursework for Physics 210, Stanford University, Fall 2007. It is written in C++ and posted as the tarball piano.tar.gz. The instructions for compiling with g++ are

                  tar -zxf piano.tar.gz
                  make
    

This code invokes the libsndfile libraries to generate .wav files. These libraries, obtained from www.mega-nerd.com/libsndfile are posted here as the tarball libsndfile-1.0.17.tar.gz. The compilation instructions are

                  tar -zxf libsndfile-1.0.17.tar.gz
                  cd libsndfile-1.0.17
                  ./configure
                  make
                  make install
    

The default installation directory is /usr/local/lib. Under some unix distributions (e.g. Fedora Core 5) ld is not set up to look in /usr/local/lib. Running the executable will then result in a message like "error while loading shared libraries libsndfile.so.1: cannot open shared object file: No such file or directory." The simplest solution to this problem is to create a soft link in a directory that ld searches, for example

                  cd /usr/lib
                  ln -s /usr/local/lib/libsndfile.so.1.0.17 libsndfile.so.1
    

Run

                  ./piano
    

to see usage. When run, a mono .wav file called out.wav is created. If the -b option is used a file called wave.out is generated instead, which is a binary file of floating point numbers in the range [-1:1]. This can be converted to any mono audio format using 3rd party tools e.g. libsndfile.

© 2007 C. R. Otey. The author grants permission to copy, distribute and display this work in unaltered form, with attribution to the author, for noncommercial purposes only. All other rights, including commercial rights, are reserved to the author.