Sharkysoft home

lava.riff.wave
Class WaveStreamWriter

java.lang.Object
  |
  +--lava.riff.wave.WaveStreamWriter
Direct Known Subclasses:
PcmWaveStreamWriter

public abstract class WaveStreamWriter
extends java.lang.Object

Base class for .wav file encoders.

Details: WaveStreamWriter is the generic base class for wave file encoders. This class handles basic wave stream writing tasks that are common to all wave writers regardless of the encoding format.


Field Summary
protected  RiffStreamWriter rsw
          RIFF file generator.
 
Constructor Summary
WaveStreamWriter(IRiffOutput raos, WaveFormatChunk fmt_chunk)
          Outputs format chunk.
 
Method Summary
abstract  void beginSamples(long duration)
          Opens wave sample data chunk.
abstract  void close()
          Closes stream.
abstract  void endSamples()
          Closes wave data chunk.
abstract  void writeSamples(java.lang.Object samples, int samples_from, int duration)
          Encodes and writes samples.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rsw

protected RiffStreamWriter rsw
RIFF file generator.

Details: rsw is the underlying RiffStreamWriter used to generate this .wav file, which is a special kind of RIFF file.

Constructor Detail

WaveStreamWriter

public WaveStreamWriter(IRiffOutput raos,
                        WaveFormatChunk fmt_chunk)
                 throws java.io.IOException
Outputs format chunk.

Details: This constructor opens a new RiffStreamWriter and writes the given wave format chunk (fmt_chunk), in preparation for generating the rest of the .wav file.

Parameters:
raos - the destination output stream
fmt_chunk - the format chunk
Method Detail

beginSamples

public abstract void beginSamples(long duration)
                           throws java.io.IOException
Opens wave sample data chunk.

Details: beginSamples prepares this WaveStreamWriter to begin recording wave sample data. This method must be called before writeSamples can be called.

If the number of (full) samples to be written is known ahead of time, that value should be provided in the duration parameter; otherwise, set this parameter to 0. Providing the duration value ahead of time allows the RIFF writer to complete the header that must appear before the sample data. Otherwise, the RIFF writer will need to seek backward in the file to complete the header after endSamples is called, which can strain the underlying buffering mechanisms if the data isn't being written to a standard random access file.

Parameters:
duration - number of samples
Throws:
java.io.IOException - if an I/O error occurs

writeSamples

public abstract void writeSamples(java.lang.Object samples,
                                  int samples_from,
                                  int duration)
                           throws java.io.IOException
Encodes and writes samples.

Details: writeSamples writes the given samples (in samples) into the wave file's wave data chunk. The sample values are given in a sample array, which is described in the package header. If the sample resolution implied by the array's primitive type is not the sample resolution of this wave file (as set in the format chunk), this method will automatically convert the samples before writing them.

The first sample in the given array is taken from samples [samples_from]. Exactly duration * wChannels values are encoded and written to the stream, where wChannels is the number of channels as set in the format chunk.

Parameters:
samples - sample array
samples_from - starting offset into array
duration - number of samples to process
Throws:
java.io.IOException - if an I/O error occurs

endSamples

public abstract void endSamples()
                         throws java.io.IOException
Closes wave data chunk.

Details: Call endSamples when there are no more wave samples to encode and write to the wave stream. Because this method causes the underlying RIFF stream generator to close the wave data chunk, no more samples can be written after this method is called.

Throws:
java.io.IOException - if an I/O error occurs

close

public abstract void close()
                    throws java.io.IOException
Closes stream.

Details: This method closes all open chunks in the wave stream and completes the stream. The close method of the underlying RiffStreamWriter is also called, which in turn calls the close method of its underlying IRiffOutput.

Throws:
java.io.IOException - if an I/O error occurs

Sharkysoft home