An FM Synthesizer |
|
Introduction
In this page we'll build an FM synthesizer starting with the basic oscillator and working out.
Along the way, many features of ABox will be explored as well as some tips for designing your own circuits.
When we're done, we'll have a new module that can be used in other circuits.
The best way to use this page is to make your browser narrow, launch ABox2, then position ABox2 along side.
Then you can click on most of the circuits to send them to ABox.
One Oscillator
Here is a simple oscillator circuit.
It's pretty loud so you might want to turn your volume down before you play it.
The circuit has three objects and plays a monotone.
|
|
On the right is the Wave Out object, every circuit you want to hear needs one.
Wave Out has three input pins. L and R are the left and right inputs, just like your stereo.
For now we'll leave A unconnected.
There are some parameters you can adjust inside the object, but we'll use the default values for now.
The middle object is an oscillator. It builds the sound that gets sent to the speaker.
The sound comes out of the = pin.
For now, only the F input is connected, we'll connect A and O later.
Without the A pin connected, the oscillator will output values between +1 and -1.
You can adjust the wave shape inside the object. There are eight to choose from.
The left object is a knob. It's job is to produce control signals.
We'll be using a lot of knobs, so learning what they can do is important.
Throughout this tutorial I'll adjust features on the knob to make life easier.
I'll explain each as we go.
At the top of the knob you see the number 776.673, in the middle you see Hz.
Hz stands for Hertz, a measurement of frequency.
Put the two together and you get 776.673 Hz.
Right away this will tell you what the knob is doing.
It's controlling the frequency of the oscillator.
Before we move on, take a moment to hear what the circuit can do.
Try changing the value on the knob and changing the wave shape of the oscillator.
When your done, hit 'undo' few times, or just re-load the circuit.
Volume Controls
Let's add a volume control.
Actually we'll add two controls, one for the oscillator, and one for the Wave Out.
We'll do the oscillator first.
|
|
|
The oscillator has it's own volume input, the A pin.
A stands for amplitude, how big a waveform is.
All we have to do is connect a knob to it and we have a volume control.
On the new knob, you see the unit dB, which is short for decibels, the unit of loudness.
Whenever you see the dB symbol on a knob it's safe to assume that it's controlling the volume of an audio signal.
0 dB is as loud as you can get, -10 dB is quieter, -20 dB is quieter still.
You might ask why isn't the A input called V for volume ?
The answer is that you can use oscillators to control other oscillators,
and you might not be controlling the volume at all.
So we use the more generic term amplitude to avoid confusion.
Now let's add a volume control to the Wave Out.
We'll use a slider and connect it to the A input.
|
|
|
More About A Inputs
If you're assuming by now that A inputs are always amplitude, you would be correct.
We'll be using the A pins for many different purposes, so here's a little more explanation of they do.
A inputs always multiply.
A inputs can also be thought of as 'volume', 'variance', 'range', or 'scale' controls.
The crucial concept is that A inputs can set the maximum value of something.
To illustrate this concept, we'll hook a scope up to our circuit.
|
|
|
The green curve is the output of the oscillator,
imagine it as your speaker cone going up and down if you like.
The orange line is the output of the volume knob.
As you adjust the volume knob, the orange line will go up and down.
When you do this, the green curve will also get bigger and smaller,
but never go passed the orange line. This comes in handy for many things.
While We're Here...
While we've got the scope out, try adjusting the frequency control and see what it looks like.
As you make the frequency higher, the green curves will get closer and closer together.
If you were to measure the distance between the peaks and do a little math, you could derive it's frequency.
If you did the math correctly, you'd come up with the same value that's on the knob.
Try changing the wave shape of the oscillator as well.
See how the triangle, ramp, and square wave get their names from what they look like.
The sine wave gets its name from trigonometry.
Envelopes
The next step in our circuit is create a way to turn the sound off.
To do this we'll use an amplitude envelope generated by an ADSR.
Here's what it looks like.
|
|
Three new objects were created and attached to the volume control that we added in the last section.
I'll start at the volume control and work backwards.
The volume knob has a new × input pin.
This was created by selecting multiply from the knob's property panel.
You'll see a small × displayed on the lower left of the knob to indicate that it is now a multiplier.
Every signal that runs through the knob will be scaled by 10dB.
This is the same concept described in the last section, we multiply to limit the signal.
The ADSR object creates a signal from the four cyan colored lines.
From left to right lines are called attack, decay, sustain and release.
You can adjust the lines by using the dots that connect them.
The vertical yellow line indicates that the wave will hold when it gets there.
The ADSR has two input pins, T and t.
The T input is the time input and tells the ADSR how long to be.
The t input is a trigger input, it tells the ADSR when to start.
Trigger inputs are circles instead of arrows.
There may be a small symbol inside circle, this tells you what kind of trigger it is.
For our circuit, the symbol is a negative edge,
this means that when the input signal goes from positive to negative, the ADSR will start.
Connected to the T input of the ADSR is a knob with the units 'sec', which stands for seconds.
1.469 tells you how many seconds.
Two adjustments to the knob were made to make it easier to use.
For ABox, 1.469 seconds is a very long time, requiring a very small number.
So small that you can't even see the inside track on the knob.
To be able to control the knob and get the value we want, the knob was set to 1024 turns.
This means that you have to run the mouse around the object 1024 times to get from one extreme to the other.
The second change to the knob was to set it as audio taper,
indicated by the small 'A' at the bottom right.
Audio taper is useful for small numbers because adjustments to knob have less effect at lower values.
The best way to visualize this is to set the knob at '1 turn audio' and
compare the mouse arm with the value track as you adjust it.
Lastly, we get to the button. The button can only produce two values.
Push the button to get one value, release it to get the other.
The symbol on the pin tells you what the current value is.
Now let's put all this together:
Press the button, hold it down. Button output goes from +1 to -1.
ADSR t input sees this negative edge and starts the ADSR.
ADSR output is multiplied by the 10 dB knob and sent to the A input of the oscillator.
After about ¾ seconds, the ADSR is at the vertical line, where it stops and waits.
The ADSR is in the sustain phase and outputs a constant value.
Let up on the button. Button output goes from -1 to +1.
ADSR t input sees this positive edge as the release signal and lets the ADSR finish.
When the ADSR is completely finished, it will sit there and wait for the next negative edge from the button.
A Closer Look
Here's what it looks like on the scope.
The orange line is the button, the green line is the oscillator.
|
|
|
Performance
One feature of this circuit bears special mention.
To see it, you need to turn on the 'clocks' display from the main menu.
While the circuit plays, you can see the small numbers at the top right of each object.
These are the clock cycles used for each sample.
0 indicates that the object is not doing anything.
There are several things to note:
When the ADSR is off, so are the rest of the objects in the circuit.
When the ADSR is on, so is the oscillator and volume control.
When the ADSR is waiting (button held down), it turns off, the volume knob turns off and the oscillator number get smaller.
The point is that you can turn portions of circuitry off, so they don't use any CPU bandwidth.
This becomes important for very large circuits, where if every object was on, the CPU would not be able to play the circuit.
It's also important for designing 'groups' that will be pasted into other circuits.
I won't get into all the details just yet,
but the basic concept has to do with whether or not the signal is changing,
and whether or not it equals zero.
Frequency Modulation
FM synthesizers are simple to implement and provide a wide variety of sounds.
FM means frequency modulation. Modulation means 'to change'.
To make the circuit an FM synthesizer, we'll add two more objects.
Here's what it looks like.
|
|
The frequency knob (776 Hz) was moved to the left.
A second oscillator was inserted.
A new frequency knob (1248 Hz) was connected to the new oscillator.
Now we have one oscillator controlling the frequency of the second oscillator.
The first oscillator is modulating the second, so we call it the modulator.
The second oscillator is creating the sound, in effect carrying it, so we call it the carrier.
The new sine wave oscillator, the modulator, is connected in a very specific way.
The A input controls the amplitude of the modulation signal, we call it the modulation depth.
The units are in hertz, so the knob connected to it would be correctly labeled depth.
This is an example of using the A input to control something other than volume.
We haven't seen the O input used yet.
O stands for offset.
The signal at the O pin is added to the sine wave.
It is connected to the frequency knob and serves as the center frequency for the carrier oscillator.
You can also think of the O input as a mix input.
Here's how the new circuitry works:
The frequency knob sets the center frequency of the carrier oscillator.
It does this by sending its value straight through the O pin to the F pin on the carrier.
The modulation depth knob controls the color of the sound by adjusting the amplitude of the modulator.
The modulator causes the carrier's frequency to change very rapidly resulting in a more complex sound.
Take a moment to explore the circuit.
You can set the button to push-on-push-off to make the circuit play all the time.
The depth knob has a big effect on the sound, ranging from mellow tones at low values,
to an extremely bright sound at higher values.
Modulating the Modulator
There are two basic ways to adjust the sound quality of an FM synthesizer.
1) Adjust the modulation depth.
2) Adjust the modulation frequency.
Either adjustment can be done with an ADSR envelope.
Below, I've used an ADSR and another knob to adjust the depth.
Now when you press the button, the depth gets a little 'kick'.
|
|
The new ADSR uses the same time and trigger values we used to adjust the amplitude.
The sustain line was turned off by selecting no sustain from the property panel.
The new knob is set as a multiplier and connects to the depth knob, now set as an adder.
The multiply knob sets the range, the add knob sets the default value.
We'll see this combination often.
Multiply then Add
Any time you want to control a parameter you'll need to determine the range and the default value.
Use a multiplier to set the range, then add the default value.
To point out the importance of the range+default concept,
let's take a look at the other values in the circuit and see how we've been using it all along.
The volume knob (-10 dB) has a range of 10dB and a default value of 0.
Since the default is zero, we didn't bother to use an add knob.
The frequency knob (776 Hz) has a default value but no range, meaning it doesn't change.
So we don't need the multiply operation.
The time knob (1.46 sec) has a default value of 1.469 seconds and a range of 0.
Again, we don't need the multiply operation.
The modulator oscillator is using the A input as the range
and the O input as the default value.
We don't need separate knobs, because the oscillator does the multiply and add for us.
Modulation Frequency
The last feature we'll add to the circuit adjusts the modulation frequency.
Here's what it looks like.
|
|
|
Changing the modulation frequency dramatically effects how harmonius the sound is.
If the ratio of the F input to the O input is a whole number, 1,2,3 etc,
all of the generated overtones exact multiples of the carrier frequency,
resulting in a musical sound.
Changing the ratio to a fractional number results in non-harmonic overtones.
For long sustaining sounds, fractional ratios can be quite discordant.
When used with with a short envelope however, a fractional ratio can create
realistic bells and percussion sounds.
We adjust the F input value by inserting a multiplier driven by an ADSR.
The ADSR does the adjusting.
When it's on (button down), it's output is +1, resulting in a ratio of 1.
When the button is let up, the ratio falls down to zero,
resulting in the odd sounding frequency sweep.
Grouping
Now that we have an FM synthesizer,
let's package it so we can use it again without having to build it from scratch.
ABox calls this package a group, meaning a group of many objects that are manipulated as one.
The new object will have input and output pins just like any other object, but inside is the circuit you built.
There are several steps involved with creating a group.
The general concept is that you define inside and outside of the group by using Pin Interfaces and a Group Object.
Set the names of the pins and the group, then save the file.
The first step in building a group is to decide what input and output pins you want.
What you want to use the object for will be a major factor.
For our example, let's assume we want to use our synth as single sound source.
So we'll want a frequency input and a trigger input.
The new object will not be controlling other objects, so all we need is sound output pin.
|
|
The next step is to use Pin Interface objects to define where the pins go.
This is shown above.
The Pin Interface is a marker object, meaning that it does not do anything to the signal.
It's job is to define the border of the new object.
Each pin interface will get turned into a pin.
The letter on the object will be the name of the new pin.
Set the letter by right clicking and filling the edit boxes.
The next step is to place the Group object in the circuit.
This is also a marker object, it's job is to define the inside of the new object.
Put the group marker next to an object.
It will look at the circuit and decide which objects are inside
by using the Pin Interfaces as boundaries.
Objects that are inside are surrounded by a green border.
The last step is to define the Group's name.
Do this by right clicking on the Group and entering some text in the edit.
For the example, I used 'FM Synth'
|
|
|
All that's left is to save the circuit.
To use the new object, start with a new file, then paste file and choose the circuit you just saved.
You can also drag and drop the file into the circuit.
Do this by opening My Computer or a folder, and dragging the file from there to ABox.
|
|
|
The new object is shown as a box with the name you put in the Group object.
The input pins are on the left, the output pin in the right.
All we have to do now is connect a frequency value, trigger, and Wave Out.
|
|
|
You can look inside the group by double clicking on it.
Inside, you'll see all the objects in the FM circuit we built.
The objects that were outside the pin interfaces have been removed.
You can edit the group as well, adjust knobs, reconnect objects, add new circuitry.
You can not add new pins.
Also keep in mind that you are only editing this group.
The original file that group came from is unchanged.
You can only have one Group marker in a circuit.
You can not put Wave or Midi devices inside of groups.
You can put groups inside of groups.
Review
We've covered a lot of material in this page.
By now you should have a good understanding of how to build and control an FM synthesizer.
Some of the key points are:
You need a Wave Out object to hear the circuit play.
Oscillators generate the sound and can be used to control other objects.
Buttons create two values.
ADSR's create envelopes that can be used as control signals.
Any knob can be turned into a multiplier or an adder.
F inputs are frequency inputs and use Hz as their units.
A inputs are amplitude inputs and set the range of the output.
O inputs are offset inputs and set the default value of the output.
T inputs are time inputs.
t inputs are triggers that only respond when a signal crosses zero.
Range and default value are implemented using multiply and add operations.
FM synthesis has four components: modulator, carrier, depth, and frequency ratio.
Circuitry can be grouped together to create a new object.
Test Yourself
The following circuit shows an FM synth.
|
|
- Locate the following elements:
- Sound output
- Volume control
- Frequency control
- Modulator oscillator
- Carrier oscillator
- Modulation depth control
- What is the modulation frequency ratio of this circuit ?
- Add circuitry to adjust the depth from 1500Hz to 500Hz over a period of 1/2 second.
There are two different ways to do this.
- By adding one knob, set the modulation ratio to 1.5.
There are two ways to do this.
- Add two Pin Interfaces and a Group object so that you will get a new object with an
F input and a sound output.
Answers below.
Answers
|
1.
|
|
|
2.
|
|
The modulation frequency ratio is 2.
Adding the signal to itself is the same as multiplying by 2.
|
|
3.
|
|
Method 1.
|
|
|
The specified range is 1000Hz (1500Hz - 500Hz)
The default value can be 500Hz.
The ADSR is set as a simple ramp, with a 1/2 second length.
Press the button to start the sweep.
|
|
Method 2.
|
|
Instead of an ADSR, use a ramp wave. To get the desired values, set the ramp wave's amplitude to 1/2
and add 1/2 to the results. To get the descending ramp, make it run backwards by using -1/2 seconds.
There is a way to eliminate the 1/2 ramp amplitude and drive the modulation depth directly with the ramp wave output. See if you can find it.
|
|
4.
|
Method 1: Multiply knob before adder 0.5 + 1 = 1.5
|
|
Method 2: Multiply knob after adder 2 × 0.75 = 1.5
|
|
|
5.
|
|
|