SoundRecorder
Class PamAudioFileStorage

java.lang.Object
  extended by SoundRecorder.PamAudioFileStorage
All Implemented Interfaces:
RecorderStorage

public class PamAudioFileStorage
extends java.lang.Object
implements RecorderStorage

Implementation of RecorderStorage specific to audio files.

Author:
Doug Gillespie
See Also:
RecorderStorage

Nested Class Summary
(package private)  class PamAudioFileStorage.WriteThread
          WriteThread makes a single call to AudioSystem.write.
 
Field Summary
private  java.io.File audioFile
           
(package private)  javax.sound.sampled.AudioFileFormat.Type audioFileType
           
private  javax.sound.sampled.AudioFormat audioFormat
           
private  javax.sound.sampled.AudioInputStream audioInputStream
           
(package private)  int bitDepth
           
(package private)  byte[] byteBuffer
           
(package private)  long fileBytes
           
private  java.lang.String fileName
           
(package private)  long fileStartMillis
           
(package private)  javax.sound.sampled.AudioFileFormat.Type fileType
           
(package private)  long lastDataMillis
           
(package private)  int nChannels
           
private  java.io.PipedInputStream pipedInputStream
           
private  java.io.PipedOutputStream pipedOutputStream
           
private  RecorderControl recorderControl
           
(package private)  float sampleRate
           
(package private)  long totalFrames
           
private  java.lang.Thread writeThread
           
 
Constructor Summary
PamAudioFileStorage(RecorderControl recorderControl)
           
 
Method Summary
 boolean addData(long dataTimeMillis, double[][] newData)
          Adds data to the store.
 boolean closeStorage()
          Closes the storage (and stops recording).
 long getFileBytes()
          Get the file size in bytes
 long getFileMilliSeconds()
          Get the file length in milliseconds
 java.lang.String getFileName()
          Gets the store file name.
 boolean openStorage(javax.sound.sampled.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
private  void writeData()
          Called within the write thread, this does not return until the pipes get closed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileName

private java.lang.String fileName

recorderControl

private RecorderControl recorderControl

audioFormat

private javax.sound.sampled.AudioFormat audioFormat

audioInputStream

private javax.sound.sampled.AudioInputStream audioInputStream

audioFile

private java.io.File audioFile

pipedInputStream

private java.io.PipedInputStream pipedInputStream

pipedOutputStream

private java.io.PipedOutputStream pipedOutputStream

byteBuffer

byte[] byteBuffer

fileType

javax.sound.sampled.AudioFileFormat.Type fileType

fileBytes

long fileBytes

fileStartMillis

long fileStartMillis

lastDataMillis

long lastDataMillis

writeThread

private java.lang.Thread writeThread

totalFrames

long totalFrames

sampleRate

float sampleRate

audioFileType

javax.sound.sampled.AudioFileFormat.Type audioFileType

nChannels

int nChannels

bitDepth

int bitDepth
Constructor Detail

PamAudioFileStorage

public PamAudioFileStorage(RecorderControl recorderControl)
Method Detail

getFileName

public java.lang.String 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 interface RecorderStorage
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 interface RecorderStorage
Parameters:
dataTimeMillis - the time of the data
newData - 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 interface RecorderStorage
Returns:
true if OK

openStorage

public boolean openStorage(javax.sound.sampled.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 interface RecorderStorage
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 time
sampleRate - Sample rate for the recording
nChannels - Number of channels in the recording
bitDepth - 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 interface RecorderStorage
Parameters:
recordingStart - new recording start time in milliseconds
Returns:
true if OK/

writeData

private void writeData()
Called within the write thread, this does not return until the pipes get closed.


getFileBytes

public long getFileBytes()
Description copied from interface: RecorderStorage
Get the file size in bytes

Specified by:
getFileBytes in interface RecorderStorage
Returns:
file size in bytes

getFileMilliSeconds

public long getFileMilliSeconds()
Description copied from interface: RecorderStorage
Get the file length in milliseconds

Specified by:
getFileMilliSeconds in interface RecorderStorage
Returns:
the file length in milliseconds.