Java Music Specification Language
DEVELOPERS' NOTES
MIGRATING TO THE NEW PURE JAVA JSYN
JSyn (Java Synthesizer) is a software synthesis API written in Java by Phil Burk (who is also a JMSL co-author). JMSL has always offered good support for JSyn and continues to do so now.
The first release of JSyn was implemented with a Java Native Interface (JNI) layer that communicated with a native synthesis library written in C.
Audio synthesis was fast, but every hardware/OS platform needed its own native library. More recently, Phil Burk developed a version of JSyn which runs in pure Java with a new API. Happily, JMSL takes advantage of the new pure Java JSyn! This section will show you how to migrate some key ideas from the old JSyn to the new.
JMSL continues to support both the older and new new pure Java versions of JSyn, so existing pieces written in JMSL+JSyn won't break.
JMSL support for the new pure Java JSyn is in the package com.softsynth.jmsl.jsyn2
IMPORTANT: all your old JSyn+JMSL will still work if you add jsyn-old-api-20161206.jar to your classpath!!! They will run in pure Java. The new JSyn API has a number of advantages however (such as token based voice allocation and retrieval),
so in the table below, we show how older techniques can be done in the new JSyn2+JMSL environment.
JMSL support comparison: old JSyn versus new JSyn | ||
---|---|---|
Resource or technique | Old JSyn | New JSyn |
Jar file needed in classpath: | jsyn-old-api-20161206.jar This Jar file is included in the JMSL distribution in the "lib" directory |
jsyn-20171016.jar This Jar file is included in the JMSL distribution in the "lib" directory |
Music device to import: | com.softsynth.jmsl.jsyn.JSynMusicDevice | com.softsynth.jmsl.jsyn2.JSynMusicDevice |
Simple 4 dimensional JSyn Instrument: | com.softsynth.jmsl.jsyn.JSynInsFromClassName ins = new JSynInsFromClassName(int maxVoices, String synthNoteClassName) | com.softsynth.jmsl.jsyn.com.softsynth.jmsl.jsyn2.JSynUnitVoiceInstrument ins = new JSynUnitVoiceInstrument(int polyphony, String unitVoiceClassName) If you want to limit the use of this to four elements (dur, pitch, amp, hold), then create a standard 4-dimensional MusicShape and set its instrument to this object, like so: MusicShape naiveMusicShape = new MusicShape(4); naiveMusicShape.useStandardDimensionNameSpace(); naiveMusicShape.setInstrument(ins); Important: unitVoiceClassName must be a new JSyn UnitVoice, not an old SynthNote! Note there is another constructor whose third parameter is a preset id, which is also new to JSyn Source Code Example |
Multidimensional JSyn Instrument: | com.softsynth.jmsl.jsyn.SynthNoteAllPortsInstrument ins = new SynthNoteAllPortsInstrument (int maxVoices, String synthNoteClassName) | com.softsynth.jmsl.jsyn.com.softsynth.jmsl.jsyn2.JSynUnitVoiceInstrument ins = new JSynUnitVoiceInstrument(int polyphony, String unitVoiceClassName) Important: unitVoiceClassName must be a new JSyn UnitVoice, not an old SynthNote! Source Code Example 1 Source Code Example 2 |
Signal Processing Instrument: | SynthNoteAllPortsInstrumentSP ins = new SynthNoteAllPortsInstrumentSP(int maxVoices, String className) ins.addSignalSource(Object signalSource); Note that the signalSource Object must be a SynthOutput |
JSynUnitVoiceInstrument signalProcessingIns = new JSynUnitVoiceInstrument((int polyphony, String unitVoiceClassName)); signalProcessingIns.addSignalSource(ins.getOutput()); With old JSyn, signal processing instruments were a different subclass. In new JSyn support, if unitVoice instanceof UnitSink then this automatically is a signal processing instrument. Note also that addSignalSource expects a UnitOutputPort Source Code Example 1 Source Code Example 2 |
Keeping track of and updating an allocated voice: | SynthNoteAllPortswInstrument's on() method returns a SynthNote object which is the allocated voice. It cannot be used to call update() or turn off() the instrument, unfortunately. Instead, update() and off() look up the allocated voice using the pitch passed to on(), which is hashed to the SynthNote returned by on(). If you want to change pitch in update and off(), you had to specify a different dimension in the double[] passed to on() that would provide a unique lookup. | JSynUnitVoiceInstrument's on() method returns an Integer object which contains the integer voicetoken which can be used to reference the allocated voice for update() and off() Object obj = ins.on(double playTime, double timeStretch, double dar[]); int voiceToken = ((Integer)obj).intValue(); ins.update(double playTime, double timeStretch, double dar[], int voiceToken); ins.off(double playTime, int voiceToken); Source Code Example 1 Source Code Example 2 |