Silence.Noise
Class Noise

java.lang.Object
  |
  +--Silence.Noise.Noise

public class Noise
extends java.lang.Object
implements java.lang.Runnable

Noise is a completely encapsulated, low-level Java interface to John Lazzaro's sfront, an implementation of the MP4 Structured Audio Orchestra Language (SAOL) and Structured Audio Score Language (SASL). Noise translates SAOL sources (saol, sasl, mid, and/or mp4 files) to a single C source code file, and then shells out to the operating system to run a C compiler that translates the C file to an executable shared library. The shared library, however, is loaded and managed by Noise.

SAOL, briefly, is an international standard for unit generator based software sound synthesis. In effect, SAOL is a successor to Csound defined at a somewhat higher level of abstraction (procedural language rather than assembler). SAOL enables users to write not only instruments, but also unit generators (user-defined opcodes), and has internal signal routing busses.

Noise supports real-time control and MIDI input, real-time audio input and output, and out-of-real-time rendering driven by score files and written to soundfiles. In addition to the existing sfront control and audio drivers, Noise can use JavaSound MIDI and audio inputs and outputs.

Noise optionally can read, store, and write all SAOL input files in one XML element.

Author:
Copyright (C) 1999 by Michael Gogins. All rights reserved.
gogins@nyc.pipeline.com

Constructor Summary
Noise()
          Creates a new Noise object and, at the same, a new implementation object (the native methods).
 
Method Summary
 void addSaslLine(java.lang.String line)
          Appends a new line of SASL source code to the internally stored score.
 boolean compile()
          Translates the input files indicated set by setSfrontCommandLine to a C source file, then translates the C source file to an executable SAOL orchestra shared library.
 void finalize()
           
 Silence.Noise.TargetDataLine getAudioInput()
          Returns the JavaSound TargetDataLine object that is used for audio input, or null if there is none.
 Silence.Noise.SourceDataLine getAudioOutput()
          Returns the JavaSound SourceDataLine object that is used for audio output, or null if there is none.
 java.lang.String getCCompilerOptions()
          Returns the C compiler options used to compile generated C source code to a SAOL executable shared library.
 byte[] getMidi()
          Returns the internally stored MIDI byte stream, or null if none.
 java.io.ByteArrayOutputStream getMidiInput()
          Returns the ByteArrayOutputStream object that is used to get MIDI input, or null if there is none.
 Silence.Noise.StreamParser getMidiOutput()
          Returns the JavaSound StreamParser object that is used for MIDI output, or null if there is none.
 java.lang.String getSaolText()
          Returns the internally stored SAOL source code.
 java.lang.String getSaslLine(int index)
          Returns the indicated line of SASL source code in the internally stored score.
 int getSaslLineCount()
          Returns the number of lines in the internally stored SASL source code.
 java.lang.String getSfrontCommandLine()
          Returns the sfront command line.
 java.lang.String getXML()
          Returns all internally stored SAOL sources as an XML stream.
 void insertSaslLine(int index, java.lang.String line)
          Inserts a new line of SASL source code to the internally stored score.
 boolean isPlaying()
          Returns true if there is a play thread, or false if not.
 boolean load(java.lang.String filename)
          Loads a SAOL source file into internal storage.
 void pause()
          Pauses the play thread.
 void play()
          Starts a thread to play the compiled SAOL orchestra executable shared library.
 boolean removeSaslLine(int index)
          Removes the indicated line of SASL source code from the internally stored score.
 void resume()
          Resumes a paused play thread.
 void run()
          Thread routine that runs the native play method.
 boolean save(java.lang.String filename)
          Saves the contents of internal storage to a SAOL source code file.
 boolean setAudioInput(Silence.Noise.TargetDataLine audioInput)
          Sets a JavaSound TargetDataLine object to act as a source of audio input.
 boolean setAudioOutput(Silence.Noise.SourceDataLine audioOutput)
          Sets a JavaSound SourceDataLine object to act as a target of audio output.
 void setCCompilerOptions(java.lang.String options)
          Sets the C compiler options required for compiling generated C source code to a SAOL executable shared library.
 void setMidi(byte[] midiStream)
          Stores a MIDI byte stream internally.
 boolean setMidiInput(java.io.ByteArrayOutputStream byteArrayOutputStream)
          Sets a ByteArrayOutputStream object, associated with a javax.media.sound.midi.StreamGenerator object, to act as a source of MIDI input.
 boolean setMidiOutput(Silence.Noise.StreamParser streamParser)
          Sets a JavaSound StreamParser object to act as a target of MIDI output.
 void setSaolText(java.lang.String saolText)
          Sets the internally stored SAOL source code.
 void setSaslLine(int index, java.lang.String line)
          Sets the indicated line of SASL source code in the internally stored score.
 void setSaslLineCount(int count)
          Sets the number of lines in the internally stored SASL source code.
 void setSfrontCommandLine(java.lang.String sfrontCommandLine)
          Sets the sfront command line.
 boolean setXML(java.lang.String xmlStream)
          Sets all internally stored SAOL sources from an XML stream.
 void stop()
          Stops the play thread.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Noise

public Noise()
Creates a new Noise object and, at the same, a new implementation object (the native methods).
Method Detail

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

setSfrontCommandLine

public void setSfrontCommandLine(java.lang.String sfrontCommandLine)
Sets the sfront command line. Options are identical to those in the sfront documentation, except that there is a "JavaSound" option for the "-cin", "-ain", and "-aout" options. For these options to work, the appropriate JavaSound input or output objects must also be set.

