<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="MSP Synthesis Tutorial 5: Frequency Modulation">
	<previous module="msp"  name="06_synthesischapter04"></previous>
	<next module="msp" name="07_samplingchapter01"></next>
	<parent name="00_mspindex">MSP Tutorials</parent>

<setdocpatch name="05yFMSynthesis" patch="05yFMSynthesis.maxpat"/>

<h1>
	Synthesis Tutorial 5: Frequency Modulation
</h1>

	<p>
		In this tutorial, we'll look at using frequency modulation to
		generate more musical tones by applying the principle of FM to
		a synthesis algorithm that can generate complex timbres that
		vary over time.
	</p>

	<h2>
		Elements of FM synthesis
	</h2>

	<p>
		Frequency modulation (FM) has proven to be a very versatile
		and effective means of synthesizing a wide variety of musical
		tones. Because it allows for the generation of complex spectra
		that can vary over time, it is very good for emulating acoustic
		instruments. In addition, the fact that it uses very few
		oscillators to produce complex sounds makes it computationally
		efficient compared to producing the same effects with additive
		synthesis.
	</p>

	<p>
		Modulating the frequency of one wave with another wave generates
		many sidebands, resulting in many more frequencies in the output
		sound than were present in the carrier and modulator waves themselves.
		As was mentioned briefly in the previous chapter, the frequencies
		of the sidebands are determined by the relationship between the
		carrier frequency (<i>Fc</i>) and the modulator frequency
		(<i>Fm</i>); the relative strength of the different sidebands
		(which affects the timbre) is determined by the relationship
		between the modulator amplitude (<i>Am</i>) and the modulator
		frequency (<i>Fm</i>).
	</p>

	<p>
		Because of these relationships, it's possible to boil the control
		of FM synthesis down to two crucial values, which are defined
		as ratios of the pertinent parameters. One important value is
		the <i>harmonicity ratio</i>, defined as <i>Fm/Fc</i>; this
		will determine what frequencies are present in the output tone,
		and whether the frequencies have an harmonic or inharmonic
		relationship. The second important value is the <i>modulation index</i>,
		defined as <i>Am/Fm;</i> this value affects the ‘brightness’ of the
		timbre by affecting the relative strength of the partials.
	</p>


	<p>
		The frequencies of the sidebands are determined by the sum and
		difference of the carrier frequency plus and minus integer
		multiples of the modulator frequency. Thus, the frequencies
		present in an FM tone will be <i>Fc</i>, <i>Fc</i>+<i>Fm,</i>
		<i>Fc-Fm</i>, <i>Fc+2Fm</i>, <i>Fc-2Fm</i>, <i>Fc+3Fm</i>,
		<i>Fc-3Fm</i>, etc. This holds true even if the difference
		frequency turns out to be a negative number; the negative frequencies
		are heard as if they were positive. The number and strength of
		sidebands present is determined by the modulation index; the
		greater the index, the greater the number of sidebands of
		significant energy.
	</p>

	<techdetail>
		<b>Technical detail:</b> In John Chowning's article
		‘Synthesis of Complex Audio Spectra by Means of Frequency Modulation’
		and in Curtis Roads' Computer Music Tutorial, they write about
		the ratio <i>Fc/Fm</i>. However, in F.R. Moore's Elements of
		Computer Music he defines the term harmonicity ratio as <i>Fm/Fc</i>.
		The idea in all cases is the same, to express the relationship
		between the carrier and modulator frequencies as a ratio. In this
		tutorial we use Moore's definition because that way whenever the
		harmonicity ratio is an integer the result will be a harmonic
		tone with <i>Fc</i> as the fundamental.
	</techdetail>

	<h2>
		An FM subpatch: simpleFM~
	</h2>

	<p>
		The <m>simpleFM~</m> object in this tutorial patch is
		not an MSP object; it's an
		<link type="vignette" module="core" name="abstractions">abstraction</link>
		that implements the ideas of harmonicity ratio and modulation index.
	</p>

	<bullet>
		Double-click on the <m>simpleFM~</m> abstraction object
		to see its contents.
	</bullet>

<illustration><img src="images/synthesischapter05a.png"/></illustration>

	<caption>
		<i>The simpleFM~ abstraction</i>
	</caption>

	<p>
		The main asset of this abstraction is that it enables one
		to specify the carrier frequency, harmonicity ratio, and
		modulation index, and it then calculates the necessary
		modulator frequency and modulator amplitude (in the <o>*~</o>
		objects) to generate the correct FM signal. The abstraction
		is flexible in that it accepts either signals or numbers in
		its inlets, and the harmonicity ratio and modulation index
		can be typed in as arguments in the main patch.
	</p>

	<bullet>
		Close the <m>[</m><m>simpleFM~</m><m>]</m> abstraction.
	</bullet>

