public class

SoftSynthesizer

extends Object
implements AudioSynthesizer ReferenceCountingDevice
java.lang.Object
   ↳ com.sun.media.sound.SoftSynthesizer

Class Overview

The software synthesizer class.

Summary

Nested Classes
class SoftSynthesizer.WeakAudioStream  
Constants
String INFO_DESCRIPTION
String INFO_NAME
String INFO_VENDOR
String INFO_VERSION
Fields
protected boolean agc_on
protected SoftChannel[] channels
protected boolean chorus_on
protected Object control_mutex
protected SoftChannelProxy[] external_channels
protected static final MidiDevice.Info info
protected boolean load_default_soundbank
protected boolean reverb_light
protected boolean reverb_on
protected int voiceIDCounter
protected int voice_allocation_mode
protected SoftSynthesizer.WeakAudioStream weakstream
Public Constructors
SoftSynthesizer()
Public Methods
void close()
Closes the device, indicating that the device should now release any system resources it is using.
Instrument[] getAvailableInstruments()
Obtains a list of instruments that come with the synthesizer.
MidiChannel[] getChannels()
Obtains the set of MIDI channels controlled by this synthesizer.
Soundbank getDefaultSoundbank()
Obtains the default soundbank for the synthesizer, if one exists.
MidiDevice.Info getDeviceInfo()
Obtains information about the device, including its Java class and Strings containing its name, vendor, and description.
AudioFormat getFormat()
Obtains the current format (encoding, sample rate, number of channels, etc.) of the synthesizer audio data.
long getLatency()
Obtains the processing latency incurred by this synthesizer, expressed in microseconds.
Instrument[] getLoadedInstruments()
Obtains a list of the instruments that are currently loaded onto this Synthesizer.
int getMaxPolyphony()
Obtains the maximum number of notes that this synthesizer can sound simultaneously.
int getMaxReceivers()
Obtains the maximum number of MIDI IN connections available on this MIDI device for receiving MIDI data.
int getMaxTransmitters()
Obtains the maximum number of MIDI OUT connections available on this MIDI device for transmitting MIDI data.
long getMicrosecondPosition()
Obtains the current time-stamp of the device, in microseconds.
AudioSynthesizerPropertyInfo[] getPropertyInfo(Map<StringObject> info)
Gets information about the possible properties for the synthesizer.
Receiver getReceiver()
Obtains a MIDI IN receiver through which the MIDI device may receive MIDI data.
Receiver getReceiverReferenceCounting()
Retrieve a Receiver that opens the device implicitly.
List<Receiver> getReceivers()
Returns all currently active, non-closed receivers connected with this MidiDevice.
Transmitter getTransmitter()
Obtains a MIDI OUT connection from which the MIDI device will transmit MIDI data The returned transmitter must be closed when the application has finished using it.
Transmitter getTransmitterReferenceCounting()
Retrieve a Transmitter that opens the device implicitly.
List<Transmitter> getTransmitters()
Returns all currently active, non-closed transmitters connected with this MidiDevice.
VoiceStatus[] getVoiceStatus()
Obtains the current status of the voices produced by this synthesizer.
boolean isOpen()
Reports whether the device is open.
boolean isSoundbankSupported(Soundbank soundbank)
Informs the caller whether this synthesizer is capable of loading instruments from the specified soundbank.
boolean loadAllInstruments(Soundbank soundbank)
Loads onto the Synthesizer all instruments contained in the specified Soundbank.
boolean loadInstrument(Instrument instrument)
Makes a particular instrument available for synthesis.
boolean loadInstruments(Soundbank soundbank, Patch[] patchList)
Loads the instruments referenced by the specified patches, from the specified Soundbank.
void open()
Opens the device, indicating that it should now acquire any system resources it requires and become operational.
void open(SourceDataLine line, Map<StringObject> info)
Opens the synthesizer and starts rendering audio into SourceDataLine.
AudioInputStream openStream(AudioFormat targetFormat, Map<StringObject> info)
Opens the synthesizer and renders audio into returned AudioInputStream.
boolean remapInstrument(Instrument from, Instrument to)
Remaps an instrument.
void unloadAllInstruments(Soundbank soundbank)
Unloads all instruments contained in the specified Soundbank.
void unloadInstrument(Instrument instrument)
Unloads a particular instrument.
void unloadInstruments(Soundbank soundbank, Patch[] patchList)
Unloads the instruments referenced by the specified patches, from the MIDI sound bank specified.
Protected Methods
SoftInstrument findInstrument(int program, int bank, int channel)
float getControlRate()
int getDeviceID()
int getGeneralMidiMode()
SoftMainMixer getMainMixer()
SoftTuning getTuning(Patch patch)
int getVoiceAllocationMode()
SoftVoice[] getVoices()
void removeReceiver(Receiver recv)
void setGeneralMidiMode(int gmmode)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.sun.media.sound.AudioSynthesizer
From interface com.sun.media.sound.ReferenceCountingDevice
From interface javax.sound.midi.MidiDevice
From interface javax.sound.midi.Synthesizer

