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 Summary
Fields Modifier and Type Field Description static int
CAPTURE
static int
CLOSE
static javax.sound.sampled.AudioFileFormat
DEF_AUDIO_FILE_FORMAT
static javax.sound.sampled.AudioFileFormat.Type
DEF_AUDIO_FILE_TYPE
static javax.sound.sampled.AudioFormat
DEF_AUDIO_FORMAT
static int
ERROR
static int
PAUSE
static int
RECORD
static int
STOP
-
Constructor Summary
Constructors 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCaptureListener(CaptureListener cl)
Add capture listener.void
close()
Close engine.javax.sound.sampled.AudioFileFormat
getAudioFileFormat()
Get audio file format.javax.sound.sampled.AudioFormat
getAudioFormat()
Get audio format.int
getBufferSize()
The actually set buffer size.long
getFramePosition()
Get already captured frames.LevelInfo[]
getLevelInfos()
Get current audio levels.java.lang.Integer
getLineBufferSize()
Get the last used line buffer size.java.lang.Float
getLineBufferSizeSeconds()
Get the last used line buffer size in seconds.long
getMaxFrameLength()
Get maximum recording length in frames.java.lang.Integer
getMaxLineBufferSize()
Get maximum line bugffer size.java.lang.Integer
getMinLineBufferSize()
Get minimum line bugffer size.float[]
getPeakLevelHold()
Get the maximum peak levels of each channel since the line is open.java.lang.Integer
getPreferredBufferSize()
Get preferred buffer size in bytes.java.lang.Integer
getPreferredLineBufferSize()
Get the preferred audio line buffer size setting.java.lang.Float
getPreferredLineBufferSizeMillis()
Get preferred line buffer size in milliseconds.PrimaryRecordTarget
getPrimaryRecordTarget()
java.io.File
getRecordingFile()
Get recording fileboolean
isCaptureOnly()
Returns true if the engine is only capturing, not recording to file.boolean
isCapturing()
Return true if capturing.boolean
isForceOpening()
boolean
isOpen()
Return open status.boolean
isRecording()
Returns true if recording.boolean
isUseAWTEventThread()
True if generated events will be queued to AWT event queue.boolean
isUseTempFile()
static void
main(java.lang.String[] args)
void
open()
Open audio line and engine.void
pause()
Pause capturing/recording.void
removeCaptureListener(CaptureListener cl)
Remove capture listener.void
resetPeakHold()
Reset the hold peak level maximum.void
run()
void
setAudioFileFormat(javax.sound.sampled.AudioFileFormat aff)
Set audio file format.void
setAudioFormat(javax.sound.sampled.AudioFormat af)
Set audio format.void
setCaptureOnly(boolean captureOnly)
Set capture only mode.void
setForceOpening(boolean forceOpening)
void
setMaxFrameLength(long maxFrameLength)
Set the maximum length of recording in frames.void
setMeasureLevel(boolean b)
Enable audio level measuring.void
setMixer(javax.sound.sampled.Mixer newCaptureMixer)
Set the recording device to capture from.void
setPreferredBufferSize(int preferredBufferSize)
Set the buffer size of this capture engine in bytes.void
setPreferredLineBufferSize(java.lang.Integer preferredLineBufferSize)
Set the buffer size of the audio line.void
setPreferredLineBufferSizeMillis(java.lang.Float preferredLineBufferSizeMillis)
Set the buffer size of the audio line.void
setPrimaryRecordTarget(PrimaryRecordTarget primaryRecordTarget)
void
setRecordingFile(java.io.File file)
Set recording file.void
setUseAWTEventThread(boolean useAWTEventThread)
Determines if events should be queued to the AWTEventThread.void
setUseTempFile(boolean useTempFile)
void
start()
Start capturing or recording.void
stop()
Stop engine.void
update(java.util.EventObject eventObject)
-
-
-
Field Detail
-
CLOSE
public static final int CLOSE
- See Also:
- Constant Field Values
-
STOP
public static final int STOP
- See Also:
- Constant Field Values
-
CAPTURE
public static final int CAPTURE
- See Also:
- Constant Field Values
-
RECORD
public static final int RECORD
- See Also:
- Constant Field Values
-
PAUSE
public static final int PAUSE
- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
DEF_AUDIO_FILE_TYPE
public static javax.sound.sampled.AudioFileFormat.Type DEF_AUDIO_FILE_TYPE
-
DEF_AUDIO_FORMAT
public static javax.sound.sampled.AudioFormat DEF_AUDIO_FORMAT
-
DEF_AUDIO_FILE_FORMAT
public static javax.sound.sampled.AudioFileFormat DEF_AUDIO_FILE_FORMAT
-
-
Constructor Detail
-
Capture
public Capture()
Create capture engine.
-
Capture
public Capture(javax.sound.sampled.Mixer device)
Create capture engine which will capture audio data from given device.- Parameters:
device
- audio device to use
-
Capture
public Capture(javax.sound.sampled.Mixer device, java.io.File recFile, javax.sound.sampled.AudioFileFormat aff)
Create capture engine.- Parameters:
device
- audio device to userecFile
- recordingfileaff
- audio file format
-
-
Method Detail
-
isUseTempFile
public boolean isUseTempFile()
-
setUseTempFile
public void setUseTempFile(boolean useTempFile)
-
setAudioFileFormat
public void setAudioFileFormat(javax.sound.sampled.AudioFileFormat aff)
Set audio file format.- Parameters:
aff
- audio file format
-
getAudioFileFormat
public javax.sound.sampled.AudioFileFormat getAudioFileFormat()
Get audio file format.- Returns:
- audio file format
-
setAudioFormat
public void setAudioFormat(javax.sound.sampled.AudioFormat af)
Set audio format.- Parameters:
af
- audio format.
-
getAudioFormat
public javax.sound.sampled.AudioFormat getAudioFormat()
Get audio format.- Returns:
- audio format
-
getMinLineBufferSize
public java.lang.Integer getMinLineBufferSize()
Get minimum line bugffer size.- Returns:
- minimum line buffer size or null if not available
-
getMaxLineBufferSize
public java.lang.Integer getMaxLineBufferSize()
Get maximum line bugffer size.- Returns:
- maximum line buffer size or null if not available
-
open
public void open() throws CaptureException
Open audio line and engine.- Throws:
CaptureException
-
start
public void start()
Start capturing or recording.
-
getMaxFrameLength
public long getMaxFrameLength()
Get maximum recording length in frames.- Returns:
- length in frames
-
pause
public void pause()
Pause capturing/recording. If already paused the engine will be restarted.
-
stop
public void stop() throws CaptureException
Stop engine.- Throws:
CaptureException
-
close
public void close() throws CaptureException
Close engine.- Throws:
CaptureException
-
getFramePosition
public long getFramePosition()
Get already captured frames.- Returns:
- frames captured/recorded
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
addCaptureListener
public void addCaptureListener(CaptureListener cl)
Add capture listener.- Parameters:
cl
- capture listener
-
removeCaptureListener
public void removeCaptureListener(CaptureListener cl)
Remove capture listener.- Parameters:
cl
- capture listener
-
update
public void update(java.util.EventObject eventObject)
- Specified by:
update
in interfaceEventQuequeListener
-
setMeasureLevel
public void setMeasureLevel(boolean b)
Enable audio level measuring. Default is true.- Parameters:
b
- true to enable measuring
-
getLevelInfos
public LevelInfo[] getLevelInfos()
Get current audio levels. Returns the maximum level of the current audio buffer.- Returns:
- current audio levels.
-
isRecording
public boolean isRecording()
Returns true if recording.- Returns:
- true if recording
-
isCapturing
public boolean isCapturing()
Return true if capturing.- Returns:
- true if capturing
-
setRecordingFile
public void setRecordingFile(java.io.File file)
Set recording file.- Parameters:
file
- recording file
-
getRecordingFile
public java.io.File getRecordingFile()
Get recording file- Returns:
- recording file
-
setMixer
public 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
-
isCaptureOnly
public boolean isCaptureOnly()
Returns true if the engine is only capturing, not recording to file.- Returns:
- true if capturing
-
setCaptureOnly
public 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.
-
getPreferredBufferSize
public java.lang.Integer getPreferredBufferSize()
Get preferred buffer size in bytes.- Returns:
- preferred buffer size or null if default
-
setPreferredBufferSize
public void setPreferredBufferSize(int preferredBufferSize)
Set the buffer size of this capture engine in bytes.- Parameters:
preferredBufferSize
-
-
getBufferSize
public int getBufferSize()
The actually set buffer size.- Returns:
- buffer size
-
getPeakLevelHold
public float[] getPeakLevelHold()
Get the maximum peak levels of each channel since the line is open.- Returns:
- array of max peak levels hold
-
resetPeakHold
public void resetPeakHold()
Reset the hold peak level maximum.
-
getPreferredLineBufferSize
public java.lang.Integer getPreferredLineBufferSize()
Get the preferred audio line buffer size setting.- Returns:
- preferred audio line buffer size
-
setPreferredLineBufferSize
public 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
-
-
getLineBufferSize
public 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
-
getLineBufferSizeSeconds
public 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
-
isOpen
public boolean isOpen()
Return open status.- Returns:
- false if capture engine is closed
-
getPreferredLineBufferSizeMillis
public java.lang.Float getPreferredLineBufferSizeMillis()
Get preferred line buffer size in milliseconds.- Returns:
- preferred line buffer size in milliseconds or null if not set.
-
setPreferredLineBufferSizeMillis
public 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
-
isUseAWTEventThread
public boolean isUseAWTEventThread()
True if generated events will be queued to AWT event queue.- Returns:
- true if AWT event queue is used
-
setUseAWTEventThread
public 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
-
-
setMaxFrameLength
public 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
-
main
public static void main(java.lang.String[] args)
-
isForceOpening
public boolean isForceOpening()
-
setForceOpening
public void setForceOpening(boolean forceOpening)
-
getPrimaryRecordTarget
public PrimaryRecordTarget getPrimaryRecordTarget()
-
setPrimaryRecordTarget
public void setPrimaryRecordTarget(PrimaryRecordTarget primaryRecordTarget)
-
-