Package ipsk.audio.impl.j2audio
Class J2AudioController
- java.lang.Object
-
- ipsk.audio.impl.j2audio.J2AudioController
-
- All Implemented Interfaces:
AudioController,CaptureListener,PlaybackListener
public class J2AudioController extends java.lang.Object implements AudioController, CaptureListener, PlaybackListener
The main class to manage multi-line audio recording and playback.- looks for matching audio mixers and lines
- opens the lines
- handles line-synchronized starting and stopping
- Author:
- klausj
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ipsk.audio.AudioController
AudioController.CaptureStatus, AudioController.PlaybackStatus
-
-
Field Summary
-
Fields inherited from interface ipsk.audio.AudioController
AUDIO_END, DISABLE_CAPTURE, FULLDUPLEX, HOLD_OPEN, OPEN_ON_DEMAND, POS_UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description J2AudioController()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAudioControllerListener(AudioControllerListener acl)Adds controller listener.voidclose()closes this sessionprotected voidcloseCapture()protected voidclosePlayback()voidconfigure()Configures a session.javax.sound.sampled.AudioFormatgetAudioFormat()get current selected audio formatAudioController.CaptureStatusgetCaptureStatus()Get status of capture engine.float[]getLevels()gets current normalized linear audio levels maximum level is 1.0 representing 0dB minimum level is 0 array has channels * numLines entrieslonggetMode()Returns mode flags.intgetNumLines()Get number of lines.javax.sound.sampled.AudioFormatgetPlaybackAudioFormat()Get audio format for playback.AudioSource[]getPlaybackAudioSources()Get playback audio sources.java.io.File[]getPlaybackFiles()Deprecated.Use getPlaybackURLs instead !longgetPlaybackFrameLength()Gets length of largest playback file in frames, -1 if not availablelonggetPlaybackFramePosition()Get playback position.longgetPlaybackStartFramePosition()Gets the start position.AudioController.PlaybackStatusgetPlaybackStatus()Get status of playback engine.longgetPlaybackStopFramePosition()Gets the stop position.java.lang.StringgetProperty(java.lang.String propertyName)Get an implementation specific property.java.lang.StringgetPropertyDescription(java.lang.String propertyName)Get a description of the property.java.lang.String[]getPropertyNames()Get an implementation specific property names.java.io.File[]getRecordingFiles()Get recording files.longgetRecordingFramePosition()Get recording position.java.io.OutputStream[]getRecordingOutputStreams()javax.sound.sampled.Mixer.InfogetSourceMixerInfo()Get current used source mixer (playback) info.javax.sound.sampled.Mixer.InfogetTargetMixerInfo()Get current used target mixer (recording) info.booleanisOverwrite()Gets overwrite flag.booleanisPlaybackRandomPositioningSupported()Get random positioning capability of the playback engine.static voidmain(java.lang.String[] args)Creates a controller.voidopen()Opens the session.voidpausePlayback()Pauses playback.voidplay()Plays the audio files(s).voidplayed(Playback pb)voidpreparePlayback()Prepares playback.voidprepareRecording()Prepares recording.booleanprepareRecording(boolean forceOverwrite)voidremoveAudioControllerListener(AudioControllerListener acl)Removes controller listener.voidsetAudioFormat(javax.sound.sampled.AudioFormat format)Use audio format audioFormat..voidsetMode(int mode)voidsetMode(long modeBits)voidsetNumLines(int numLines)Use numLines lines.voidsetOverwrite(boolean overwrite)Sets overwrite flag.voidsetPlaybackAudioSources(AudioSource[] audioSources)Set playback audio sources.voidsetPlaybackFiles(java.io.File[] files)Set playback files.longsetPlaybackFramePosition(long newPosition)Sets the new frame position of playback.voidsetPlaybackInputStreams(java.io.InputStream[] inputStreams)Sets playback Inputstreams to use.longsetPlaybackStartFramePosition(long startPosition)Sets the start position.longsetPlaybackStopFramePosition(long stopPosition)Sets the stop position.voidsetPlaybackURLs(java.net.URL[] urls)Set playback URL's.voidsetProperty(java.lang.String arg0, java.lang.String arg1)Set a property for a specific implementation.voidsetRecordingFiles(java.io.File[] files)Sets recording files to use.voidsetRecordingOutputStreams(java.io.OutputStream[] streams)Sets recording OutputStreams to use.voidsetSettings()Call the graphical user interface of the controller implementation to set the configuration.voidsetSourceMixer(javax.sound.sampled.Mixer mixer)Sets playback mixer.voidsetSourceMixer(javax.sound.sampled.Mixer.Info mixerInfo)Use the source mixer (playback) described by mixerInfo.voidsetSourceMixerName(java.lang.String string)Use the source mixer (playback) with the given name.voidsetTargetMixer(javax.sound.sampled.Mixer mixer)Sets recording mixer.voidsetTargetMixer(javax.sound.sampled.Mixer.Info mixerInfo)Use the target mixer (recording) described by mixerInfo.voidsetTargetMixerName(java.lang.String targetMixerName)Use the target mixer (recording) with the given name.voidstartCapture()Starts the capturing of data.voidstartDuplex()voidstartPlayback()Starts the playback.voidstartRecording()Starts recording to the given files.voidstop()voidstopCapture()Stops capturing.voidstopPlayback()Stops playback.voidstopRecording()Stops recording. the method blocks until all files are writtenvoidupdate(Capture src, CaptureStatus cs)voidupdate(Playback p, Playback.PlayerStatus ps)protected voidupdateListeners(AudioController.PlaybackStatus pe, AudioController.CaptureStatus ce)
-
-
-
Method Detail
-
setNumLines
public void setNumLines(int numLines)
Description copied from interface:AudioControllerUse numLines lines. For each line a recording file will be created.- Specified by:
setNumLinesin interfaceAudioController- Parameters:
numLines- number of lines to use
-
setSourceMixer
public void setSourceMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Description copied from interface:AudioControllerUse the source mixer (playback) described by mixerInfo.- Specified by:
setSourceMixerin interfaceAudioController- Parameters:
mixerInfo- the info (name) of the mixer
-
setMode
public void setMode(int mode)
-
configure
public void configure() throws AudioControllerExceptionDescription copied from interface:AudioControllerConfigures a session.- Specified by:
configurein interfaceAudioController- Throws:
AudioControllerException
-
open
public void open() throws AudioControllerExceptionDescription copied from interface:AudioControllerOpens the session.- Specified by:
openin interfaceAudioController- Throws:
AudioControllerException
-
prepareRecording
public void prepareRecording() throws AudioControllerExceptionDescription copied from interface:AudioControllerPrepares recording.- Specified by:
prepareRecordingin interfaceAudioController- Throws:
AudioControllerException
-
prepareRecording
public boolean prepareRecording(boolean forceOverwrite) throws AudioControllerException- Throws:
AudioControllerException
-
startRecording
public void startRecording()
Description copied from interface:AudioControllerStarts recording to the given files.- Specified by:
startRecordingin interfaceAudioController- See Also:
AudioController.prepareRecording()
-
stopRecording
public void stopRecording() throws AudioControllerExceptionDescription copied from interface:AudioControllerStops recording. the method blocks until all files are written- Specified by:
stopRecordingin interfaceAudioController- Throws:
AudioControllerException
-
played
public void played(Playback pb)
-
preparePlayback
public void preparePlayback() throws AudioControllerExceptionDescription copied from interface:AudioControllerPrepares playback.- Specified by:
preparePlaybackin interfaceAudioController- Throws:
AudioControllerException
-
getLevels
public float[] getLevels()
gets current normalized linear audio levels maximum level is 1.0 representing 0dB minimum level is 0 array has channels * numLines entries- Specified by:
getLevelsin interfaceAudioController- Returns:
- current audio levels
-
close
public void close()
closes this session- Specified by:
closein interfaceAudioController
-
closePlayback
protected void closePlayback()
-
closeCapture
protected void closeCapture()
-
addAudioControllerListener
public void addAudioControllerListener(AudioControllerListener acl)
Description copied from interface:AudioControllerAdds controller listener.- Specified by:
addAudioControllerListenerin interfaceAudioController- Parameters:
acl- controller listener
-
removeAudioControllerListener
public void removeAudioControllerListener(AudioControllerListener acl)
Description copied from interface:AudioControllerRemoves controller listener.- Specified by:
removeAudioControllerListenerin interfaceAudioController- Parameters:
acl- controller listener
-
updateListeners
protected void updateListeners(AudioController.PlaybackStatus pe, AudioController.CaptureStatus ce)
-
getAudioFormat
public javax.sound.sampled.AudioFormat getAudioFormat()
get current selected audio format- Specified by:
getAudioFormatin interfaceAudioController- Returns:
- audio format
-
startPlayback
public void startPlayback() throws AudioControllerExceptionDescription copied from interface:AudioControllerStarts the playback.- Specified by:
startPlaybackin interfaceAudioController- Throws:
AudioControllerException
-
play
public void play() throws AudioControllerExceptionPlays the audio files(s). (Blocking!) Blocks until the whole file is played.- Throws:
AudioControllerException
-
pausePlayback
public void pausePlayback()
Description copied from interface:AudioControllerPauses playback.- Specified by:
pausePlaybackin interfaceAudioController
-
stopPlayback
public void stopPlayback()
Description copied from interface:AudioControllerStops playback.- Specified by:
stopPlaybackin interfaceAudioController
-
startCapture
public void startCapture()
Description copied from interface:AudioControllerStarts the capturing of data. Can be used to capture data from the line without writing to files- Specified by:
startCapturein interfaceAudioController
-
stopCapture
public void stopCapture()
Description copied from interface:AudioControllerStops capturing.- Specified by:
stopCapturein interfaceAudioController
-
stop
public void stop() throws java.io.IOException- Throws:
java.io.IOException
-
startDuplex
public void startDuplex() throws AudioControllerException- Throws:
AudioControllerException
-
getPlaybackFrameLength
public long getPlaybackFrameLength()
Description copied from interface:AudioControllerGets length of largest playback file in frames, -1 if not available- Specified by:
getPlaybackFrameLengthin interfaceAudioController- Returns:
- length of largest playback file in frames
-
getPlaybackFramePosition
public long getPlaybackFramePosition()
Description copied from interface:AudioControllerGet playback position.- Specified by:
getPlaybackFramePositionin interfaceAudioController- Returns:
- current playback position in audio frames or POS_UNKNOWN (-1) if not supported
-
getRecordingFramePosition
public long getRecordingFramePosition()
Description copied from interface:AudioControllerGet recording position.- Specified by:
getRecordingFramePositionin interfaceAudioController- Returns:
- current recording position in audio frames or -1 if not supported
-
setPlaybackFramePosition
public long setPlaybackFramePosition(long newPosition)
Description copied from interface:AudioControllerSets the new frame position of playback.- Specified by:
setPlaybackFramePositionin interfaceAudioController- Parameters:
newPosition- the requested position- Returns:
- the actually set position or POS_UNKNOWN (-1) if not supported
-
setSettings
public void setSettings()
Description copied from interface:AudioControllerCall the graphical user interface of the controller implementation to set the configuration.- Specified by:
setSettingsin interfaceAudioController
-
getCaptureStatus
public AudioController.CaptureStatus getCaptureStatus()
Get status of capture engine.- Specified by:
getCaptureStatusin interfaceAudioController- Returns:
- capture status
-
getPlaybackStatus
public AudioController.PlaybackStatus getPlaybackStatus()
Get status of playback engine.- Specified by:
getPlaybackStatusin interfaceAudioController- Returns:
- playback status
-
getPlaybackFiles
public java.io.File[] getPlaybackFiles()
Deprecated.Use getPlaybackURLs instead !Description copied from interface:AudioControllerGets playback files.the size of the array is equal the number of lines opened.
- Specified by:
getPlaybackFilesin interfaceAudioController- Returns:
- playback files array (returns alaways null !)
-
getRecordingFiles
public java.io.File[] getRecordingFiles()
Get recording files.- Specified by:
getRecordingFilesin interfaceAudioController- Returns:
- recording files array
-
setPlaybackFiles
public void setPlaybackFiles(java.io.File[] files)
Set playback files.- Specified by:
setPlaybackFilesin interfaceAudioController- Parameters:
files-
-
setPlaybackURLs
public void setPlaybackURLs(java.net.URL[] urls)
Set playback URL's.- Specified by:
setPlaybackURLsin interfaceAudioController- Parameters:
urls-
-
setPlaybackAudioSources
public void setPlaybackAudioSources(AudioSource[] audioSources)
Set playback audio sources.- Specified by:
setPlaybackAudioSourcesin interfaceAudioController- Parameters:
audioSources- sources for playback
-
getPlaybackAudioSources
public AudioSource[] getPlaybackAudioSources()
Get playback audio sources.- Returns:
- playback audio sources
-
setPlaybackInputStreams
public void setPlaybackInputStreams(java.io.InputStream[] inputStreams)
Description copied from interface:AudioControllerSets playback Inputstreams to use.the size of the array must equal the number of lines opened.
- Specified by:
setPlaybackInputStreamsin interfaceAudioController- Parameters:
inputStreams- the inputstream array to play
-
setRecordingFiles
public void setRecordingFiles(java.io.File[] files)
Description copied from interface:AudioControllerSets recording files to use.the size of the array must equal the number of lines opened.
- Specified by:
setRecordingFilesin interfaceAudioController- Parameters:
files-
-
setRecordingOutputStreams
public void setRecordingOutputStreams(java.io.OutputStream[] streams)
Description copied from interface:AudioControllerSets recording OutputStreams to use.the size of the array must equal the number of lines opened.
- Specified by:
setRecordingOutputStreamsin interfaceAudioController- Parameters:
streams- recording OutputStreams
-
getRecordingOutputStreams
public java.io.OutputStream[] getRecordingOutputStreams()
-
setAudioFormat
public void setAudioFormat(javax.sound.sampled.AudioFormat format)
Description copied from interface:AudioControllerUse audio format audioFormat..- Specified by:
setAudioFormatin interfaceAudioController- Parameters:
format-
-
isPlaybackRandomPositioningSupported
public boolean isPlaybackRandomPositioningSupported()
Description copied from interface:AudioControllerGet random positioning capability of the playback engine.- Specified by:
isPlaybackRandomPositioningSupportedin interfaceAudioController- Returns:
- random positioning capability
-
setSourceMixer
public void setSourceMixer(javax.sound.sampled.Mixer mixer)
Sets playback mixer.- Parameters:
mixer-
-
setTargetMixer
public void setTargetMixer(javax.sound.sampled.Mixer mixer)
Sets recording mixer.- Parameters:
mixer-
-
setTargetMixerName
public void setTargetMixerName(java.lang.String targetMixerName)
Description copied from interface:AudioControllerUse the target mixer (recording) with the given name.- Specified by:
setTargetMixerNamein interfaceAudioController- Parameters:
targetMixerName- the name of the target mixer
-
getMode
public long getMode()
Returns mode flags.- Specified by:
getModein interfaceAudioController- Returns:
- mode
-
main
public static void main(java.lang.String[] args)
Creates a controller. Usage: java J2AudioController [-f][-i][-r][-p] [recordfile] Example:java J2AudioController rrecords to Untitled.wav 44100kHz,16bit, stereo
-
setOverwrite
public void setOverwrite(boolean overwrite)
Description copied from interface:AudioControllerSets overwrite flag. If the overwrite flag is set, existing recording files are overwritten without any exception or warning.- Specified by:
setOverwritein interfaceAudioController- Parameters:
overwrite- overwrite flag
-
isOverwrite
public boolean isOverwrite()
Description copied from interface:AudioControllerGets overwrite flag. If the overwrite flag is set, existing recording files are overwritten without any exception or warning.- Specified by:
isOverwritein interfaceAudioController- Returns:
- overwrite flag
-
setPlaybackStartFramePosition
public long setPlaybackStartFramePosition(long startPosition)
Description copied from interface:AudioControllerSets the start position. Used to play only a segment of an audio file.- Specified by:
setPlaybackStartFramePositionin interfaceAudioController- Parameters:
startPosition- position in audio frames from where to start- Returns:
- the actually set start position
-
getPlaybackStartFramePosition
public long getPlaybackStartFramePosition()
Description copied from interface:AudioControllerGets the start position.- Specified by:
getPlaybackStartFramePositionin interfaceAudioController- Returns:
- start position
-
setPlaybackStopFramePosition
public long setPlaybackStopFramePosition(long stopPosition)
Description copied from interface:AudioControllerSets the stop position. Used to play only a segment of an audio file. To play the whole audio file set the position to AUDIO_END (-1).- Specified by:
setPlaybackStopFramePositionin interfaceAudioController- Parameters:
stopPosition- position in audio frames to stop- Returns:
- the actually set stop position
-
getPlaybackStopFramePosition
public long getPlaybackStopFramePosition()
Description copied from interface:AudioControllerGets the stop position.- Specified by:
getPlaybackStopFramePositionin interfaceAudioController- Returns:
- stop position
-
update
public void update(Playback p, Playback.PlayerStatus ps)
- Specified by:
updatein interfacePlaybackListener
-
getNumLines
public int getNumLines()
Description copied from interface:AudioControllerGet number of lines.- Specified by:
getNumLinesin interfaceAudioController- Returns:
- number of lines to use
-
getSourceMixerInfo
public javax.sound.sampled.Mixer.Info getSourceMixerInfo()
Description copied from interface:AudioControllerGet current used source mixer (playback) info.- Specified by:
getSourceMixerInfoin interfaceAudioController- Returns:
- mixerInfo the info of the source mixer
-
setTargetMixer
public void setTargetMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Description copied from interface:AudioControllerUse the target mixer (recording) described by mixerInfo.- Specified by:
setTargetMixerin interfaceAudioController- Parameters:
mixerInfo- the info of the target mixer
-
getTargetMixerInfo
public javax.sound.sampled.Mixer.Info getTargetMixerInfo()
Description copied from interface:AudioControllerGet current used target mixer (recording) info.- Specified by:
getTargetMixerInfoin interfaceAudioController- Returns:
- mixerInfo the info (name) of the target mixer
-
setMode
public void setMode(long modeBits)
- Specified by:
setModein interfaceAudioController
-
update
public void update(Capture src, CaptureStatus cs)
- Specified by:
updatein interfaceCaptureListener
-
getPlaybackAudioFormat
public javax.sound.sampled.AudioFormat getPlaybackAudioFormat()
Description copied from interface:AudioControllerGet audio format for playback. The controller sets the audio format according to the set playback files. So it can differ from the chosen foprmat.- Specified by:
getPlaybackAudioFormatin interfaceAudioController- Returns:
- audio format
-
getPropertyNames
public java.lang.String[] getPropertyNames()
Description copied from interface:AudioControllerGet an implementation specific property names.- Specified by:
getPropertyNamesin interfaceAudioController- Returns:
- property names
-
getPropertyDescription
public java.lang.String getPropertyDescription(java.lang.String propertyName)
Description copied from interface:AudioControllerGet a description of the property.- Specified by:
getPropertyDescriptionin interfaceAudioController- Returns:
- description
-
setProperty
public void setProperty(java.lang.String arg0, java.lang.String arg1)Description copied from interface:AudioControllerSet a property for a specific implementation.- Specified by:
setPropertyin interfaceAudioController
-
getProperty
public java.lang.String getProperty(java.lang.String propertyName)
Description copied from interface:AudioControllerGet an implementation specific property.- Specified by:
getPropertyin interfaceAudioController- Returns:
- value of the property or null if there is no such property
-
setSourceMixerName
public void setSourceMixerName(java.lang.String string)
Description copied from interface:AudioControllerUse the source mixer (playback) with the given name.- Specified by:
setSourceMixerNamein interfaceAudioController- Parameters:
string-
-
-