What do functions sound like?

The pitch of the notes is correlated to their vertical position on the staff.

I was a band geek in middle and high school, the euphonium being my instrument of choice. When the band director handed out a new piece of sheet music for the band to study, the first thing we had to do was sight read it, and use the ink on the page to imagine what the song sounds like.

To do this, I’d hum some tone, and if the notes ascended, I increased the tone of my hum. If the notes descended, I’d relax my mouth to hum lower notes. Of course, this process is very crude, and much of the detail is ignored in the first pass.

If I can turn dots on a page into sound, why not a function?

Simple real-valued functions can be understood in several ways:

As a curve on a plane.
As describing the motion of something.
Describing color (HSV color mode used).

The Plan

Today, I used the principle of sight reading sheet music to turn a function’s plot into an audio file.

Given a function defined on interval [t_{\text{init}}, t_{\text{final}} ], the sound file will be t_{\text{final}} – t_{\text{min}} seconds long. To transform f(x) into audible frequencies, we must decide a range of frequencies determined by \text{min}f(x) and \text{max}f(x) and “squish” the function values into pitches we can hear, at time t.

To create the audio file, I adapted some code from Andrew Ippoliti’s blog that explains how to use Scipy’s wavfile feature. I animated the curves using matplotlib, and stiched the frames and audio together using virtualdub.

f(x) = x\sin(x)
f(x) = \sin(x^2)

Make your own sounds (and perhaps try to improve the audio quality?) with the code: https://github.com/ezamo007/blog/tree/master/3-hearing_fx.

Leave a Reply

Your email address will not be published.