getSfrontCommandLine

public java.lang.String getSfrontCommandLine()
Returns the sfront command line.

setSaolText

public void setSaolText(java.lang.String saolText)
Sets the internally stored SAOL source code.

getSaolText

public java.lang.String getSaolText()
Returns the internally stored SAOL source code.

setSaslLineCount

public void setSaslLineCount(int count)
Sets the number of lines in the internally stored SASL source code. Setting the count to 0 removes all SASL code.

getSaslLineCount

public int getSaslLineCount()
Returns the number of lines in the internally stored SASL source code.

setSaslLine

public void setSaslLine(int index,
                        java.lang.String line)
Sets the indicated line of SASL source code in the internally stored score. Useful for implementing an SASL editor or for algorithmic composition clients.

getSaslLine

public java.lang.String getSaslLine(int index)
Returns the indicated line of SASL source code in the internally stored score. Useful for implementing an SASL editor.

removeSaslLine

public boolean removeSaslLine(int index)
Removes the indicated line of SASL source code from the internally stored score. Lines are shifted up to fill the gap.

insertSaslLine

public void insertSaslLine(int index,
                           java.lang.String line)
Inserts a new line of SASL source code to the internally stored score. Existing lines are shifted down by one to make room for the new line. Useful for implementing an SASL editor or for algorithmic composition.

addSaslLine

public void addSaslLine(java.lang.String line)
Appends a new line of SASL source code to the internally stored score. Useful for implementing an SASL editor or for algorithmic composition.

setMidi

public void setMidi(byte[] midiStream)
Stores a MIDI byte stream internally. Used in place of MIDI file input.

getMidi

public byte[] getMidi()
Returns the internally stored MIDI byte stream, or null if none.

setXML

public boolean setXML(java.lang.String xmlStream)
Sets all internally stored SAOL sources from an XML stream. The tags are:
Noise
SAOL
SASL
MIDI
CCompilerOptions

getXML

public java.lang.String getXML()
Returns all internally stored SAOL sources as an XML stream. The tags are:
Noise
SAOL
SASL
MIDI
CCompilerOptions

load

public boolean load(java.lang.String filename)
Loads a SAOL source file into internal storage. File types loaded are xml, saol, sasl, mid, and mp4.

save

public boolean save(java.lang.String filename)
Saves the contents of internal storage to a SAOL source code file. File types saved are xml, saol, sasl, mid, and mp4.

setCCompilerOptions

public void setCCompilerOptions(java.lang.String options)
Sets the C compiler options required for compiling generated C source code to a SAOL executable shared library. The placeholder "%s" must be used to denote the C source code file. On Windows with Microsoft Visual C++, for example, the options might be "cl %s winmm.lib /dll". The options are stored in a persistent configuration file or the system registry.

getCCompilerOptions

public java.lang.String getCCompilerOptions()
Returns the C compiler options used to compile generated C source code to a SAOL executable shared library.

compile

public boolean compile()
Translates the input files indicated set by setSfrontCommandLine to a C source file, then translates the C source file to an executable SAOL orchestra shared library. If the command line is null, then internally stored sources, if any, are used and the command line is inferred from them.

setMidiInput

public boolean setMidiInput(java.io.ByteArrayOutputStream byteArrayOutputStream)
Sets a ByteArrayOutputStream object, associated with a javax.media.sound.midi.StreamGenerator object, to act as a source of MIDI input. A proxy in Noise calls the methods of the Java object. Returns false for failure. Set with null to remove the input.

getMidiInput

public java.io.ByteArrayOutputStream getMidiInput()
Returns the ByteArrayOutputStream object that is used to get MIDI input, or null if there is none.

setMidiOutput

public boolean setMidiOutput(Silence.Noise.StreamParser streamParser)
Sets a JavaSound StreamParser object to act as a target of MIDI output. A proxy in Noise calls the methods of the Java object. Returns false for failure, or if the StreamParser is not accepted. Set with null to remove the output.

getMidiOutput

public Silence.Noise.StreamParser getMidiOutput()
Returns the JavaSound StreamParser object that is used for MIDI output, or null if there is none.

setAudioInput

public boolean setAudioInput(Silence.Noise.TargetDataLine audioInput)
Sets a JavaSound TargetDataLine object to act as a source of audio input. Do not be confused by the naming convention! A proxy in Noise calls the methods of the Java object. Returns false for failure, or if the TargetDataLine is not accepted.

getAudioInput

public Silence.Noise.TargetDataLine getAudioInput()
Returns the JavaSound TargetDataLine object that is used for audio input, or null if there is none.

setAudioOutput

public boolean setAudioOutput(Silence.Noise.SourceDataLine audioOutput)
Sets a JavaSound SourceDataLine object to act as a target of audio output. Do not be confused by the naming convention! A proxy in Noise calls the methods of the Java object. Returns false for failure, or if the SourceDataLine is not accepted.

getAudioOutput

public Silence.Noise.SourceDataLine getAudioOutput()
Returns the JavaSound SourceDataLine object that is used for audio output, or null if there is none.

play

public void play()
Starts a thread to play the compiled SAOL orchestra executable shared library.

isPlaying

public boolean isPlaying()
Returns true if there is a play thread, or false if not.

run

public void run()
Thread routine that runs the native play method.
Specified by:
run in interface java.lang.Runnable

pause

public void pause()
Pauses the play thread.

resume

public void resume()
Resumes a paused play thread.

stop

public void stop()
Stops the play thread.