com.jsyn.engine
Class SynthesisEngine

java.lang.Object
  extended by com.jsyn.engine.SynthesisEngine
All Implemented Interfaces:
Synthesizer, java.lang.Runnable

public class SynthesisEngine
extends java.lang.Object
implements java.lang.Runnable, Synthesizer

Internal implementation of JSyn Synthesizer. The public API is in the Synthesizer interface. This class might be used directly internally.

See Also:
Synthesizer

Field Summary
static int BUILD_NUMBER
           
static double DB96
           
static int DEFAULT_FRAME_RATE
           
static java.lang.String VERSION_TEXT
           
 
Fields inherited from interface com.jsyn.Synthesizer
FRAMES_PER_BLOCK
 
Constructor Summary
SynthesisEngine()
           
 
Method Summary
 void add(UnitGenerator ugen)
          Add a unit generator to the synthesizer so it can be played.
 void addBlockTask(java.lang.Runnable blockTask)
           
 void autoStopUnit(UnitGenerator unitGenerator)
           
static short convertDoubleToShort(double d)
           
static double convertShortToDouble(short sdata)
           
 double convertTimeToExponentialScaler(double duration)
           
 TimeStamp createTimeStamp()
          Create a TimeStamp using the current audio time.
 void generateNextBlock()
           
 AudioDeviceManager getAudioDeviceManager()
          An AudioDeviceManager is an interface to audio hardware.
 double getCurrentTime()
           
 long getFrameCount()
           
 double getFramePeriod()
           
 int getFrameRate()
           
 double[] getInputBuffer(int i)
           
 double getInputLatency()
           
 double getInverseNyquist()
           
 double[] getOutputBuffer(int i)
           
 double getOutputLatency()
           
 double getUsage()
           
 java.lang.String getVersion()
           
 int getVersionCode()
           
 boolean isPullDataEnabled()
           
 boolean isRealTime()
          Is JSyn running in real-time mode?
 void queueCommand(ScheduledCommand command)
           
 void remove(UnitGenerator ugen)
           
 void removeBlockTask(java.lang.Runnable blockTask)
           
 void run()
           
 void scheduleCommand(double time, ScheduledCommand command)
           
 void scheduleCommand(TimeStamp timeStamp, ScheduledCommand command)
          Send a command to be processed in the background audio thread.
 void setPullDataEnabled(boolean pullDataEnabled)
          If set true then audio data will be pulled from the output ports of connected unit generators.
 void setRealTime(boolean realTime)
          If set true then the synthesizer will generate audio in real-time.
 void sleepFor(double duration)
          Sleep for the specified audio time duration.
 void sleepUntil(double time)
          Sleep until the specified audio time is reached.
 void start()
          Begin generating audio using default frame rate of 44100 and two stereo output channels.
 void start(int frameRate, int inputDeviceID, int numInputChannels, int outputDeviceID, int numOutputChannels)
           
 void startUnit(UnitGenerator unit)
          Start a unit generator now.
 void startUnit(UnitGenerator unit, double time)
          Start a unit generator at the specified time.
 void startUnit(UnitGenerator unit, TimeStamp timeStamp)
           
 void stop()
          Stop generating audio.
 void stopUnit(UnitGenerator unit)
           
 void stopUnit(UnitGenerator unit, double time)
           
 void stopUnit(UnitGenerator unit, TimeStamp timeStamp)
           
 void terminate()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BUILD_NUMBER

public static final int BUILD_NUMBER
See Also:
Constant Field Values

VERSION_TEXT

public static final java.lang.String VERSION_TEXT

DEFAULT_FRAME_RATE

public static final int DEFAULT_FRAME_RATE
See Also:
Constant Field Values

DB96

public static final double DB96
See Also:
Constant Field Values
Constructor Detail

SynthesisEngine

public SynthesisEngine()
Method Detail

getVersion

public java.lang.String getVersion()
Specified by:
getVersion in interface Synthesizer
Returns:
version as a string.

getVersionCode

public int getVersionCode()
Specified by:
getVersionCode in interface Synthesizer
Returns:
version as an integer that only gets bigger.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isPullDataEnabled

public boolean isPullDataEnabled()

setPullDataEnabled

public void setPullDataEnabled(boolean pullDataEnabled)
If set true then audio data will be pulled from the output ports of connected unit generators. The final unit in a tree of units needs to be start()ed.

Parameters:
pullDataEnabled -

terminate

public void terminate()

start

public void start()
Description copied from interface: Synthesizer
Begin generating audio using default frame rate of 44100 and two stereo output channels.

Specified by:
start in interface Synthesizer

start

public void start(int frameRate,
                  int inputDeviceID,
                  int numInputChannels,
                  int outputDeviceID,
                  int numOutputChannels)
Specified by:
start in interface Synthesizer

stop

public void stop()
Description copied from interface: Synthesizer
Stop generating audio.

Specified by:
stop in interface Synthesizer

run

public void run()
Specified by:
run in interface java.lang.Runnable

