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 void
addAudioControllerListener(AudioControllerListener acl)
Adds controller listener.void
close()
closes this sessionprotected void
closeCapture()
protected void
closePlayback()
void
configure()
Configures a session.javax.sound.sampled.AudioFormat
getAudioFormat()
get current selected audio formatAudioController.CaptureStatus
getCaptureStatus()
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 entrieslong
getMode()
Returns mode flags.int
getNumLines()
Get number of lines.javax.sound.sampled.AudioFormat
getPlaybackAudioFormat()
Get audio format for playback.AudioSource[]
getPlaybackAudioSources()
Get playback audio sources.java.io.File[]
getPlaybackFiles()
Deprecated.Use getPlaybackURLs instead !long
getPlaybackFrameLength()
Gets length of largest playback file in frames, -1 if not availablelong
getPlaybackFramePosition()
Get playback position.long
getPlaybackStartFramePosition()
Gets the start position.AudioController.PlaybackStatus
getPlaybackStatus()
Get status of playback engine.long
getPlaybackStopFramePosition()
Gets the stop position.java.lang.String
getProperty(java.lang.String propertyName)
Get an implementation specific property.java.lang.String
getPropertyDescription(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.long
getRecordingFramePosition()
Get recording position.java.io.OutputStream[]
getRecordingOutputStreams()
javax.sound.sampled.Mixer.Info
getSourceMixerInfo()
Get current used source mixer (playback) info.javax.sound.sampled.Mixer.Info
getTargetMixerInfo()
Get current used target mixer (recording) info.boolean
isOverwrite()
Gets overwrite flag.boolean
isPlaybackRandomPositioningSupported()
Get random positioning capability of the playback engine.static void
main(java.lang.String[] args)
Creates a controller.void
open()
Opens the session.void
pausePlayback()
Pauses playback.void
play()
Plays the audio files(s).void
played(Playback pb)
void
preparePlayback()
Prepares playback.void
prepareRecording()
Prepares recording.boolean
prepareRecording(boolean forceOverwrite)
void
removeAudioControllerListener(AudioControllerListener acl)
Removes controller listener.void
setAudioFormat(javax.sound.sampled.AudioFormat format)
Use audio format audioFormat..void
setMode(int mode)
void
setMode(long modeBits)
void
setNumLines(int numLines)
Use numLines lines.void
setOverwrite(boolean overwrite)
Sets overwrite flag.void
setPlaybackAudioSources(AudioSource[] audioSources)
Set playback audio sources.void
setPlaybackFiles(java.io.File[] files)
Set playback files.long
setPlaybackFramePosition(long newPosition)
Sets the new frame position of playback.void
setPlaybackInputStreams(java.io.InputStream[] inputStreams)
Sets playback Inputstreams to use.long
setPlaybackStartFramePosition(long startPosition)
Sets the start position.long
setPlaybackStopFramePosition(long stopPosition)
Sets the stop position.void
setPlaybackURLs(java.net.URL[] urls)
Set playback URL's.void
setProperty(java.lang.String arg0, java.lang.String arg1)
Set a property for a specific implementation.void
setRecordingFiles(java.io.File[] files)
Sets recording files to use.void
setRecordingOutputStreams(java.io.OutputStream[] streams)
Sets recording OutputStreams to use.void
setSettings()
Call the graphical user interface of the controller implementation to set the configuration.void
setSourceMixer(javax.sound.sampled.Mixer mixer)
Sets playback mixer.void
setSourceMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Use the source mixer (playback) described by mixerInfo.void
setSourceMixerName(java.lang.String string)
Use the source mixer (playback) with the given name.void
setTargetMixer(javax.sound.sampled.Mixer mixer)
Sets recording mixer.void
setTargetMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Use the target mixer (recording) described by mixerInfo.void
setTargetMixerName(java.lang.String targetMixerName)
Use the target mixer (recording) with the given name.void
startCapture()
Starts the capturing of data.void
startDuplex()
void
startPlayback()
Starts the playback.void
startRecording()
Starts recording to the given files.void
stop()
void
stopCapture()
Stops capturing.void
stopPlayback()
Stops playback.void
stopRecording()
Stops recording. the method blocks until all files are writtenvoid
update(Capture src, CaptureStatus cs)
void
update(Playback p, Playback.PlayerStatus ps)
protected void
updateListeners(AudioController.PlaybackStatus pe, AudioController.CaptureStatus ce)
-
-
-
Method Detail
-
setNumLines
public void setNumLines(int numLines)
Description copied from interface:AudioController
Use numLines lines. For each line a recording file will be created.- Specified by:
setNumLines
in interfaceAudioController
- Parameters:
numLines
- number of lines to use
-
setSourceMixer
public void setSourceMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Description copied from interface:AudioController
Use the source mixer (playback) described by mixerInfo.- Specified by:
setSourceMixer
in interfaceAudioController
- Parameters:
mixerInfo
- the info (name) of the mixer
-
setMode
public void setMode(int mode)
-
configure
public void configure() throws AudioControllerException
Description copied from interface:AudioController
Configures a session.- Specified by:
configure
in interfaceAudioController
- Throws:
AudioControllerException
-
open
public void open() throws AudioControllerException
Description copied from interface:AudioController
Opens the session.- Specified by:
open
in interfaceAudioController
- Throws:
AudioControllerException
-
prepareRecording
public void prepareRecording() throws AudioControllerException
Description copied from interface:AudioController
Prepares recording.- Specified by:
prepareRecording
in interfaceAudioController
- Throws:
AudioControllerException
-
prepareRecording
public boolean prepareRecording(boolean forceOverwrite) throws AudioControllerException
- Throws:
AudioControllerException
-
startRecording
public void startRecording()
Description copied from interface:AudioController
Starts recording to the given files.- Specified by:
startRecording
in interfaceAudioController
- See Also:
AudioController.prepareRecording()
-
stopRecording
public void stopRecording() throws AudioControllerException
Description copied from interface:AudioController
Stops recording. the method blocks until all files are written- Specified by:
stopRecording
in interfaceAudioController
- Throws:
AudioControllerException
-
played
public void played(Playback pb)
-
preparePlayback
public void preparePlayback() throws AudioControllerException
Description copied from interface:AudioController
Prepares playback.- Specified by:
preparePlayback
in 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:
getLevels
in interfaceAudioController
- Returns:
- current audio levels
-
close
public void close()
closes this session- Specified by:
close
in interfaceAudioController
-
closePlayback
protected void closePlayback()
-
closeCapture
protected void closeCapture()
-
addAudioControllerListener
public void addAudioControllerListener(AudioControllerListener acl)
Description copied from interface:AudioController
Adds controller listener.- Specified by:
addAudioControllerListener
in interfaceAudioController
- Parameters:
acl
- controller listener
-
removeAudioControllerListener
public void removeAudioControllerListener(AudioControllerListener acl)
Description copied from interface:AudioController
Removes controller listener.- Specified by:
removeAudioControllerListener
in 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:
getAudioFormat
in interfaceAudioController
- Returns:
- audio format
-
startPlayback
public void startPlayback() throws AudioControllerException
Description copied from interface:AudioController
Starts the playback.- Specified by:
startPlayback
in interfaceAudioController
- Throws:
AudioControllerException
-
play
public void play() throws AudioControllerException
Plays the audio files(s). (Blocking!) Blocks until the whole file is played.- Throws:
AudioControllerException
-
pausePlayback
public void pausePlayback()
Description copied from interface:AudioController
Pauses playback.- Specified by:
pausePlayback
in interfaceAudioController
-
stopPlayback
public void stopPlayback()
Description copied from interface:AudioController
Stops playback.- Specified by:
stopPlayback
in interfaceAudioController
-
startCapture
public void startCapture()
Description copied from interface:AudioController
Starts the capturing of data. Can be used to capture data from the line without writing to files- Specified by:
startCapture
in interfaceAudioController
-
stopCapture
public void stopCapture()
Description copied from interface:AudioController
Stops capturing.- Specified by:
stopCapture
in 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:AudioController
Gets length of largest playback file in frames, -1 if not available- Specified by:
getPlaybackFrameLength
in interfaceAudioController
- Returns:
- length of largest playback file in frames
-
getPlaybackFramePosition
public long getPlaybackFramePosition()
Description copied from interface:AudioController
Get playback position.- Specified by:
getPlaybackFramePosition
in interfaceAudioController
- Returns:
- current playback position in audio frames or POS_UNKNOWN (-1) if not supported
-
getRecordingFramePosition
public long getRecordingFramePosition()
Description copied from interface:AudioController
Get recording position.- Specified by:
getRecordingFramePosition
in interfaceAudioController
- Returns:
- current recording position in audio frames or -1 if not supported
-
setPlaybackFramePosition
public long setPlaybackFramePosition(long newPosition)
Description copied from interface:AudioController
Sets the new frame position of playback.- Specified by:
setPlaybackFramePosition
in 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:AudioController
Call the graphical user interface of the controller implementation to set the configuration.- Specified by:
setSettings
in interfaceAudioController
-
getCaptureStatus
public AudioController.CaptureStatus getCaptureStatus()
Get status of capture engine.- Specified by:
getCaptureStatus
in interfaceAudioController
- Returns:
- capture status
-
getPlaybackStatus
public AudioController.PlaybackStatus getPlaybackStatus()
Get status of playback engine.- Specified by:
getPlaybackStatus
in interfaceAudioController
- Returns:
- playback status
-
getPlaybackFiles
public java.io.File[] getPlaybackFiles()
Deprecated.Use getPlaybackURLs instead !Description copied from interface:AudioController
Gets playback files.the size of the array is equal the number of lines opened.
- Specified by:
getPlaybackFiles
in interfaceAudioController
- Returns:
- playback files array (returns alaways null !)
-
getRecordingFiles
public java.io.File[] getRecordingFiles()
Get recording files.- Specified by:
getRecordingFiles
in interfaceAudioController
- Returns:
- recording files array
-
setPlaybackFiles
public void setPlaybackFiles(java.io.File[] files)
Set playback files.- Specified by:
setPlaybackFiles
in interfaceAudioController
- Parameters:
files
-
-
setPlaybackURLs
public void setPlaybackURLs(java.net.URL[] urls)
Set playback URL's.- Specified by:
setPlaybackURLs
in interfaceAudioController
- Parameters:
urls
-
-
setPlaybackAudioSources
public void setPlaybackAudioSources(AudioSource[] audioSources)
Set playback audio sources.- Specified by:
setPlaybackAudioSources
in 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:AudioController
Sets playback Inputstreams to use.the size of the array must equal the number of lines opened.
- Specified by:
setPlaybackInputStreams
in interfaceAudioController
- Parameters:
inputStreams
- the inputstream array to play
-
setRecordingFiles
public void setRecordingFiles(java.io.File[] files)
Description copied from interface:AudioController
Sets recording files to use.the size of the array must equal the number of lines opened.
- Specified by:
setRecordingFiles
in interfaceAudioController
- Parameters:
files
-
-
setRecordingOutputStreams
public void setRecordingOutputStreams(java.io.OutputStream[] streams)
Description copied from interface:AudioController
Sets recording OutputStreams to use.the size of the array must equal the number of lines opened.
- Specified by:
setRecordingOutputStreams
in interfaceAudioController
- Parameters:
streams
- recording OutputStreams
-
getRecordingOutputStreams
public java.io.OutputStream[] getRecordingOutputStreams()
-
setAudioFormat
public void setAudioFormat(javax.sound.sampled.AudioFormat format)
Description copied from interface:AudioController
Use audio format audioFormat..- Specified by:
setAudioFormat
in interfaceAudioController
- Parameters:
format
-
-
isPlaybackRandomPositioningSupported
public boolean isPlaybackRandomPositioningSupported()
Description copied from interface:AudioController
Get random positioning capability of the playback engine.- Specified by:
isPlaybackRandomPositioningSupported
in 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:AudioController
Use the target mixer (recording) with the given name.- Specified by:
setTargetMixerName
in interfaceAudioController
- Parameters:
targetMixerName
- the name of the target mixer
-
getMode
public long getMode()
Returns mode flags.- Specified by:
getMode
in 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 r
records to Untitled.wav 44100kHz,16bit, stereo
-
setOverwrite
public void setOverwrite(boolean overwrite)
Description copied from interface:AudioController
Sets overwrite flag. If the overwrite flag is set, existing recording files are overwritten without any exception or warning.- Specified by:
setOverwrite
in interfaceAudioController
- Parameters:
overwrite
- overwrite flag
-
isOverwrite
public boolean isOverwrite()
Description copied from interface:AudioController
Gets overwrite flag. If the overwrite flag is set, existing recording files are overwritten without any exception or warning.- Specified by:
isOverwrite
in interfaceAudioController
- Returns:
- overwrite flag
-
setPlaybackStartFramePosition
public long setPlaybackStartFramePosition(long startPosition)
Description copied from interface:AudioController
Sets the start position. Used to play only a segment of an audio file.- Specified by:
setPlaybackStartFramePosition
in 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:AudioController
Gets the start position.- Specified by:
getPlaybackStartFramePosition
in interfaceAudioController
- Returns:
- start position
-
setPlaybackStopFramePosition
public long setPlaybackStopFramePosition(long stopPosition)
Description copied from interface:AudioController
Sets 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:
setPlaybackStopFramePosition
in interfaceAudioController
- Parameters:
stopPosition
- position in audio frames to stop- Returns:
- the actually set stop position
-
getPlaybackStopFramePosition
public long getPlaybackStopFramePosition()
Description copied from interface:AudioController
Gets the stop position.- Specified by:
getPlaybackStopFramePosition
in interfaceAudioController
- Returns:
- stop position
-
update
public void update(Playback p, Playback.PlayerStatus ps)
- Specified by:
update
in interfacePlaybackListener
-
getNumLines
public int getNumLines()
Description copied from interface:AudioController
Get number of lines.- Specified by:
getNumLines
in interfaceAudioController
- Returns:
- number of lines to use
-
getSourceMixerInfo
public javax.sound.sampled.Mixer.Info getSourceMixerInfo()
Description copied from interface:AudioController
Get current used source mixer (playback) info.- Specified by:
getSourceMixerInfo
in interfaceAudioController
- Returns:
- mixerInfo the info of the source mixer
-
setTargetMixer
public void setTargetMixer(javax.sound.sampled.Mixer.Info mixerInfo)
Description copied from interface:AudioController
Use the target mixer (recording) described by mixerInfo.- Specified by:
setTargetMixer
in interfaceAudioController
- Parameters:
mixerInfo
- the info of the target mixer
-
getTargetMixerInfo
public javax.sound.sampled.Mixer.Info getTargetMixerInfo()
Description copied from interface:AudioController
Get current used target mixer (recording) info.- Specified by:
getTargetMixerInfo
in interfaceAudioController
- Returns:
- mixerInfo the info (name) of the target mixer
-
setMode
public void setMode(long modeBits)
- Specified by:
setMode
in interfaceAudioController
-
update
public void update(Capture src, CaptureStatus cs)
- Specified by:
update
in interfaceCaptureListener
-
getPlaybackAudioFormat
public javax.sound.sampled.AudioFormat getPlaybackAudioFormat()
Description copied from interface:AudioController
Get 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:
getPlaybackAudioFormat
in interfaceAudioController
- Returns:
- audio format
-
getPropertyNames
public java.lang.String[] getPropertyNames()
Description copied from interface:AudioController
Get an implementation specific property names.- Specified by:
getPropertyNames
in interfaceAudioController
- Returns:
- property names
-
getPropertyDescription
public java.lang.String getPropertyDescription(java.lang.String propertyName)
Description copied from interface:AudioController
Get a description of the property.- Specified by:
getPropertyDescription
in interfaceAudioController
- Returns:
- description
-
setProperty
public void setProperty(java.lang.String arg0, java.lang.String arg1)
Description copied from interface:AudioController
Set a property for a specific implementation.- Specified by:
setProperty
in interfaceAudioController
-
getProperty
public java.lang.String getProperty(java.lang.String propertyName)
Description copied from interface:AudioController
Get an implementation specific property.- Specified by:
getProperty
in 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:AudioController
Use the source mixer (playback) with the given name.- Specified by:
setSourceMixerName
in interfaceAudioController
- Parameters:
string
-
-
-