Package ipsk.audio.capture
Class Capture
- java.lang.Object
- 
- ipsk.audio.capture.Capture
 
- 
- All Implemented Interfaces:
- EventQuequeListener,- java.lang.Runnable,- java.util.EventListener
 
 public class Capture extends java.lang.Object implements java.lang.Runnable, EventQuequeListener Audio capture engine.- Author:
- klausj
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intCAPTUREstatic intCLOSEstatic javax.sound.sampled.AudioFileFormatDEF_AUDIO_FILE_FORMATstatic javax.sound.sampled.AudioFileFormat.TypeDEF_AUDIO_FILE_TYPEstatic javax.sound.sampled.AudioFormatDEF_AUDIO_FORMATstatic intERRORstatic intPAUSEstatic intRECORDstatic intSTOP
 - 
Constructor SummaryConstructors Constructor Description Capture()Create capture engine.Capture(javax.sound.sampled.Mixer device)Create capture engine which will capture audio data from given device.Capture(javax.sound.sampled.Mixer device, java.io.File recFile, javax.sound.sampled.AudioFileFormat aff)Create capture engine.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCaptureListener(CaptureListener cl)Add capture listener.voidclose()Close engine.javax.sound.sampled.AudioFileFormatgetAudioFileFormat()Get audio file format.javax.sound.sampled.AudioFormatgetAudioFormat()Get audio format.intgetBufferSize()The actually set buffer size.longgetFramePosition()Get already captured frames.LevelInfo[]getLevelInfos()Get current audio levels.java.lang.IntegergetLineBufferSize()Get the last used line buffer size.java.lang.FloatgetLineBufferSizeSeconds()Get the last used line buffer size in seconds.longgetMaxFrameLength()Get maximum recording length in frames.java.lang.IntegergetMaxLineBufferSize()Get maximum line bugffer size.java.lang.IntegergetMinLineBufferSize()Get minimum line bugffer size.float[]getPeakLevelHold()Get the maximum peak levels of each channel since the line is open.java.lang.IntegergetPreferredBufferSize()Get preferred buffer size in bytes.java.lang.IntegergetPreferredLineBufferSize()Get the preferred audio line buffer size setting.java.lang.FloatgetPreferredLineBufferSizeMillis()Get preferred line buffer size in milliseconds.PrimaryRecordTargetgetPrimaryRecordTarget()java.io.FilegetRecordingFile()Get recording filebooleanisCaptureOnly()Returns true if the engine is only capturing, not recording to file.booleanisCapturing()Return true if capturing.booleanisForceOpening()booleanisOpen()Return open status.booleanisRecording()Returns true if recording.booleanisUseAWTEventThread()True if generated events will be queued to AWT event queue.booleanisUseTempFile()static voidmain(java.lang.String[] args)voidopen()Open audio line and engine.voidpause()Pause capturing/recording.voidremoveCaptureListener(CaptureListener cl)Remove capture listener.voidresetPeakHold()Reset the hold peak level maximum.voidrun()voidsetAudioFileFormat(javax.sound.sampled.AudioFileFormat aff)Set audio file format.voidsetAudioFormat(javax.sound.sampled.AudioFormat af)Set audio format.voidsetCaptureOnly(boolean captureOnly)Set capture only mode.voidsetForceOpening(boolean forceOpening)voidsetMaxFrameLength(long maxFrameLength)Set the maximum length of recording in frames.voidsetMeasureLevel(boolean b)Enable audio level measuring.voidsetMixer(javax.sound.sampled.Mixer newCaptureMixer)Set the recording device to capture from.voidsetPreferredBufferSize(int preferredBufferSize)Set the buffer size of this capture engine in bytes.voidsetPreferredLineBufferSize(java.lang.Integer preferredLineBufferSize)Set the buffer size of the audio line.voidsetPreferredLineBufferSizeMillis(java.lang.Float preferredLineBufferSizeMillis)Set the buffer size of the audio line.voidsetPrimaryRecordTarget(PrimaryRecordTarget primaryRecordTarget)voidsetRecordingFile(java.io.File file)Set recording file.voidsetUseAWTEventThread(boolean useAWTEventThread)Determines if events should be queued to the AWTEventThread.voidsetUseTempFile(boolean useTempFile)voidstart()Start capturing or recording.voidstop()Stop engine.voidupdate(java.util.EventObject eventObject)
 
- 
- 
- 
Field Detail- 
CLOSEpublic static final int CLOSE - See Also:
- Constant Field Values
 
 - 
STOPpublic static final int STOP - See Also:
- Constant Field Values
 
 - 
