audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> Audio > Synthesis > Additive Synthesis Introduction    
 
   

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;
/**
* A basic additive synthesis instrument implementation
* which includes sine waves as overtones.
* @author Andrew R. Brown
*/
public final class OvertoneInst extends jm.audio.Instrument{   //---------------------------------------------- // Attributes //---------------------------------------------- /** The number of channels */ private int channels; /** the sample rate passed to the instrument */ private int sampleRate; /** * A constructor to set an initial * sampling rate and number of channels. * @param sampleRate */ public OvertoneInst(int sampleRate){ this.sampleRate = sampleRate; this.channels = 2; } //---------------------------------------------- // Methods //---------------------------------------------- /** * Initialisation method used to build the objects that * this instrument will use */ public void createChain(){ // fundamental Oscillator osc0 = new Oscillator(this, Oscillator.SINE_WAVE, this.sampleRate, this.channels); Volume vol0 = new Volume(osc0,(float)1.0); // 1st harmonic 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); // 2nd harmonic 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); // 3nd harmonic 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); // add them together 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.

 

 
 

jMusic Australia Council Queensland University of Technology Sitemap Contact Home Home http://www.qut.com http://explodingart.com/jmusic http://www.ozco.gov.au

Digital Instrument making Home