Class PcmWaveWriter

java.lang.Object
javaforce.codec.speex.AudioFileWriter
javaforce.codec.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(2, 44100);
 byte[] silence = new byte[16*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$
Author:
Jim Lawrence, helloNetwork.com, Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
  • Field Details

    • WAVE_FORMAT_PCM

      public static final short WAVE_FORMAT_PCM
      Wave type code of PCM
      See Also:
    • WAVE_FORMAT_SPEEX

      public static final short WAVE_FORMAT_SPEEX
      Wave type code of Speex
      See Also:
    • WAVE_FRAME_SIZES

      public static final int[][][] WAVE_FRAME_SIZES
      Table describing the number of frames per packet in a Speex Wave file, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10). See end of file for exerpt from SpeexACM code for more explanations.
    • WAVE_BITS_PER_FRAME

      public static final int[][][] WAVE_BITS_PER_FRAME
      Table describing the number of bit per Speex frame, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10). See end of file for exerpt from SpeexACM code for more explanations.
  • Constructor Details

    • PcmWaveWriter

      public PcmWaveWriter()
      Constructor.
    • PcmWaveWriter

      public PcmWaveWriter(int sampleRate, int channels)
      Constructor.
      Parameters:
      sampleRate - the number of samples per second.
      channels - the number of audio channels (1=mono, 2=stereo, ...).
    • PcmWaveWriter

      public PcmWaveWriter(int mode, int quality, int sampleRate, int channels, int nframes, boolean vbr)
      Constructor.
      Parameters:
      mode - the mode of the encoder (0=NB, 1=WB, 2=UWB).
      quality -
      sampleRate - the number of samples per second.
      channels - the number of audio channels (1=mono, 2=stereo, ...).
      nframes - the number of frames per speex packet.
      vbr -
  • Method Details

    • close

      public void close() throws IOException
      Closes the output file. MUST be called to have a correct stream.
      Specified by:
      close in class AudioFileWriter
      Throws:
      IOException - if there was an exception closing the Audio Writer.
    • open

      public void open(File file) throws IOException
      Open the output file.
      Specified by:
      open in class AudioFileWriter
      Parameters:
      file - - file to open.
      Throws:
      IOException - if there was an exception opening the Audio Writer.
    • open

      public void open(String filename) throws IOException
      Open the output file.
      Specified by:
      open in class AudioFileWriter
      Parameters:
      filename - filename to open.
      Throws:
      IOException - if there was an exception opening the Audio Writer.
    • writeHeader

      public void writeHeader(String comment) throws 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:
      IOException
    • writePacket

      public void writePacket(byte[] data, int offset, int len) throws 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:
      IOException