package com.softsynth.jsyn.circuits; import java.util.*; import java.awt.*; import java.applet.Applet; import com.softsynth.jsyn.*; /** * Bell generated by ring modulating two triangle waves. * Ring modulation simply involves multiplying two signals together. * * Output = Osc2.output * ( (Osc1.output * ExpLag.output) + ExpLag.output); * Osc1.Frequency = Osc2.frequency * modIndex; * * @author (C) 1997 Phil Burk, SoftSynth.com, All Rights Reserved */ public class RingModBell extends SynthNote { public TriangleOscillator osc1, osc2; public ExponentialLag expLag; public MultiplyUnit freqScalar; public MultiplyUnit ringMod; public AddUnit ampMixer; /* Declare ports. */ public SynthInput modIndex; /* Ratio of frequency of two oscillators. */ public SynthVariable halfLife; /* Decay time for exponential envelope. */ /* * Setup synthesis. */ public RingModBell() throws SynthException { /* Create various unit generators and add them to circuit. */ add( osc1 = new TriangleOscillator() ); add( osc2 = new TriangleOscillator() ); add( ampMixer = new AddUnit() ); add( expLag = new ExponentialLag() ); add( freqScalar = new MultiplyUnit() ); add( ringMod = new MultiplyUnit() ); /* Make ports on internal units appear as ports on circuit. */ addPort( amplitude = osc2.amplitude ); addPort( modIndex = freqScalar.inputB, "modIndex" ); addPort( halfLife = expLag.halfLife ); addPort( output = ringMod.output ); /* Make a virtual port that connects to several internal ports. */ /* Set signal type for frequency control so that we can operate in hertz. */ /* Use the predefined frequency port from the SynthNote class. */ frequency = new SynthDistributor( this, "frequency", Synth.SIGNAL_TYPE_OSC_FREQ ); /* Ring modulate osc1 and osc2 to get bell like sounds. * Output = Osc2.output * ( (Osc1.output * ExpLag.output) + ExpLag.output); * Osc1.Frequency = Osc2.frequency * modIndex; */ osc2.output.connect( ringMod.inputA ); ampMixer.output.connect( ringMod.inputB ); expLag.output.connect( ampMixer.inputA ); expLag.output.connect( osc1.amplitude ); osc1.output.connect( ampMixer.inputB ); frequency.connect( osc2.frequency ); frequency.connect( freqScalar.inputA ); freqScalar.output.connect( osc1.frequency ); frequency.setup(0.0, 5000.0, 10000.0 ); modIndex.set( 4.0/5.0 ); amplitude.set(0.5); halfLife.setup(0.0, 0.2, 1.0); } public void setStage( int time, int stage ) throws SynthException { switch( stage ) { case 0: double half = halfLife.get(); /* Spike up, then go down slowly. */ expLag.halfLife.set( time, 0.001 ); expLag.input.set( time, 0.5 ); expLag.halfLife.set( time + 20, half ); expLag.input.set( time + 20, 0.0 ); start( time ); break; default: break; } } }