org.pscode.xui.sound.bigclip
Class BigClip

java.lang.Object
  extended by org.pscode.xui.sound.bigclip.BigClip
All Implemented Interfaces:
EventListener, Clip, DataLine, Line, LineListener

public class BigClip
extends Object
implements Clip, LineListener

An implementation of the javax.sound.sampled.Clip that is designed to handle Clips of arbitrary size, limited only by the amount of memory available to the app. It uses the post 1.4 thread behaviour (daemon thread) that will stop the sound running after the main has exited.

N.B. Remove @Override notation and logging to use in 1.3+

Since:
1.5
Version:
2009-08-17
Author:
Andrew Thompson

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.sound.sampled.DataLine
DataLine.Info
 
Field Summary
 
Fields inherited from interface javax.sound.sampled.Clip
LOOP_CONTINUOUSLY
 
Constructor Summary
BigClip()
          Default constructor for a BigClip.
BigClip(Clip clip)
          There are a number of AudioSystem methods that will return a configured Clip.
 
Method Summary
 void addLineListener(LineListener listener)
           
 int available()
           
 void close()
           
 void drain()
           
 void flush()
           
 byte[] getAudioData()
          Provides the entire audio buffer of this clip.
 int getBufferSize()
           
 Control getControl(Control.Type control)
           
 Control[] getControls()
           
 AudioFormat getFormat()
           
 int getFrameLength()
           
 int getFramePosition()
           
 float getLevel()
           
 Line.Info getLineInfo()
           
 long getLongFramePosition()
           
 long getMicrosecondLength()
           
 long getMicrosecondPosition()
           
 boolean isActive()
           
 boolean isControlSupported(Control.Type control)
           
 boolean isOpen()
           
 boolean isRunning()
           
 void loop(int count)
           
 void open()
           
 void open(AudioFormat format, byte[] data, int offset, int bufferSize)
           
 void open(AudioInputStream stream)
           
 void removeLineListener(LineListener listener)
           
 void setFramePosition(int frames)
           
 void setLoopPoints(int start, int end)
           
 void setMicrosecondPosition(long milliseconds)
           
 void setParentComponent(Component parent)
          Sets a parent component to act as owner of a "Loading track.." progress dialog.
 void start()
          TODO - fix bug in LOOP_CONTINUOUSLY
 void stop()
           
 void update(LineEvent le)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BigClip

public BigClip()
Default constructor for a BigClip. Does nothing. Information from the AudioInputStream passed in open() will be used to get an appropriate SourceDataLine.


BigClip

public BigClip(Clip clip)
        throws LineUnavailableException
There are a number of AudioSystem methods that will return a configured Clip. This convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the same AudioFormat as the original Clip.

Parameters:
clip - Clip The Clip used to configure the BigClip.
Throws:
LineUnavailableException
Method Detail

getAudioData

public byte[] getAudioData()
Provides the entire audio buffer of this clip.

Returns:
audioData byte[] The bytes of the audio data that is loaded in this Clip.

setParentComponent

public void setParentComponent(Component parent)
Sets a parent component to act as owner of a "Loading track.." progress dialog. If null, there will be no progress shown.


update

public void update(LineEvent le)
Specified by:
update in interface LineListener

loop

public void loop(int count)
Specified by:
loop in interface Clip

setLoopPoints

public void setLoopPoints(int start,
                          int end)
Specified by:
setLoopPoints in interface Clip

setMicrosecondPosition

public void setMicrosecondPosition(long milliseconds)
Specified by:
setMicrosecondPosition in interface Clip

getMicrosecondPosition

public long getMicrosecondPosition()
Specified by:
getMicrosecondPosition in interface DataLine

getMicrosecondLength

public long getMicrosecondLength()
Specified by:
getMicrosecondLength in interface Clip

setFramePosition

public void setFramePosition(int frames)
Specified by:
setFramePosition in interface Clip

getFramePosition

public int getFramePosition()
Specified by:
getFramePosition in interface DataLine

getFrameLength

public int getFrameLength()
Specified by:
getFrameLength in interface Clip

open

public void open(AudioInputStream stream)
          throws IOException,
                 LineUnavailableException
Specified by:
open in interface Clip
Throws:
IOException
LineUnavailableException

open

public void open(AudioFormat format,
                 byte[] data,
                 int offset,
                 int bufferSize)
          throws LineUnavailableException
Specified by:
open in interface Clip
Throws:
LineUnavailableException

getLevel

public float getLevel()
Specified by:
getLevel in interface DataLine

getLongFramePosition

public long getLongFramePosition()
Specified by:
getLongFramePosition in interface DataLine

available

public int available()
Specified by:
available in interface DataLine

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface DataLine

getFormat

public AudioFormat getFormat()
Specified by:
getFormat in interface DataLine

isActive

public boolean isActive()
Specified by:
isActive in interface DataLine

isRunning

public boolean isRunning()
Specified by:
isRunning in interface DataLine

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Line

stop

public void stop()
Specified by:
stop in interface DataLine

start

public void start()
TODO - fix bug in LOOP_CONTINUOUSLY

Specified by:
start in interface DataLine

flush

public void flush()
Specified by:
flush in interface DataLine

drain

public void drain()
Specified by:
drain in interface DataLine

removeLineListener

public void removeLineListener(LineListener listener)
Specified by:
removeLineListener in interface Line

addLineListener

public void addLineListener(LineListener listener)
Specified by:
addLineListener in interface Line

getControl

public Control getControl(Control.Type control)
Specified by:
getControl in interface Line

getControls

public Control[] getControls()
Specified by:
getControls in interface Line

isControlSupported

public boolean isControlSupported(Control.Type control)
Specified by:
isControlSupported in interface Line

close

public void close()
Specified by:
close in interface Line

open

public void open()
          throws LineUnavailableException
Specified by:
open in interface Line
Throws:
LineUnavailableException

getLineInfo

public Line.Info getLineInfo()
Specified by:
getLineInfo in interface Line