audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> Audio > Synthesis > Spectral Morphing    
 
   

Spectral Morphing

This tutorial shows how dynamic timbres can be generated by changing the balance between overtones with amplitude envelopes.
The result in this simple example is like a cross-fade between two samples.
It will indicate how  elaborate dynamic sprectra can be created by envelope control over partial loudness.

View / Download source - Instrument source code

View / Download source - Composition source code

The instrument class
 

import jm.audio.io.*;
import jm.audio.synth.*;
import jm.music.data.Note;
import jm.audio.Instrument;
/** * An additive synthesis instrument implementation * which cross fades two different spectra, each * with five partials. * @author Andrew R. Brown */ public final class AddMorphInst extends Instrument{ //---------------------------------------------- // Attributes //---------------------------------------------- private int overtones = 10; /** the relative frequencies which make up this note */ private double[] freqVals = {1.0, 3.0, 5.0, 7.0, 9.0, 1.0, 2.8, 5.6, 8.4, 11.0}; /** the volumes to use for each frequency */ private double[] volVals = {1.0, 0.7, 0.5, 0.3, 0.2, 1.0, 0.7, 0.5, 0.3, 0.2}; /** The points to use in the construction of Envelopes */ private double[][] points = new double[overtones][6]; private double[] pointArray1 = {0.0, 0.0, 0.02, 1.0, 1.0, 0.0}; private double[] pointArray2 = {0.0, 0.0, 0.98, 1.0, 1.0, 0.0}; /** Pan */ private float pan; /** The sample Rate to use */ private int sampleRate; /** The Oscillators to use for each frequency specified */ private Oscillator[] osc; /** The envelope to apply to each Oscillator's output */ private Envelope[] env; /** The volume to apply to each envelopes output */ private Volume[] vol; //---------------------------------------------- // Constructor //---------------------------------------------- public AddMorphInst(int sampleRate){ this.sampleRate = sampleRate; // set up envelope points for (int i=0; i<5; i++) { points[i] = pointArray1; } for (int i=5; i<10; i++) { points[i] = pointArray2; } } //---------------------------------------------- // Methods //---------------------------------------------- /** * Initialisation method is used to build the objects that * this instrument will use */ public void createChain(){ //define the audio chain(s) osc = new Oscillator[overtones]; env = new Envelope[overtones]; vol = new Volume[overtones]; for(int i=0;i //And now the add object brings us back to one path. Add add = new Add(vol); StereoPan span = new StereoPan(add); SampleOut sout = new SampleOut(span); } }



Ten partials (overtones) are declared, the first five are for one timbre and the other five for a second timbre.
Two envelopes are used, one with a quick attack followed by a decay applied to the first five partials, the other the reverse,
a slow attack leading to a fast release which is applied to the other five partials.
The assigning of envelopes to partials is done in the two for-loops in the constructor.

The first five partials have frequency ratios (with the fundamental) that are simple odd multiples, thus the sound is somewhat like a square wave or clarinet.
The later five partials have ratios that result in inharmonic frequencies which produces a sharsher bell-like timbre
(but, of course, without the attack).
The resulting sound shifts fro one timbre to the other as the amplitude of the partial sets shifts,
resulting is a morphing or cross-fade between the two spectra.

Musical Example

import jm.JMC;
import jm.music.data.*;
import jm.audio.*;
import jm.util.*;
public final class AddMorphTest implements JMC{
	public static void main(String[] args){
		Score score = new Score("JMDemo - Additive Synthesis test");
		Part part = new Part("Spectra Notes", 0);
		Phrase phr = new Phrase(0.0);
		int sampleRate = 44100;
		Instrument inst = new AddMorphInst(sampleRate);
		Note note = new Note(C3, 8.0);
		phr.addNote(note);
		part.addPhrase(phr);
		score.addPart(part);
		Write.au(score, "AddMorphTest.au", inst);
	}
}


The code above uses the instrument to render a simple jMusic score.

 

 

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