Generating (and Saving) Tones with SoX

I’ve been using the command line program SoX to generate tones for my physics demonstrations on sound waves.

Single frequency tones can be used for talking about frequency and wavelength, as well as discussing octaves.

Combine two tones allows you to talk about interference and beats.

SoX can do a lot more than this, so I though I’d compile what I’m using it for in a single, reference post. For the record: I’m using SoX in Terminal on a Mac.

Using SoX

To play a single note (frequency 173.5 Hz) for 5 seconds, use:

> play -n  synth 5 sin 347

To save the note to a mp3 file (called note.mp3) use:

> sox -n note.mp3 synth 5 sin 347

The SoX command to play two notes with frequencies of 347 and 357 Hz is:

> play -n synth 15 sin 347 sin 357

and to make an mp3 file use:

> sox -n beat_10.mp3 synth 15 sin 347 sin 357

Sound Waves: Calculating Wavelength and Frequency

One of my physics students is working on a project to demonstrate interference in sound waves, so I generated a few sound files with different wavelengths for her to experiment with.

A sound wave with a frequency of 347 cycles per second (347 Hz), which has a wavelength of approximately 1 meter. Waveform captured using the WaveWindow program.

Using SoX, you can generate waves by inputing the frequency you want (using the synth command). The frequency (f) depends on the wavelength (\lambda) and speed (v) of the sound waves through air.

f = \frac{v}{\lambda}

The speed of sound through the air depends on the temperature (it’s a linear relationship). Hyperphysics has a nice Speed of Sound in Air calculator, which tells me that at room temperature (about 25 ÂșC):

Speed of Sound in Air:
v = 347 m/s

Using the formula above (or sengpielaudio’s wave calculator) we can calculate the frequency we need for any wavelength.

For example, if we wanted a 2 meter wavelength:

f = \frac{v}{\lambda}

f = \frac{347 \; \textrm{m/s}}{2 \;\textrm{m}}

f = 173.5 \; s^{-1}

Which sounds like this: 2m.mp3. (Note that 1 cycle per second equals 1 hertz, so 173.5 s-1 = 173.5 Hz).

The tone files I’ve created are below (the ones greater than 1 m may work best, but I’ve included the others for completeness):

Wavelength Frequency Sound File (mp3)
0.1 m 3470 Hz 10cm.mp3
0.25 m 1388 Hz 25cm.mp3
0.5 m 694 Hz 50cm.mp3
1 m 347 Hz 1m.mpg
2 m 173.5 Hz 2m.mp3
3 m 116 Hz 3m.mp3

Notes

SoX

The SoX command to create the 2 m sound file (that lasts for 60 seconds) is:

 > sox -n 2m.mp3 synth 60 sin 173.5

On the SoX manual page, look up the synth command.

WaveWindow

WaveWindow is a nice, shareware ($12) oscilloscope for the Mac, though it does not show the longer wavelengths very nicely.