generateNextBlock

public void generateNextBlock()

getCurrentTime

public double getCurrentTime()
Specified by:
getCurrentTime in interface Synthesizer
Returns:
the current audio time in seconds.

createTimeStamp

public TimeStamp createTimeStamp()
Description copied from interface: Synthesizer
Create a TimeStamp using the current audio time.

Specified by:
createTimeStamp in interface Synthesizer

scheduleCommand

public void scheduleCommand(TimeStamp timeStamp,
                            ScheduledCommand command)
Description copied from interface: Synthesizer
Send a command to be processed in the background audio thread.

Specified by:
scheduleCommand in interface Synthesizer

scheduleCommand

public void scheduleCommand(double time,
                            ScheduledCommand command)
Specified by:
scheduleCommand in interface Synthesizer

queueCommand

public void queueCommand(ScheduledCommand command)
Specified by:
queueCommand in interface Synthesizer

getInputBuffer

public double[] getInputBuffer(int i)

getOutputBuffer

public double[] getOutputBuffer(int i)

autoStopUnit

public void autoStopUnit(UnitGenerator unitGenerator)

startUnit

public void startUnit(UnitGenerator unit,
                      double time)
Description copied from interface: Synthesizer
Start a unit generator at the specified time. This is not needed if a unit generator's output is connected to other units. Typically you only need to start units that have no outputs, for example LineOut.

Specified by:
startUnit in interface Synthesizer

stopUnit

public void stopUnit(UnitGenerator unit,
                     double time)
Specified by:
stopUnit in interface Synthesizer

startUnit

public void startUnit(UnitGenerator unit,
                      TimeStamp timeStamp)
Specified by:
startUnit in interface Synthesizer

stopUnit

public void stopUnit(UnitGenerator unit,
                     TimeStamp timeStamp)
Specified by:
stopUnit in interface Synthesizer

startUnit

public void startUnit(UnitGenerator unit)
Description copied from interface: Synthesizer
Start a unit generator now.

Specified by:
startUnit in interface Synthesizer

stopUnit

public void stopUnit(UnitGenerator unit)
Specified by:
stopUnit in interface Synthesizer

getInverseNyquist

public double getInverseNyquist()

convertTimeToExponentialScaler

public double convertTimeToExponentialScaler(double duration)

getFrameCount

public long getFrameCount()

getFrameRate

public int getFrameRate()
Specified by:
getFrameRate in interface Synthesizer
Returns:
the frameRate

getFramePeriod

public double getFramePeriod()
Specified by:
getFramePeriod in interface Synthesizer
Returns:
the inverse of the frameRate for efficiency

convertShortToDouble

public static double convertShortToDouble(short sdata)

convertDoubleToShort

public static short convertDoubleToShort(double d)

addBlockTask

public void addBlockTask(java.lang.Runnable blockTask)

removeBlockTask

public void removeBlockTask(java.lang.Runnable blockTask)

getUsage

public double getUsage()
Specified by:
getUsage in interface Synthesizer
Returns:
the current CPU usage as a fraction between 0.0 and 1.0.

getAudioDeviceManager

public AudioDeviceManager getAudioDeviceManager()
Description copied from interface: Synthesizer
An AudioDeviceManager is an interface to audio hardware. It might be implemented using JavaSound or a wrapper around PortAudio.

Specified by:
getAudioDeviceManager in interface Synthesizer
Returns:
audio device manager being used by the synthesizer.

setRealTime

public void setRealTime(boolean realTime)
Description copied from interface: Synthesizer
If set true then the synthesizer will generate audio in real-time. Set it true for live audio. If false then JSyn will run in non-real-time mode. This can be used to generate audio to be written to a file. The default is true.

Specified by:
setRealTime in interface Synthesizer

isRealTime

public boolean isRealTime()
Description copied from interface: Synthesizer
Is JSyn running in real-time mode?

Specified by:
isRealTime in interface Synthesizer

getOutputLatency

public double getOutputLatency()

getInputLatency

public double getInputLatency()

add

public void add(UnitGenerator ugen)
Description copied from interface: Synthesizer
Add a unit generator to the synthesizer so it can be played. This is required before starting or connecting a ugen into a network.

Specified by:
add in interface Synthesizer

remove

public void remove(UnitGenerator ugen)
Specified by:
remove in interface Synthesizer

sleepUntil

public void sleepUntil(double time)
                throws java.lang.InterruptedException
Description copied from interface: Synthesizer
Sleep until the specified audio time is reached. In non-real-time mode, this will enable the synthesizer to run.

Specified by:
sleepUntil in interface Synthesizer
Throws:
java.lang.InterruptedException

sleepFor

public void sleepFor(double duration)
              throws java.lang.InterruptedException
Description copied from interface: Synthesizer
Sleep for the specified audio time duration. In non-real-time mode, this will enable the synthesizer to run.

Specified by:
sleepFor in interface Synthesizer
Throws:
java.lang.InterruptedException