Constants

protected static final String INFO_DESCRIPTION

Constant Value: "Software MIDI Synthesizer"

protected static final String INFO_NAME

Constant Value: "Gervill"

protected static final String INFO_VENDOR

Constant Value: "OpenJDK"

protected static final String INFO_VERSION

Constant Value: "1.0"

Fields

protected boolean agc_on

protected SoftChannel[] channels

protected boolean chorus_on

protected Object control_mutex

protected SoftChannelProxy[] external_channels

protected static final MidiDevice.Info info

protected boolean load_default_soundbank

protected boolean reverb_light

protected boolean reverb_on

protected int voiceIDCounter

protected int voice_allocation_mode

protected SoftSynthesizer.WeakAudioStream weakstream

Public Constructors

public SoftSynthesizer ()

Public Methods

public void close ()

Closes the device, indicating that the device should now release any system resources it is using.

All Receiver and Transmitter instances open from this device are closed. This includes instances retrieved via MidiSystem.

public Instrument[] getAvailableInstruments ()

Obtains a list of instruments that come with the synthesizer. These instruments might be built into the synthesizer, or they might be part of a default soundbank provided with the synthesizer, etc.

Note that you don't use this method to find out which instruments are currently loaded onto the synthesizer; for that purpose, you use getLoadedInstruments(). Nor does the method indicate all the instruments that can be loaded onto the synthesizer; it only indicates the subset that come with the synthesizer. To learn whether another instrument can be loaded, you can invoke isSoundbankSupported(), and if the instrument's Soundbank is supported, you can try loading the instrument.

Returns
  • list of available instruments. If the synthesizer has no instruments coming with it, an array of length 0 is returned.

public MidiChannel[] getChannels ()

Obtains the set of MIDI channels controlled by this synthesizer. Each non-null element in the returned array is a MidiChannel that receives the MIDI messages sent on that channel number.

The MIDI 1.0 specification provides for 16 channels, so this method returns an array of at least 16 elements. However, if this synthesizer doesn't make use of all 16 channels, some of the elements of the array might be null, so you should check each element before using it.

Returns
  • an array of the MidiChannel objects managed by this Synthesizer. Some of the array elements may be null.

public Soundbank getDefaultSoundbank ()

Obtains the default soundbank for the synthesizer, if one exists. (Some synthesizers provide a default or built-in soundbank.) If a synthesizer doesn't have a default soundbank, instruments must be loaded explicitly from an external soundbank.

Returns
  • default soundbank, or null if one does not exist.

public MidiDevice.Info getDeviceInfo ()

Obtains information about the device, including its Java class and Strings containing its name, vendor, and description.

Returns
  • device info

public AudioFormat getFormat ()

Obtains the current format (encoding, sample rate, number of channels, etc.) of the synthesizer audio data.

If the synthesizer is not open and has never been opened, it returns the default format.

Returns
  • current audio data format

public long getLatency ()

Obtains the processing latency incurred by this synthesizer, expressed in microseconds. This latency measures the worst-case delay between the time a MIDI message is delivered to the synthesizer and the time that the synthesizer actually produces the corresponding result.

Although the latency is expressed in microseconds, a synthesizer's actual measured delay may vary over a wider range than this resolution suggests. For example, a synthesizer might have a worst-case delay of a few milliseconds or more.

Returns
  • the worst-case delay, in microseconds

public Instrument[] getLoadedInstruments ()

Obtains a list of the instruments that are currently loaded onto this Synthesizer.

Returns
  • a list of currently loaded instruments

