Class TransposingSampleSustainingInstrumentWithAmplitudeMap

  extended by com.softsynth.jmsl.InstrumentAdapter
      extended by com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrument
          extended by com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrumentWithLoops
              extended by com.softsynth.jmsl.jsyn.TransposingSampleSustainingInstrument
                  extended by jmsltestsuite.TransposingSampleSustainingInstrumentWithAmplitudeMap
All Implemented Interfaces:
Editable, Instrument, Namable, OutputProvider, Transposable, AttributeBuildable, DirectorySettable, HandleSpecialXMLTag

public class TransposingSampleSustainingInstrumentWithAmplitudeMap
extends TransposingSampleSustainingInstrument

This subclass of TransposingSampleSustainingInstrument overrides getAlternativeSampleIndex() to map note 60 to three different samples based on amplitude. Notice that one sample is mapped to 60. Two additional samples are mapped to pitches 200 and 201, which we never expect to play directly. They serve as convenient places to stash alternative samples within the existing API. The logic of mapping quiet, medium, loud versions of middle c is implemented in getAlternativeSampleIndex()

Nick Didkovsky, (c) 2004 All rights reserved, Email:

Field Summary
Fields inherited from class com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrument
Constructor Summary
TransposingSampleSustainingInstrumentWithAmplitudeMap(java.lang.String dir)
Method Summary
 int getAlternativeSampleIndex(int pitchIndex, double timeStretch, double[] data)
          Precondition: pitchIndex points to a valid sample, previously loaded with addSamplePitch().
static void main(java.lang.String[] args)
Methods inherited from class com.softsynth.jmsl.jsyn.TransposingSampleSustainingInstrument
buildFromAttributes, getCrossfadeDuration, getOutput, getOutput, play, setCrossfadeDuration
Methods inherited from class com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrumentWithLoops
addSamplePitch, clear, getSampleLoopRegioner, getSampleLoopRegioners, loadSample
Methods inherited from class com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrument
addEditListener, addSamplePitch, addSamplePitch, close, edit, getDirectory, getEditEnabled, getNumChannels, getNumOutputs, getPitches, getSampleFilename, getSynthSamples, getTuning, getVoices, handleSpecialTag, notifyEditListeners, off, on, open, reload, removeEditListener, setDirectory, setEditEnabled, setNumChannels, setTuning, testSampleDirectory, writeSpecialXMLTags
Methods inherited from class com.softsynth.jmsl.InstrumentAdapter
getDimensionNameSpace, getInterpreter, getMixerClassName, getMusicDevice, getName, getTransposition, noteOff, noteOn, noteOnFor, setDimensionNameSpace, setInterpreter, setMixerClassName, setMusicDevice, setName, setTransposition, toString, update
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public TransposingSampleSustainingInstrumentWithAmplitudeMap(java.lang.String dir)
Method Detail


public int getAlternativeSampleIndex(int pitchIndex,
                                     double timeStretch,
                                     double[] data)
Precondition: pitchIndex points to a valid sample, previously loaded with addSamplePitch(). Override this method to point to a different valid sample index. For example, you might store a loud sample at pitchIndex 60 and quiet sample at index 200 (ie some pitch index you'd never bang directly), and if the amplitude of data[] < 0.3 return 200 for this pitchIndex, else return 60)
       public int getAlternativeSampleIndex(int pitchIndex, double timeStretch, double[] data) {
       double amp = data[2];
       if (pitchIndex == 60 && amp &lt 0.4) {
       return 201;
       if (pitchIndex == 60 && amp &gt 0.7) {
       return 200;
       return pitchIndex;

getAlternativeSampleIndex in class SimpleSamplePlayingInstrument
valid index to use instead of pitchIndex.


public static void main(java.lang.String[] args)