|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
krut.KRUT_Recording.Sampler
public class Sampler
The audio sampler records sound from a DataLine obtained from the AudioSystem. The sound is recorded by obtaining a series of samples buffered in the DataLine and saving them through an OutputStream into a file. Before the samples are saved, a synchronization check (optional) is performed, and if there has been loss of sound, the existing series of samples are "stretched" through an algorithm explained in the source comments, until sync with the system-clock is re-established.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
java.io.File |
audioFile
The file used for saving the audio data. |
int |
channels
The number of recording channels. |
int |
countTimesAhead
IMPORTANT: countTimesAhead should always be 0, or there can be a situation where the sampler can no longer "catch up" with the clock. |
int |
countTimesLag
This is the counter for how many times the sampler should wait before correcting a delayed sample. |
float |
frequency
The recording frequency. |
int |
maxAhead
The maximum ahead times in parts of a second, like this: maxAhead = 50 gives the max ahead 1/50 s = 20ms. |
int |
maxLag
The maximum lag times in parts of a second, like this: maxLag = 50 gives the max lag 1/50 s = 20ms. |
SaveFileChooser |
mySaveQuery
It is necessary for the Sampler to have access to a SaveFileChooser, because the Sampler needs to use the getNextFile() method both in init() and in finished(). |
boolean |
recording
recording is used to flag if the Sampler is recording. |
int |
sampleSize
The sample size in bits. |
long |
sleepTime
The time the sampler sleeps between each time emptying the buffer, in milliseconds. |
float |
speed
This is a measure of the speed the sound should be played back with. |
boolean |
stopped
stopped is a flag to tell the Sampler if it should record or not. |
boolean |
syncAudio
syncAudio is a flag to tell the sampler if it should sync audio, whenever it misses frames, or just continue recording. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Sampler()
Creates a new instance of Sampler Calling this constructor will create a Sampler that uses an output File with the default filename given by the private parameter defaultFileName. |
|
Sampler(java.lang.String fileName)
Creates a new instance of Sampler Calling this constructor will create a Sampler that uses an output File with the specified filename. |
Method Summary | |
---|---|
void |
finish()
Finish up, writing the final audio file from the temporary file already created. |
void |
hold()
Used to sync audio. |
void |
init()
This method sets up all the input streams and output streams that are used in the recording. |
void |
run()
Main working method. |
boolean |
setAudioFile(java.lang.String fileName)
Change the name of the final audio output file to. |
void |
setSyncTime(long syncTime)
Set the syncTime for the run() method This MUST be done before wakeUp() is called to start the recording. |
void |
stopRecording()
Stops the recording. |
void |
wakeUp()
Wakes up threads waiting for the sampler. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public float frequency
public int sampleSize
public int channels
public java.io.File audioFile
public boolean recording
public boolean stopped
public boolean syncAudio
public int countTimesLag
public int countTimesAhead
public float speed
public SaveFileChooser mySaveQuery
public long sleepTime
public int maxLag
public int maxAhead
Constructor Detail |
---|
public Sampler(java.lang.String fileName)
fileName
- The file name of the audio file that
is created by this Sampler.public Sampler()
Method Detail |
---|
public void init()
public void stopRecording()
public void setSyncTime(long syncTime)
syncTime
- The time to wait (in millis) between each
audio sync check.public void hold()
public void wakeUp()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public boolean setAudioFile(java.lang.String fileName)
fileName
- The name of the file that should be
created by this Sampler.
public void finish()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |