So far in this series, we’ve generated and played pure tones using Python. If you’ve been following along, you might have noticed little clicks at the beginnings and/or ends of these tones, particularly if you set your computer volume rather high.
One likely reason for hearing onset/offset clicks is spectral splatter. There is a wikipedia article about spectral splatter. It reads,
Spectral splatter (also called switch noise) refers to spurious emissions that result from an abrupt change in the transmitted signal, usually when transmission is started or stopped. For example, a device transmitting a sine wave produces a single peak in the frequency spectrum; however, if the device abruptly starts or stops transmitting this sine wave, it will emit noise at frequencies other than the frequency of the sine wave. This noise is known as spectral splatter.
This is a pretty succinct explanation. You can actually see splatter when you look at the spectrogram of a pure tone:
Spectrogram of a 1000-Hz pure tone.
Spectral splatter can be reduced by gradually ramping the amplitude of the tone. A common choice of ramp shape is raised cosine, which looks like this:
Raised-cosine ramps. The ramp on the left is applied to the beginning of the sound, and the ramp on the right is applied to the end.
The spectrogram of the ramped tone looks like this:
Spectrogram of a 1000-Hz pure tone with raised-cosine ramps.
While ramping reduces splatter, it doesn’t eliminate it completely, and the effectiveness of the ramps depends on their duration. If you listen carefully, you can clearly hear the difference between tones with, say, 10-ms and 30-ms ramps. I’m not aware of any research on this matter—although I’m sure there is some, buried away in back issues of The Journal of the Acoustical Society of America—but in my experience, 25-ms ramps work well.
If you hear clicks even with sufficiently long ramps, or in the middle of a tone, it could be a buffering issue. Examples of buffering issues include delivering sounds to the audio output before it is ready to receive them, closing the connection to the audio output before the sound is finished, or delivering more than one sound to the audio output at once. Commonly such issues can be resolved by padding, or adding a few ms of silence to the beginning or end of the sound waveform. Padding can occasionally present issues in circumstances where timing is critical, such as in a psychological experiment, but most of the time it’s ok pad a little.
Clicks and other noticeable imperfections in sound playback can occur for any number of system-specific reasons and it is impossible to list them all here. However, in my experience, some combination or ramping and padding fixes most issues.
- Originally posted March 26, 2019.