Additive
Synthesis Introduction
This tutorial shows how sine tones can be combined to create
rich timbres.
All sounds are composed of multiple sine wave partials, often called overtones
or harmonics.
Creating sounds from the basic building block of a sine wave - additive
synthesis - allows the creation of any sound, but the process to create
complex sounds can be tedious.
This tutorial introduces this process using just a few overtones.
Heres the result:
HarmonicsTest.au[3027k]
Here's the code:
View / Download source
- Overtone Instrument source code
View / Download
source - Composition source code
Instrument class
import jm.audio.io.*; import jm.audio.synth.*; import jm.music.data.Note; import jm.audio.AudioObject;
public final class OvertoneInst extends jm.audio.Instrument{
private int channels;
private int sampleRate;
*
*
*
public OvertoneInst(int sampleRate){
this.sampleRate = sampleRate;
this.channels = 2;
}
public void createChain(){
Oscillator osc0 = new Oscillator(this, Oscillator.SINE_WAVE,
this.sampleRate, this.channels);
Volume vol0 = new Volume(osc0,(float)1.0);
Oscillator osc1 = new Oscillator(this, Oscillator.SINE_WAVE,
this.sampleRate, this.channels);
osc1.setFrqRatio((float)2.0);
Volume vol1 = new Volume(osc1,(float)0.5);
Oscillator osc2 = new Oscillator(this, Oscillator.SINE_WAVE,
this.sampleRate, this.channels);
osc2.setFrqRatio((float)3.0);
Volume vol2 = new Volume(osc2,(float)0.25);
Oscillator osc3 = new Oscillator(this, Oscillator.SINE_WAVE,
this.sampleRate, this.channels);
osc3.setFrqRatio((float)3.0);
Volume vol3 = new Volume(osc3,(float)0.025);
AudioObject[] overtones = {vol0, vol1, vol2, vol3};
Add adder = new Add(overtones);
Envelope env = new Envelope(adder, new double[] {0.0, 0.0, 0.1,
1.0, 1.0, 0.0});
StereoPan span = new StereoPan(env);
SampleOut sout = new SampleOut(span); }
}
|
All instruments in jMusic extend the Instrument class, by doing this they
inherit a great deal of automatic behaviour
that is useful but on no concern for us in this tutorial.
The code above creates four sine waves, each one at a higher frequency
- specified by the setfrqRatio() method.
Each overtone is also at a different loudness - higher frequencies are
at lower levels, as is common in natural sounds.
These harmonics are added together, passed through an amplitude envelope
object, panned as appropriate for the note,
then written to an audio file on disk.
Musical Example
import jm.JMC; import jm.music.data.*; import jm.audio.*; import jm.util.*public final class HarmonicsTest implements JMC{ public static void main(String[] args){ Score score = new Score("JMDemo - Additive synthesis test"); Part part = new Part("wave", 0); Phrase phr = new Phrase(0.0); int sampleRate = 44100; Instrument inst = new OvertoneInst(sampleRate); Note note = new Note(C4, 4.0); phr.addNote(note); part.addPhrase(phr); score.addPart(part); Write.au(score, "HarmonicsTest.au", inst); } }
|
The code above uses the instrument to render a simple jMusic score
that has just one note.
|