com.jsyn.util
Class WaveFileWriter

java.lang.Object
  extended by com.jsyn.util.WaveFileWriter
All Implemented Interfaces:
AudioOutputStream

public class WaveFileWriter
extends java.lang.Object
implements AudioOutputStream

Write audio data to a WAV file. Just write float data, then close().


Constructor Summary
WaveFileWriter(java.io.File outputFile)
          Create a writer that will write to the specified file.
 
Method Summary
 void close()
           
 void setBitsPerSample(int i)
          Only 16 bit samples supported at the moment.
 void setFrameRate(int frameRate)
           
 void setSamplesPerFrame(int samplesPerFrame)
          For stereo, set this to 2.
 void write(double value)
          Write audio to the WAV file.
 void write(double[] buffer)
          Write audio to the WAV file.
 void write(double[] buffer, int start, int count)
          Write audio to the WAV file.
 void writeDataChunkHeader()
          Write a 'data' chunk header to the WAV file.
 void writeFormatChunk()
          Write an 'fmt ' chunk to the WAV file containing the given information.
 void writeIntLittle(int n)
          Write a 32 bit integer to the stream in Little Endian format.
 void writeShortLittle(short n)
          Write a 16 bit intgeer to the stream in Little Endian format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaveFileWriter

public WaveFileWriter(java.io.File outputFile)
               throws java.io.FileNotFoundException
Create a writer that will write to the specified file.

Parameters:
outputFile -
Throws:
java.io.FileNotFoundException
Method Detail

setFrameRate

public void setFrameRate(int frameRate)

setSamplesPerFrame

public void setSamplesPerFrame(int samplesPerFrame)
For stereo, set this to 2.


setBitsPerSample

public void setBitsPerSample(int i)
Only 16 bit samples supported at the moment.


close

public void close()
           throws java.io.IOException
Specified by:
close in interface AudioOutputStream
Throws:
java.io.IOException

write

public void write(double[] buffer)
           throws java.io.IOException
Write audio to the WAV file.

Specified by:
write in interface AudioOutputStream
Throws:
java.io.IOException

write

public void write(double value)
           throws java.io.IOException
Write audio to the WAV file.

Specified by:
write in interface AudioOutputStream
Throws:
java.io.IOException

write

public void write(double[] buffer,
                  int start,
                  int count)
           throws java.io.IOException
Write audio to the WAV file.

Specified by:
write in interface AudioOutputStream
Throws:
java.io.IOException

writeIntLittle

public void writeIntLittle(int n)
                    throws java.io.IOException
Write a 32 bit integer to the stream in Little Endian format.

Throws:
java.io.IOException

writeShortLittle

public void writeShortLittle(short n)
                      throws java.io.IOException
Write a 16 bit intgeer to the stream in Little Endian format.

Throws:
java.io.IOException

writeFormatChunk

public void writeFormatChunk()
                      throws java.io.IOException
Write an 'fmt ' chunk to the WAV file containing the given information.

Throws:
java.io.IOException

writeDataChunkHeader

public void writeDataChunkHeader()
                          throws java.io.IOException
Write a 'data' chunk header to the WAV file. This should be followed by call to writeShortLittle() to write the data to the chunk. If you do not know the length of the data chunk when calling this method, then pass zero for the size. Then when you finish writing the data call fixSizes().

Throws:
java.io.IOException