Ring Modulation

This tutorial shows raw modulation. It shows what happens when the output of one waveform is directly used as the amplitude for another.

Hear the result of this tutorial's music below.

View / Download source - Instrument source code

View / Download source - Testing source code

Instrument

Here is the code:
import jm.audio.io.*;
import jm.audio.synth.*;
import jm.music.data.Note;
import jm.audio.AudioObject;
 

/**
* A basic ring modulation synthesis instrument
* which is basic Amplitude Modulation
* @author Andrew Brown
*/

 
public final class RingModulationInst extends jm.audio.Instrument{
/
/----------------------------------------------
// Attributes
//----------------------------------------------
/** the sample rate passed to the instrument */

private int sampleRate;

/** the sample rate passed to the instrument */

private int channels;
 
//----------------------------------------------
// Constructor
//----------------------------------------------
/**
* Basic default constructor to set an initial
* sampling rate.
* @param sampleRate
*/

public RingModulationInst(int sampleRate){
this.sampleRate = sampleRate;
this.channels = 1;
}
 
//----------------------------------------------
// Methods
//----------------------------------------------
/**
* Initialisation method used to build the objects that
* this instrument will use.
*/

public void createChain(){
Oscillator modulator = new Oscillator(this,
Oscillator.SINE_WAVE, this.sampleRate,
this.channels);
modulator.setFrqRatio((float)2.1);
Envelope env = new Envelope(modulator,
new double[] {0.0, 0.0, 1.0, 1.0});
Oscillator carrier = new Oscillator(env,
Oscillator.SINE_WAVE, Oscillator.AMPLITUDE);
Envelope env2 = new Envelope(carrier,
new double[] {0.0, 0.0, 0.05, 1.0, 1.0, 0.0});
SampleOut sout = new SampleOut(env2);
}
}

Ring Modulation

This instrument alters (modulates) the amplitude of one waveform (the carrier) by the sample values of a second (the modulator). Ring modulation is a simple multiplication of one waveform amplitude values by another. In ring modulation the modulator output is applied directly to the input of the carrier, without any DC offset to remove negative values as done in ‘classic’ ring modulation.

Ring modulation creates a somewhat unpredictable sound, often clangourous, because neither the frequency of the carrier or modulator appear in the final output, instead sidebands (overtones) at the sum and difference frequencies appear. In this example sine waves are used. You can imagine that when more complex sounds are used the resulting timbre is even more complex.
Ring Modulation diagram

Composition Example

The following example creates a note using the RingModulationInst and outputs an audio file of it.

import jm.JMC;
import jm.music.data.*;
import jm.audio.*;
import jm.util.*;

public final class RingModTest implements JMC{
public static void main(String[] args){
Score score = new Score("JMDemo - Audio test");
Part part = new Part("wave", 0);
Phrase phr = new Phrase(0.0);
int sampleRate = 44100;
Instrument inst = new RingModulationInst(sampleRate);
 
Note note = new Note(C4, 4.0);
phr.addNote(note);
 
part.addPhrase(phr);
score.addPart(part);
Write.au(score, "RingModTest.au", inst);
}
}



jMusic Tutorial Index


© 2001 Andrew Brown