JMSL Tutorial: JSyn and JMSL, using a common clock

JMSL offers tight integration with JSyn, which allows JMSL to use JSyn as a highly controllable sound engine. 
JMSL's JSynMusicDevice and other support classes hide the details discussed below, but we show you what's under the hood so you can get a better understanding of how JMSL and JSyn integrate.

If you just want to learn how to make sound with a JSyn SynthNote using JMSL, skip to the next tutorial. Otherwise read on.

Converting from JMSL time to JSyn time
Recall that JMSL schedules its Composables with time measured as a Java double, where 1.0 equals 1 second.  JSyn uses a clock with integer "ticks" (where 1 is a tiny fraction of a second).  Therefore, JMSL Composables that want to bang JSyn units need to convert their playTime to JSyn time.  JMSL's SynthClock allows for this.

* To tell JMSL to use a native JSyn clock, we do the following:

        JMSL.clock = new com.softsynth.jmsl.jsyn.SynthClock();

* To convert from JMSL time to JSyn time follow this example:
                
// Convert JMSL's playTime to a time usable by JSyn
...
int onTime = (int) JMSL.clock.timeToNative(playTime);
int offTime = (int) JMSL.clock.timeToNative(playTime + someDuration);
someCircuit.somePort.set(onTime, someValue);
someCircuit.somePort.set(offTime, someOtherValue);
Note that another way to calculate a future time (like offTime above) would be to convert the duration to native ticks and add to onTime, like so:
int onTime = (int) JMSL.clock.timeToNative(playTime);
int offTime = onTime + (int) ( JMSL.clock.getNativeRate() * someDuration );
...etc...


To summarize, the conversion of JMSL time to JSyn time requires:

  1. that JMSL's clock is a com.softsynth.jmsl.jsyn.SynthClock, and
  2. that JMSL Time is converted to JSyn time by JMSL.clock.timeToNative()
However, as the next lesson shows, JSynMusicDevice handles the SynthClock initialization automatically when it is open()'ed.
JSynInsFromClassName handles time conversion automatically when it bangs a JSyn SynthNote.  Read on...




Previous Tutorial Index Tutorial Contents Next
  (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved
  JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.