org.xiph.speex
Class PcmWaveWriter

java.lang.Object
  extended byorg.xiph.speex.AudioFileWriter
      extended byorg.xiph.speex.PcmWaveWriter

public class PcmWaveWriter
extends AudioFileWriter

Writes basic PCM wave files from binary audio data.

Here's an example that writes 2 seconds of silence

 PcmWaveWriter s_wsw = new PcmWaveWriter();
 byte[] silence = new byte[16*2*44100];
 wsw.SetFormat(2, 44100);
 wsw.Open("C:\\out.wav");
 wsw.WriteHeader(); 
 wsw.WriteData(silence, 0, silence.length);
 wsw.WriteData(silence, 0, silence.length);
 wsw.Close(); 
 

Version:
$Revision: 1.7 $
Author:
Jim Lawrence, helloNetwork.com, Marc Gimpel, Wimba S.A. (marc@wimba.com)

Field Summary
private  int channels
           
private  java.io.RandomAccessFile raf
           
private  int sampleRate
           
private  int size
           
 
Constructor Summary
PcmWaveWriter()
          Constructor.
PcmWaveWriter(int channels, int sampleRate)
          Constructor.
 
Method Summary
 void close()
          Closes the output file.
 void open(java.lang.String filename)
          Open the output file.
private  void setFormat(int channels, int sampleRate)
          Sets the output format.
 void writeHeader(java.lang.String comment)
          Writes the initial data chunks that start the wave file.
 void writePacket(byte[] data, int offset, int len)
          Writes a packet of audio.
 
Methods inherited from class org.xiph.speex.AudioFileWriter
writeInt, writeInt, writeLong, writeShort, writeShort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raf

private java.io.RandomAccessFile raf

channels

private int channels

sampleRate

private int sampleRate

size

private int size
Constructor Detail

PcmWaveWriter

public PcmWaveWriter()
Constructor.


PcmWaveWriter

public PcmWaveWriter(int channels,
                     int sampleRate)
Constructor.

Parameters:
channels -
sampleRate -
Method Detail

setFormat

private void setFormat(int channels,
                       int sampleRate)
Sets the output format. Must be called before WriteHeader().

Parameters:
channels -
sampleRate -

close

public void close()
           throws java.io.IOException
Closes the output file. MUST be called to have a correct stream.

Specified by:
close in class AudioFileWriter
Throws:
java.io.IOException

open

public void open(java.lang.String filename)
          throws java.io.IOException
Open the output file.

Specified by:
open in class AudioFileWriter
Parameters:
filename - filename to open.
Throws:
java.io.IOException

writeHeader

public void writeHeader(java.lang.String comment)
                 throws java.io.IOException
Writes the initial data chunks that start the wave file. Prepares file for data samples to written.

Specified by:
writeHeader in class AudioFileWriter
Parameters:
comment - ignored by the WAV header.
Throws:
java.io.IOException

writePacket

public void writePacket(byte[] data,
                        int offset,
                        int len)
                 throws java.io.IOException
Writes a packet of audio.

Specified by:
writePacket in class AudioFileWriter
Parameters:
data - audio data
offset - the offset from which to start reading the data.
len - the length of data to read.
Throws:
java.io.IOException


Copyright © 1999-2004 Wimba S.A. All Rights Reserved.