Sound Buttons

Navigation:  Objects > Action Buttons >

Sound Buttons

Previous pageReturn to chapter overviewNext page
Show/Hide Hidden Text

A Sound button plays a sound defined by a mathematical function that describes air pressure over time. The volume is determined by the amplitude of the function, and the pitch is determined by its period. Use Sound buttons to explore the physical properties of sound waves and the mathematics of oscillating functions, addition of waveforms, and so on. (You must have speakers or headphones to hear the sound created by a Sound button.)

Note

The amplitude of the function should be between –1 and 1. Larger amplitudes may result in clipping and distortion of the sound.

When one function is selected, the resulting Sound button plays a monophonic sound. When two functions are selected, the resulting Sound button plays stereo sounds, with one function controlling the right channel and the other controlling the left channel.

Select one or two functions and choose Edit | Action Buttons | Sound to create a Sound button.

The independent variable of the sound function represents time in seconds, so to play a sound at 440 hertz (A above middle C) you could use this function: f(x) = sin(440·2π·x). Sketchpad will warn you if you try to play a sound with a frequency or amplitude below the audible range.

Press the button to listen to the function. To stop playing the sound, press the button a second time or press the Esc key. (You may need to press Esc more than once.)

For example:

1. Use Edit | Preferences | Units to set your sketch’s preferred angle unit to radians.

2. Choose Number | New Function and define f(x) = sin(440·2π·x).

3. With the function selected, choose Edit | Action Buttons | Sound. Sketchpad creates a Sound button.

4. Press the button. Sketchpad plays a sound that repeats 440 times per second. This frequency corresponds to A above middle C.

5. Press the button again to release it and stop listening to the function.

Use parameters in your function definition to create more interesting sounds. For instance, if you use the function f(x) = a·sin(freq·2π·x), you can vary parameter a to change the volume and parameter freq to change the frequency while you’re playing the sound.