CAPTUREpublic static final int CAPTURE - See Also:
- Constant Field Values
 
 - 
RECORDpublic static final int RECORD - See Also:
- Constant Field Values
 
 - 
PAUSEpublic static final int PAUSE - See Also:
- Constant Field Values
 
 - 
ERRORpublic static final int ERROR - See Also:
- Constant Field Values
 
 - 
DEF_AUDIO_FILE_TYPEpublic static javax.sound.sampled.AudioFileFormat.Type DEF_AUDIO_FILE_TYPE 
 - 
DEF_AUDIO_FORMATpublic static javax.sound.sampled.AudioFormat DEF_AUDIO_FORMAT 
 - 
DEF_AUDIO_FILE_FORMATpublic static javax.sound.sampled.AudioFileFormat DEF_AUDIO_FILE_FORMAT 
 
- 
 - 
Constructor Detail- 
Capturepublic Capture() Create capture engine.
 - 
Capturepublic Capture(javax.sound.sampled.Mixer device) Create capture engine which will capture audio data from given device.- Parameters:
- device- audio device to use
 
 - 
Capturepublic Capture(javax.sound.sampled.Mixer device, java.io.File recFile, javax.sound.sampled.AudioFileFormat aff)Create capture engine.- Parameters:
- device- audio device to use
- recFile- recordingfile
- aff- audio file format
 
 
- 
 - 
Method Detail- 
isUseTempFilepublic boolean isUseTempFile() 
 - 
setUseTempFilepublic void setUseTempFile(boolean useTempFile) 
 - 
setAudioFileFormatpublic void setAudioFileFormat(javax.sound.sampled.AudioFileFormat aff) Set audio file format.- Parameters:
- aff- audio file format
 
 - 
getAudioFileFormatpublic javax.sound.sampled.AudioFileFormat getAudioFileFormat() Get audio file format.- Returns:
- audio file format
 
 - 
setAudioFormatpublic void setAudioFormat(javax.sound.sampled.AudioFormat af) Set audio format.- Parameters:
- af- audio format.
 
 - 
getAudioFormatpublic javax.sound.sampled.AudioFormat getAudioFormat() Get audio format.- Returns:
- audio format
 
 - 
getMinLineBufferSizepublic java.lang.Integer getMinLineBufferSize() Get minimum line bugffer size.- Returns:
- minimum line buffer size or null if not available
 
 - 
getMaxLineBufferSizepublic java.lang.Integer getMaxLineBufferSize() Get maximum line bugffer size.- Returns:
- maximum line buffer size or null if not available
 
 - 
openpublic void open() throws CaptureExceptionOpen audio line and engine.- Throws:
- CaptureException
 
 - 
startpublic void start() Start capturing or recording.
 - 
getMaxFrameLengthpublic long getMaxFrameLength() Get maximum recording length in frames.- Returns:
- length in frames
 
 - 
pausepublic void pause() Pause capturing/recording. If already paused the engine will be restarted.
 - 
stoppublic void stop() throws CaptureExceptionStop engine.- Throws:
- CaptureException
 
 - 
closepublic void close() throws CaptureExceptionClose engine.- Throws:
- CaptureException
 
 - 
getFramePositionpublic long getFramePosition() Get already captured frames.- Returns:
- frames captured/recorded
 
 - 
runpublic void run() - Specified by:
- runin interface- java.lang.Runnable
 
 - 
addCaptureListenerpublic void addCaptureListener(CaptureListener cl) Add capture listener.- Parameters:
- cl- capture listener
 
 - 
removeCaptureListenerpublic void removeCaptureListener(CaptureListener cl) Remove capture listener.- Parameters:
- cl- capture listener
 
 - 
updatepublic void update(java.util.EventObject eventObject) - Specified by:
- updatein interface- EventQuequeListener
 
 - 
setMeasureLevelpublic void setMeasureLevel(boolean b) Enable audio level measuring. Default is true.- Parameters:
- b- true to enable measuring
 
 - 
getLevelInfospublic LevelInfo[] getLevelInfos() Get current audio levels. Returns the maximum level of the current audio buffer.- Returns:
- current audio levels.
 
 - 
isRecordingpublic boolean isRecording() Returns true if recording.- Returns:
- true if recording
 
 - 
isCapturingpublic boolean isCapturing() Return true if capturing.- Returns:
- true if capturing
 
 - 
setRecordingFilepublic void setRecordingFile(java.io.File file) Set recording file.- Parameters:
- file- recording file
 
 - 
getRecordingFilepublic java.io.File getRecordingFile() Get recording file- Returns:
- recording file
 
 - 
setMixerpublic void setMixer(javax.sound.sampled.Mixer newCaptureMixer) Set the recording device to capture from. The given device will be used if the capture engine is opened the next time.- Parameters:
- newCaptureMixer- recording device
 
 - 
isCaptureOnlypublic boolean isCaptureOnly() Returns true if the engine is only capturing, not recording to file.- Returns:
- true if capturing
 
 - 
setCaptureOnlypublic void setCaptureOnly(boolean captureOnly) Set capture only mode. In capture mode no recording file will be written. Capture mode may be used to measure input level without recording.
 - 
getPreferredBufferSizepublic java.lang.Integer getPreferredBufferSize() Get preferred buffer size in bytes.- Returns:
- preferred buffer size or null if default
 
 - 
setPreferredBufferSizepublic void setPreferredBufferSize(int preferredBufferSize) Set the buffer size of this capture engine in bytes.- Parameters:
- preferredBufferSize-
 
 - 
getBufferSizepublic int getBufferSize() The actually set buffer size.- Returns:
- buffer size
 
 - 
getPeakLevelHoldpublic float[] getPeakLevelHold() Get the maximum peak levels of each channel since the line is open.- Returns:
- array of max peak levels hold
 
 - 
resetPeakHoldpublic void resetPeakHold() Reset the hold peak level maximum.
 - 
getPreferredLineBufferSizepublic java.lang.Integer getPreferredLineBufferSize() Get the preferred audio line buffer size setting.- Returns:
- preferred audio line buffer size
 
 - 
setPreferredLineBufferSizepublic void setPreferredLineBufferSize(java.lang.Integer preferredLineBufferSize) Set the buffer size of the audio line. It is recommended to set this to one second ( @seesetPreferredLineBufferSizeMillis(Float)setPreferredLineBufferSizeMillis(Float)), which is the maximum line buffer size under Windows XP to avoid buffer overruns (especially during garbage collector runs). The default setting is to open the line with default JavaSound settings (500ms for Windows).- Parameters:
- preferredLineBufferSize-
 
 - 
getLineBufferSizepublic java.lang.Integer getLineBufferSize() Get the last used line buffer size. Returns the last used line buffer size.- Returns:
- audio line buffer size or null if capture was not started yet
 
 - 
getLineBufferSizeSecondspublic java.lang.Float getLineBufferSizeSeconds() Get the last used line buffer size in seconds. Returns the last used line buffer size.- Returns:
- audio line buffer size or null if capture line was not opened yet
 
 - 
isOpenpublic boolean isOpen() Return open status.- Returns:
- false if capture engine is closed
 
 - 
getPreferredLineBufferSizeMillispublic java.lang.Float getPreferredLineBufferSizeMillis() Get preferred line buffer size in milliseconds.- Returns:
- preferred line buffer size in milliseconds or null if not set.
 
 - 
setPreferredLineBufferSizeMillispublic void setPreferredLineBufferSizeMillis(java.lang.Float preferredLineBufferSizeMillis) Set the buffer size of the audio line. It is recommended to set this to one second, which is the maximum line buffer size under Windows XP to avoid buffer overruns (especially during garbage collector runs). The default setting is to open the line with default JavSound settings (500ms for Windows).- Parameters:
- preferredLineBufferSizeMillis- preferred line buffer size in milliseconds or null for default
 
 - 
isUseAWTEventThreadpublic boolean isUseAWTEventThread() True if generated events will be queued to AWT event queue.- Returns:
- true if AWT event queue is used
 
 - 
setUseAWTEventThreadpublic void setUseAWTEventThread(boolean useAWTEventThread) Determines if events should be queued to the AWTEventThread. For GUI applications it is recommended to set this to true, to avoid AWT/Swing deadlocks (Swing is not thread safe).- Parameters:
- useAWTEventThread-
 
 - 
setMaxFrameLengthpublic void setMaxFrameLength(long maxFrameLength) Set the maximum length of recording in frames. The capture engine will stop if the amount of frames are recorded.- Parameters:
- maxFrameLength- maximum recording length in frames
 
 - 
mainpublic static void main(java.lang.String[] args) 
 - 
isForceOpeningpublic boolean isForceOpening() 
 - 
setForceOpeningpublic void setForceOpening(boolean forceOpening) 
 - 
getPrimaryRecordTargetpublic PrimaryRecordTarget getPrimaryRecordTarget() 
 - 
setPrimaryRecordTargetpublic void setPrimaryRecordTarget(PrimaryRecordTarget primaryRecordTarget) 
 
- 
 
-