Package SoundRecorder
Class PamAudioFileStorage
java.lang.Object
SoundRecorder.PamAudioFileStorage
- All Implemented Interfaces:
RecorderStorage
Implementation of RecorderStorage specific to audio files.
- Author:
- Doug Gillespie
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addData
(long dataTimeMillis, double[][] newData) Adds data to the store.boolean
Closes the storage (and stops recording).long
Get the number of frames in the current file.long
Get the file length in millisecondsGets the store file name.long
Get the file size in bytes/ Note that this is the physical size of the file which may not relate to the file length if a compressed recording system is used.long
Get the time the current file started at.long
Get the absolute maximum file size in bytes for this type of storageboolean
openStorage
(AudioFileFormat.Type fileType, long recordingStart, float sampleRate, int nChannels, int bitDepth) Write data to an audio file.boolean
reOpenStorage
(long recordingStart) Reopens the recording storage in a new file (if appropriate) This is done in the RecorderStorage class rather than as separate calls to closeStorage and openStorage in
-
Constructor Details
-
PamAudioFileStorage
-
-
Method Details
-
getFileName
Description copied from interface:RecorderStorage
Gets the store file name. The file name must be set to null when the file is closed.- Specified by:
getFileName
in interfaceRecorderStorage
- Returns:
- file name (or name of other store type)
-
addData
public boolean addData(long dataTimeMillis, double[][] newData) Description copied from interface:RecorderStorage
Adds data to the store. Data are in a double array newData[channels][samples]. The number of channels must match the number of channels in the call to openStorage and the number of samples must be the same for all channels.- Specified by:
addData
in interfaceRecorderStorage
- Parameters:
dataTimeMillis
- the time of the datanewData
- array of arrays of double data arranged by channel and sample- Returns:
- true if OK.
-
closeStorage
public boolean closeStorage()Description copied from interface:RecorderStorage
Closes the storage (and stops recording). The input and output data streams are flushed and closed. This automatically causes the write thread to terminate.- Specified by:
closeStorage
in interfaceRecorderStorage
- Returns:
- true if OK
-
openStorage
public boolean openStorage(AudioFileFormat.Type fileType, long recordingStart, float sampleRate, int nChannels, int bitDepth) Write data to an audio file.Writing audio data is relatively straight forward. The actual writing is done in a separate thread. That thread needs an InputStream to read data from. This is one end of a pair of PipedInput and PipedOutput Streams. This thread writes data into the other end of the pipe as it arrives.
- Specified by:
openStorage
in interfaceRecorderStorage
- Parameters:
fileType
- Type of file storage (e.g. AU, AIFF, WAVE)recordingStart
- Start time of recording in milliseconds. The storage system should base a file name on the timesampleRate
- Sample rate for the recordingnChannels
- Number of channels in the recordingbitDepth
- Number of bits (e.g. 8, 16, 24)- Returns:
- true if OK
-
reOpenStorage
public boolean reOpenStorage(long recordingStart) Description copied from interface:RecorderStorage
Reopens the recording storage in a new file (if appropriate) This is done in the RecorderStorage class rather than as separate calls to closeStorage and openStorage in- Specified by:
reOpenStorage
in interfaceRecorderStorage
- Parameters:
recordingStart
- new recording start time in milliseconds- Returns:
- true if OK/
-
getFileSizeBytes
public long getFileSizeBytes()Description copied from interface:RecorderStorage
Get the file size in bytes/ Note that this is the physical size of the file which may not relate to the file length if a compressed recording system is used.- Specified by:
getFileSizeBytes
in interfaceRecorderStorage
- Returns:
- file size in bytes
-
getFileFrames
public long getFileFrames()Description copied from interface:RecorderStorage
Get the number of frames in the current file.- Specified by:
getFileFrames
in interfaceRecorderStorage
- Returns:
- the number of frames in the current file.
-
getFileMilliSeconds
public long getFileMilliSeconds()Description copied from interface:RecorderStorage
Get the file length in milliseconds- Specified by:
getFileMilliSeconds
in interfaceRecorderStorage
- Returns:
- the file length in milliseconds.
-
getFileStartTime
public long getFileStartTime()Description copied from interface:RecorderStorage
Get the time the current file started at.- Specified by:
getFileStartTime
in interfaceRecorderStorage
- Returns:
- time file started at or -1 if no current file.
-
getMaxFileSizeBytes
public long getMaxFileSizeBytes()Description copied from interface:RecorderStorage
Get the absolute maximum file size in bytes for this type of storage- Specified by:
getMaxFileSizeBytes
in interfaceRecorderStorage
- Returns:
- Maximum size. Return Long.MAX_VALUE if it's indefinite.
-