Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Lessons:11Length:57 minutes
Webaudio 1
  • Overview
  • Transcript

3.1 Different Notes and Sounds

In this lesson, I’ll explain how different frequencies make different musical notes, as well as how different basic waveforms make different sounds.

Related Links

3.1 Different Notes and Sounds

Okay. In order to make our exercise sound a bit nicer, we'll need to learn a bit more about notes, frequencies and waves. So first, what actually is sound? Let's do a quick Google search. Let's see. Sound is vibrations that travel through the air or another medium, and can be heard when they reach a person or animal's ear. That's right animals can hear sound too. [LAUGH] So in order to make sound, we need to vibrate the air somehow. We need to do that with some sort of sound generator. This can be your own voice. When we speak, we're vibrating the air in front of us which has an echoing effect that vibrates some more air and more until it reaches the ear drum of someone near is. In this course, we'll be using an oscillator as a sound generator. An oscillator produces a consistent periodic wave of sound to vibrate the air. The default type of wave from a wave audio oscillator, is a sine wave. It looks something like this. This rising peak in the wave form, is the part where we're pushing air molecules together, which causes high pressure. Because these air molecules are moved we leave behind an area of low pressure which is shown here by this chafe. These vibrations happen really fast. This sound wave is repeated over and over again and [INAUDIBLE] it happens by default 440 times a second. The number of times a wave is played a second is known as its frequency and is measured in hertz. So the frequency of this wave would be referred to as 440 hertz. Let's press our button again to hear it. [SOUND] If you wanted to change the pitch of this oscillator, that is if you wanted to make a musical note that sounds higher or lower, we simply change the frequency. To make a higher note, we increase the frequency, meaning that we vibrate the air much more quickly. If we head back to our audio.js file, let's specify the frequency of the oscillator. We can do this by saying osc.frequency.value equals, let's double it from its default value, so let's say 880. Okay, back to our browser. And press our button. [NOISE]. There, you'll hear that the note played is much higher than before. Feel free to play around with these frequency values. Using a lower value will give you a lower sounding note. While we're talking about frequencies, you might be wondering how these relate to actual musical notes. Well, specific frequencies map to the standard musical notes you might find on a piano or any other instrument. You can find the list of these mappings of frequencies to notes on Wikipedia. So, if we wanted to play an F-sharp, for example. We specify the frequency as 739.989. If we scroll down a bit further you can see that our default frequency of 440 Hertz plays an A. Let's change our oscillator to play a B. We can see from the table that a frequency of a B is 493.883, so let's plug that in. Okay, let's just check that in the browser. [SOUND] Great. So this sine wave is starting to sound a bit boring. Luckily, there are a few other types of waves available to us. Now, what do I mean by different types of waves? This diagram will help. We've been playing this sine wave which has a nice, round sound. But instead of smoothly fluctuating there, we can do it in different ways. A square wave for example, you can see here that it changes the pressure more suddenly, while a triangle wave follows the same rough part of the sine wave but in a more linear fashion. A sawtooth wave, on the other hand, suddenly drops in pressure but it's a slow rise back up. Each of these waves sound different. Let's try them out. In order to change the wave type, we just say osc.type equals Square. Let's go back to the browser and press our button. [NOISE] Now you can hear that sounds a bit harsher than the sound wave. So let's try a triangle wave instead. [SOUND]. You can hear that stuff in here again. Now things are starting to open up for us. We can create different musical notes using a variety of different sounds. I think we're ready to create something worthy of our users.

Back to the top