Sounds good - part 1.5

The last few posts on sounds seemed well received, so I'm inserting a few more explanations of sound-related concepts between the first (basics) and second (spectrogram-based) installments. Consider this part 1.5, covering some of the more fundamental topics, but migrating towards spectrogram-based ideas at the end.

Karplus–Strong (string synthesis):
You might recall from part 1 that pressure that changes in the form of a sine wave is interpreted by our ears as a single, pure tone. As explored in the waveforms section though, other shapes (triangle, square, saw, ...) when repeated at the same frequency also sound like the same note, just the acoustics are a bit different. This leads to the question: if it's just the repetition that is important, what do other shapes sound like? It turns out, that you can start with a random shape, repeat it at the right frequency, and it will usually sound like a stringed instrument. Adding in a filter (see below), you get a nice synthesized (i.e. faked) string sound, as implemented in karplusstrong.go in my go-sound library.

You can see the repeating pattern, but also that it doesn't look very sine-wave-y. The result is something that sounds like this:

Pass filters:
I threw the word 'filter' in above without explaining it properly; and for good reason! The topic of filters in signal processing comes up all the time, and could last many posts, but for now, just think of a filter as some simple processing done to a sound wave that produces another 'filtered' sound wave. You could argue that many of the effects described in these posts are filters; there's quite an interesting history of people coming up with techniques to do all sorts of interesting stuff in hardware alone (e.g. combining capacitors and resistors to process analog signal), and a large number of guitar pedals are nothing more than fancy filters.

Rather than going into fine details, I'll instead give some examples of filters that you may see used when people are talking about audio signals: pass filters. These all work by changing which frequencies remain in the sound (and which ones are filtered out), you can think of it as blanking out some of the rows in our spectrogram from post 2. The also have some very uncreative names:

  • Low-pass filter: Frequencies below a given cutoff (i.e. 'low') remain, and high ones are cut, hence why it's also known as a high-cut filter (wonderful naming...). If a recording has lots of high-pitched static, you could use one of these to try to reduce that.
  • High-pass (or low-cut) filter: exactly the opposite, frequencies above a given cutoff (i.e. 'high') remain. 
  • Band-pass filter: what you get when you have a low-pass and a high-pass, only signal between two frequencies (i.e. within a 'band') remains. Similarly, there's band-cut, the opposite.
  • Notch: a special kind of band-cut filter centered on one frequency; very useful for e.g. removing 60hz noise coming from being around electronics.

While not yet available in go-sound, there is DenseIIR.go which can be used to implement them, there's just some maths with complex numbers that needs to be added before it can be used :(

Beat frequency:
As mentioned above, a tone is nothing more than a sine-wave, repeating at a given frequency; e.g. repeat 440 times per second, and you get the note A (or, A440 to be precise). Also recall that, if you have two sounds at the same time, this is achieved by adding their pressures together. This has an interesting side-effect that, when you have two sine waves that are close together (e.g. 440hz and 441hz), their sum looks like this:

It still looks like a single sine wave, but the amplitude (how far the lines reach from the center = how loud the sound is) also changes in a repeatable fashion! As a result, you might be able to guess what this sounds like: a single tone, but with pulsating loudness - i.e. a beat. Here's one I generated (note: low frequency, so might need headphones):

This is called a beat frequency, and interestingly, the frequency of the loudness is the different of the two notes making it up. So in this case, a 440hz and a 441hz sound will pulsate in loudness (441-440) = 1 time per second. It's very noticeable when two people whistle near the same pitch, and can also be used to tune instruments as the beat disappears when two notes share a frequency (e.g. see these instructions for tuning a guitar).

Last but not least for this post, harmonics. It was briefly touched on in the part 2 post, and also covered in the string synthesis above, but you may have been wondering: if repeating a random shape sounds like a string instrument, what sounds like a trumpet? Or piano / guitar / flute / ... etc, why does an instrument sound like it does? There's a number of reasons, but one of the strongest is the collection of other tones we hear when a base ('fundamental') note is played. These other tones are called harmonics, and which ones are heard, and how loud or delayed they are changes quite a bit per instrument depending on things like where the sound is travelling, what sort of string or membrane its vibrating, ...

If you look at the spectrogram for my sine/square/triangle/saw example on freesound:

It's really easy to see where the shape changes, as lots more horizontal lines appear - these are the harmonics. The amazing thing is that your ear does not interpret these as different tones, but rather combines them into one single, richer sound. It gets fancier too: even when there is no fundamental, just harmonics, your brain often 'fills in' its own fundamental (as demonstrated on youtube) - so you are 'hearing' a tone at a frequency that doesn't exist in the original pressure waves. What's more, this is a basis for Shephard Tones - the ability to create an illusion where pitch just keeps increasing (or decreasing)! The folks at Nintendo used this to good effect for some ever-rising stairs:

Enjoy! Probably not many changes will be made to go-sound over the summer due to me being busy with an internship, but as always, if there are questions or things I should cover, post below.


Popular posts from this blog

Sounds good - part 1

Perceiving Frequencies

Real life is full of Kaizo blocks