org.qtunes.speaker.spi.javasound
Class SpeakerImpl

java.lang.Object
  extended by org.qtunes.speaker.spi.javasound.SpeakerImpl
All Implemented Interfaces:
Service, Speaker

public class SpeakerImpl
extends java.lang.Object
implements Speaker


Constructor Summary
SpeakerImpl()
           
 
Method Summary
 void close()
          Close the speaker, immediately stopping it and discarding any data.
 void drain()
          Block until the data already written to the speaker completes If it fails, set the error.
 void flush()
          Immediately stop the speaker and discard any cached data written to it If it fails, set the error.
 int getBufferSize()
          Return the size of the speaker buffer in bytes.
 ServiceContext getContext()
          Return the ServiceContext that was passed into Service.startService(org.qtunes.core.ServiceContext)
 int getDelay()
          Return the number of ms delay for this speaker, between a packet being written and it being heard
 java.lang.String getDisplayName()
          Return a nice name for the Speaker for display to the user
 java.lang.Exception getError()
          If this speaker has failed for some reason, return the Exception.
 javax.sound.sampled.Mixer.Info getMixer()
           
 Player getPlayer()
          Get the Player currently assigned to this speaker
 int getUniqueId()
          Return a unique ID for the speaker
 int getVolumeAdjustment()
          Get the volume adjustment that applies to this speaker (+ve or -ve, 0 for no adjustment
 boolean hasGain()
          Returns true if this speaker can have its gain adjusted
 boolean isAvailable()
           
 boolean isOpen()
          True after open has been called, false after close has been called
 void open(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
          Open the Speaker and start it.
 java.util.Map<java.lang.String,java.lang.Object> reportState()
          Return a Map describing the state of this Service, for serialization back to any client that needs to know (eg webplayer) - so values should be serializable objects, eg Lists, Maps or simple objects.
 void setGain(float gain)
          Set the gain of this speaker.
 void setMixer(javax.sound.sampled.Mixer.Info mixer)
           
 void setMixer(java.lang.String name)
           
 void setPlayer(Player player)
          Set the player for the speaker.
 void setVolumeAdjustment(int volumeadjust)
          Set the volume adjustment that applies to this speaker, which should be be added to the gain for this speaker.
 void startService(ServiceContext context)
          Start the Service
 void stopService(ServiceContext context)
          Stop the Service
 void write(byte[] buf, int off, int len)
          Write data to the speaker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpeakerImpl

public SpeakerImpl()
Method Detail

getError

public java.lang.Exception getError()
Description copied from interface: Speaker
If this speaker has failed for some reason, return the Exception. Otherwise return null.

Specified by:
getError in interface Speaker

getPlayer

public Player getPlayer()
Description copied from interface: Speaker
Get the Player currently assigned to this speaker

Specified by:
getPlayer in interface Speaker

setPlayer

public void setPlayer(Player player)
Description copied from interface: Speaker
Set the player for the speaker. This method should call Player.removeSpeaker(org.qtunes.speaker.Speaker) on the old player and Player.addSpeaker(org.qtunes.speaker.Speaker) on the new one, and anyone moving speakers between players should call this method rather than those methods directly.

Specified by:
setPlayer in interface Speaker

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: Speaker
Return a nice name for the Speaker for display to the user

Specified by:
getDisplayName in interface Speaker

getUniqueId

public int getUniqueId()
Description copied from interface: Speaker
Return a unique ID for the speaker

Specified by:
getUniqueId in interface Speaker

isAvailable

public boolean isAvailable()

hasGain

public boolean hasGain()
Description copied from interface: Speaker
Returns true if this speaker can have its gain adjusted

Specified by:
hasGain in interface Speaker

setMixer

public void setMixer(javax.sound.sampled.Mixer.Info mixer)

setMixer

public void setMixer(java.lang.String name)

getMixer

public javax.sound.sampled.Mixer.Info getMixer()

getDelay

public int getDelay()
Description copied from interface: Speaker
Return the number of ms delay for this speaker, between a packet being written and it being heard

Specified by:
getDelay in interface Speaker

getBufferSize

public int getBufferSize()
Description copied from interface: Speaker
Return the size of the speaker buffer in bytes.

Specified by:
getBufferSize in interface Speaker

write

public void write(byte[] buf,
                  int off,
                  int len)
Description copied from interface: Speaker
Write data to the speaker. If it fails, set the error

Specified by:
write in interface Speaker

flush

public void flush()
Description copied from interface: Speaker
Immediately stop the speaker and discard any cached data written to it If it fails, set the error.

Specified by:
flush in interface Speaker

drain

public void drain()
Description copied from interface: Speaker
Block until the data already written to the speaker completes If it fails, set the error.

Specified by:
drain in interface Speaker

isOpen

public boolean isOpen()
Description copied from interface: Speaker
True after open has been called, false after close has been called

Specified by:
isOpen in interface Speaker

close

public void close()
Description copied from interface: Speaker
Close the speaker, immediately stopping it and discarding any data. Does not throw exception or fail.

Specified by:
close in interface Speaker

open

public void open(float sampleRate,
                 int sampleSizeInBits,
                 int channels,
                 boolean signed,
                 boolean bigEndian)
Description copied from interface: Speaker
Open the Speaker and start it. Reset any error that may have been set.

Specified by:
open in interface Speaker

setVolumeAdjustment

public void setVolumeAdjustment(int volumeadjust)
Description copied from interface: Speaker
Set the volume adjustment that applies to this speaker, which should be be added to the gain for this speaker.

Specified by:
setVolumeAdjustment in interface Speaker

getVolumeAdjustment

public int getVolumeAdjustment()
Description copied from interface: Speaker
Get the volume adjustment that applies to this speaker (+ve or -ve, 0 for no adjustment

Specified by:
getVolumeAdjustment in interface Speaker

setGain

public void setGain(float gain)
Description copied from interface: Speaker
Set the gain of this speaker. A value of NaN means "no audio". If this method fails, set the Error.

Specified by:
setGain in interface Speaker

startService

public void startService(ServiceContext context)
Description copied from interface: Service
Start the Service

Specified by:
startService in interface Service
Parameters:
context - the ServiceContext for this Service

stopService

public void stopService(ServiceContext context)
Description copied from interface: Service
Stop the Service

Specified by:
stopService in interface Service
Parameters:
context - the ServiceContext for this Service (same as was passed into start)

getContext

public ServiceContext getContext()
Description copied from interface: Service
Return the ServiceContext that was passed into Service.startService(org.qtunes.core.ServiceContext)

Specified by:
getContext in interface Service

reportState

public java.util.Map<java.lang.String,java.lang.Object> reportState()
Description copied from interface: Service
Return a Map describing the state of this Service, for serialization back to any client that needs to know (eg webplayer) - so values should be serializable objects, eg Lists, Maps or simple objects. If no useful state, return null.

Specified by:
reportState in interface Service