<br/>

	<h2>
		Producing different FM tones
	</h2>

	<p>
		In the main patch, the carrier frequency and harmonicity
		ratio are provided to <m>simpleFM~</m> as constant values,
		and the modulation index is provided as a time-varying
		signal generated by the envelope using the <o>function</o> object.
	</p>

	<p>
		Because modulation index is the main determinant of timbre
		(brightness), and because the timbre of most real sounds
		varies over time, the modulation index is a prime candidate
		to be controlled by an envelope. This timbre envelope may or
		may not correspond exactly with the amplitude of the sound,
		so in the main patch one envelope is used to control amplitude,
		and another to control brightness.
	</p>

	<p>
		Each of the presets contained in the <o>preset</o> object
		have settings to produce a different kind of FM tone, as
		described below.
	</p>

	<bullet>
		Turn audio on and click on the first preset in the <o>preset</o> object
		to recall some settings for the instrument. Click on
		the <o>button</o> to play a note. Adjust the <o>gain~</o>
		slider to a comfortable volume, as some presets are
		louder than others. To hear each of the different preset
		tones, click on a different preset in the <o>preset</o> object
		to recall the settings for the instrument, then click on
		the <o>button</o> to play a note.
	</bullet>

	<p>
		<b>Preset 1</b>. The carrier frequency is for the pitch
		C an octave below middle C. The non-integer value for
		the harmonicity ratio will cause an inharmonic set of
		partials. This inharmonic spectrum, the steady drop in
		modulation index from bright to pure, and the long
		exponential amplitude decay all combine to make a
		metallic bell-like tone.
	</p>

	<p>
		<b>Preset 2</b>. This tone is similar to the first one,
		but with a (slightly mistuned) harmonic value for the
		harmonicity ratio, so the tone is more like an electric
		piano.
	</p>

	<p>
		<b>Preset 3</b>. An ‘irrational’ (1 over the square root
		of 2) value for the harmonicity ratio, a low modulation
		index, a short duration, and a characteristic envelope
		combine to give this tone a quasi- pitched drum-like quality.
	</p>

	<p>
		<b>Preset 4</b>. In brass instruments the brightness
		is closely correlated with the loudness. So, to
		achieve a trumpet-like sound in this example the modulation
		index envelope essentially tracks the amplitude envelope.
		The amplitude envelope is also characteristic of brass
		instruments, with a slow attack and little decay. The pitch
		is G above middle C, and the harmonicity ratio is 1 for a
		fully harmonic spectrum.
	</p>

	<p>
		<b>Preset 5</b>. On the trumpet, a higher note generally
		requires a more forceful attack; so the same envelope
		applied to a shorter duration, and a carrier frequency
		for the pitch high C, emulate a staccato high trumpet
		note.
	</p>

	<p>
		<b>Preset 6</b>. The same pitch and harmonicity, but
		with a percussive attack and a low modulation index,
		give a xylophone sound.
	</p>

	<p>
		<b>Preset 7</b>. A harmonicity ratio of 4 gives a spectrum
		that emphasizes odd harmonics. This, combined with a low modulation
		index and a slow attack, produces a clarinet-like tone.
	</p>

	<p>
		<b>Preset 8</b>. Of course, the real fun of FM synthesis is
		the surreal timbres you can make by choosing unorthodox
		values for the different parameters. Here, an extreme and
		wildly fluctuating modulation index produces a sound unlike
		that produced by any acoustic object.
	</p>

	<bullet>
		You can experiment with your own envelopes and settings to
		discover new FM sounds. When you have finished, click on
		the <o>ezdac~</o> to turn audio off.
	</bullet>

	<p>
		As with amplitude modulation, frequency modulation can also
		be performed using complex tones. Sinusoids have traditionally
		been used most because they give the most predictable results,
		but many other interesting sounds can be obtained by using
		complex tones for the carrier and modulator signals.
	</p>

<h2>Summary</h2>

	<p>
		FM synthesis is an effective technique for emulating acoustic
		instrumental sounds as well as for generating unusual new sounds.
	</p>

	<p>
		The frequencies present in an FM tone are equal to the carrier
		frequency plus and minus integer multiples of the modulator
		frequency. Therefore, the harmonicity of the tone can be
		described by a single number - the ratio of the modulator and
		carrier frequencies - sometimes called the <i>harmonicity ratio.</i>
		The relative amplitude of the partials is dependent on the ratio of
		the modulator's amplitude to its frequency, known as
		the <i>modulation index</i>.
	</p>

	<p>
		In most acoustic instruments, the timbre changes over
		the course of a note, so envelope control of the
		modulation index is appropriate for producing interesting
		sounds. A non-integer harmonicity ratio yields an
		inharmonic spectrum, and when combined with a percussive
		amplitude envelope can produce drum-like and bell-like
		sounds. An integer harmonicity ratio combined with the
		proper modulation index envelope and amplitude envelope
		can produce a variety of pitched instrument sounds.
	</p>

</chapter>