public int getMaxPolyphony ()

Obtains the maximum number of notes that this synthesizer can sound simultaneously.

Returns
  • the maximum number of simultaneous notes

public int getMaxReceivers ()

Obtains the maximum number of MIDI IN connections available on this MIDI device for receiving MIDI data.

Returns
  • maximum number of MIDI IN connections, or -1 if an unlimited number of connections is available.

public int getMaxTransmitters ()

Obtains the maximum number of MIDI OUT connections available on this MIDI device for transmitting MIDI data.

Returns
  • maximum number of MIDI OUT connections, or -1 if an unlimited number of connections is available.

public long getMicrosecondPosition ()

Obtains the current time-stamp of the device, in microseconds. If a device supports time-stamps, it should start counting at 0 when the device is opened and continue incrementing its time-stamp in microseconds until the device is closed. If it does not support time-stamps, it should always return -1.

Returns
  • the current time-stamp of the device in microseconds, or -1 if time-stamping is not supported by the device.

public AudioSynthesizerPropertyInfo[] getPropertyInfo (Map<StringObject> info)

Gets information about the possible properties for the synthesizer.

Parameters
info a proposed list of tag/value pairs that will be sent on open.
Returns
  • an array of AudioSynthesizerPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required.

public Receiver getReceiver ()

Obtains a MIDI IN receiver through which the MIDI device may receive MIDI data. The returned receiver must be closed when the application has finished using it.

Obtaining a Receiver with this method does not open the device. To be able to use the device, it has to be opened explicitly by calling open(). Also, closing the Receiver does not close the device. It has to be closed explicitly by calling close().

Returns
  • a receiver for the device.

public Receiver getReceiverReferenceCounting ()

Retrieve a Receiver that opens the device implicitly. This method is similar to MidiDevice.getReceiver(). However, by calling this one, the device is opened implicitly. This is needed by MidiSystem.getReceiver().

public List<Receiver> getReceivers ()

Returns all currently active, non-closed receivers connected with this MidiDevice. A receiver can be removed from the device by closing it.

Returns
  • an unmodifiable list of the open receivers

public Transmitter getTransmitter ()

Obtains a MIDI OUT connection from which the MIDI device will transmit MIDI data The returned transmitter must be closed when the application has finished using it.

Obtaining a Transmitter with this method does not open the device. To be able to use the device, it has to be opened explicitly by calling open(). Also, closing the Transmitter does not close the device. It has to be closed explicitly by calling close().

Returns
  • a MIDI OUT transmitter for the device.

public Transmitter getTransmitterReferenceCounting ()

Retrieve a Transmitter that opens the device implicitly. This method is similar to MidiDevice.getTransmitter(). However, by calling this one, the device is opened implicitly. This is needed by MidiSystem.getTransmitter().

public List<Transmitter> getTransmitters ()

Returns all currently active, non-closed transmitters connected with this MidiDevice. A transmitter can be removed from the device by closing it.

Returns
  • an unmodifiable list of the open transmitters

public VoiceStatus[] getVoiceStatus ()

Obtains the current status of the voices produced by this synthesizer. If this class of Synthesizer does not provide voice information, the returned array will always be of length 0. Otherwise, its length is always equal to the total number of voices, as returned by getMaxPolyphony(). (See the VoiceStatus class description for an explanation of synthesizer voices.)

Returns
  • an array of VoiceStatus objects that supply information about the corresponding synthesizer voices

public boolean isOpen ()

Reports whether the device is open.

Returns
  • true if the device is open, otherwise false

public boolean isSoundbankSupported (Soundbank soundbank)

Informs the caller whether this synthesizer is capable of loading instruments from the specified soundbank. If the soundbank is unsupported, any attempts to load instruments from it will result in an IllegalArgumentException.

Parameters
soundbank soundbank for which support is queried
Returns
  • true if the soundbank is supported, otherwise false

public boolean loadAllInstruments (Soundbank soundbank)

Loads onto the Synthesizer all instruments contained in the specified Soundbank.

Parameters
soundbank the Soundbank whose are instruments are to be loaded
Returns
  • true if the instruments are all successfully loaded (or already had been), false if any instrument could not be loaded (for example, if the Synthesizer had insufficient memory)

public boolean loadInstrument (Instrument instrument)

Makes a particular instrument available for synthesis. This instrument is loaded into the patch location specified by its Patch object, so that if a program-change message is received (or has been received) that causes that patch to be selected, subsequent notes will be played using the sound of instrument. If the specified instrument is already loaded, this method does nothing and returns true.

The instrument must be part of a soundbank that this Synthesizer supports. (To make sure, you can use the getSoundbank method of Instrument and the isSoundbankSupported method of Synthesizer.)

Parameters
instrument instrument to load
Returns
  • true if the instrument is successfully loaded (or already had been), false if the instrument could not be loaded (for example, if the synthesizer has insufficient memory to load it)

public boolean loadInstruments (Soundbank soundbank, Patch[] patchList)

Loads the instruments referenced by the specified patches, from the specified Soundbank. Each of the Patch objects indicates a bank and program number; the Instrument that has the matching Patch is loaded into that bank and program location.

Parameters
soundbank the Soundbank containing the instruments to load
patchList list of patches for which instruments should be loaded
Returns
  • true if the instruments are all successfully loaded (or already had been), false if any instrument could not be loaded (for example, if the Synthesizer had insufficient memory)

public void open ()

Opens the device, indicating that it should now acquire any system resources it requires and become operational.

An application opening a device explicitly with this call has to close the device by calling close(). This is necessary to release system resources and allow applications to exit cleanly.

Note that some devices, once closed, cannot be reopened. Attempts to reopen such a device will always result in a MidiUnavailableException.

public void open (SourceDataLine line, Map<StringObject> info)

Opens the synthesizer and starts rendering audio into SourceDataLine.

An application opening a synthesizer explicitly with this call has to close the synthesizer by calling close(). This is necessary to release system resources and allow applications to exit cleanly.

Note that some synthesizers, once closed, cannot be reopened. Attempts to reopen such a synthesizer will always result in a MidiUnavailableException.

Parameters
line which AudioSynthesizer writes output audio into. If line is null, then line from system default mixer is used.
info a Map object containing properties for additional configuration supported by synthesizer. If info is null then default settings are used.

public AudioInputStream openStream (AudioFormat targetFormat, Map<StringObject> info)

Opens the synthesizer and renders audio into returned AudioInputStream.

An application opening a synthesizer explicitly with this call has to close the synthesizer by calling close(). This is necessary to release system resources and allow applications to exit cleanly.

Note that some synthesizers, once closed, cannot be reopened. Attempts to reopen such a synthesizer will always result in a MidiUnavailableException.

Parameters
targetFormat specifies the AudioFormat used in returned AudioInputStream.
info a Map object containing properties for additional configuration supported by synthesizer. If info is null then default settings are used.

public boolean remapInstrument (Instrument from, Instrument to)

Remaps an instrument. Instrument to takes the place of instrument from.
For example, if from was located at bank number 2, program number 11, remapping causes that bank and program location to be occupied instead by to.
If the function succeeds, instrument from is unloaded.

To cancel the remapping reload instrument from by invoking one of loadInstrument(Instrument), loadInstruments(Soundbank, Patch[]) or loadAllInstruments(Soundbank).

Parameters
from the Instrument object to be replaced
to the Instrument object to be used in place of the old instrument, it should be loaded into the synthesizer
Returns
  • true if the instrument succeessfully remapped, false if feature is not implemented by synthesizer

public void unloadAllInstruments (Soundbank soundbank)

Unloads all instruments contained in the specified Soundbank.

Parameters
soundbank soundbank containing instruments to unload

public void unloadInstrument (Instrument instrument)

Unloads a particular instrument.

Parameters
instrument instrument to unload

public void unloadInstruments (Soundbank soundbank, Patch[] patchList)

Unloads the instruments referenced by the specified patches, from the MIDI sound bank specified.

Parameters
soundbank soundbank containing instruments to unload
patchList list of patches for which instruments should be unloaded

Protected Methods

protected SoftInstrument findInstrument (int program, int bank, int channel)

protected float getControlRate ()

protected int getDeviceID ()

protected int getGeneralMidiMode ()

protected SoftMainMixer getMainMixer ()

protected SoftTuning getTuning (Patch patch)

protected int getVoiceAllocationMode ()

protected SoftVoice[] getVoices ()

protected void removeReceiver (Receiver recv)

protected void setGeneralMidiMode (int gmmode)