org.xiph.speex
Class OggSpeexWriter

java.lang.Object
  extended by org.xiph.speex.AudioFileWriter
      extended by org.xiph.speex.OggSpeexWriter

public class OggSpeexWriter
extends AudioFileWriter

Ogg Speex Writer

Version:
$Revision: 1.2 $
Author:
Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)

Field Summary
private  int channels
          Defines the number of channels of the audio input (1=mono, 2=stereo).
private  byte[] dataBuffer
          Data buffer
private  int dataBufferPtr
          Pointer within the Data buffer
private  long granulepos
          Absolute granule position (the number of audio samples from beginning of file to end of Ogg Packet).
private  byte[] headerBuffer
          Header buffer
private  int headerBufferPtr
          Pointer within the Header buffer
private  int mode
          Defines the encoder mode (0=NB, 1=WB and 2-UWB).
private  int nframes
          Defines the number of frames per speex packet.
private  java.io.OutputStream out
          The OutputStream
private  int packetCount
          Speex packet count within an Ogg Page
static int PACKETS_PER_OGG_PAGE
          Number of packets in an Ogg page (must be less than 255)
private  int pageCount
          Ogg Page count
private  int sampleRate
          Defines the sampling rate of the audio input.
private  int size
           
private  int streamSerialNumber
          Ogg Stream Serial Number
private  boolean vbr
          Defines whether or not to use VBR (Variable Bit Rate).
 
Constructor Summary
OggSpeexWriter()
          Builds an Ogg Speex Writer.
OggSpeexWriter(int mode, int sampleRate, int channels, int nframes, boolean vbr)
          Builds an Ogg Speex Writer.
 
Method Summary
 void close()
          Closes the output file.
private  void flush(boolean eos)
          Flush the Ogg page out of the buffers into the file.
 void open(java.io.File file)
          Open the output file.
 void open(java.lang.String filename)
          Open the output file.
private  void setFormat(int mode, int sampleRate, int channels, int nframes, boolean vbr)
          Sets the output format.
 void setSerialNumber(int serialNumber)
          Sets the Stream Serial Number.
 void writeHeader(java.lang.String comment)
          Writes the header pages that start the Ogg Speex file.
 void writePacket(byte[] data, int offset, int len)
          Writes a packet of audio.
 
Methods inherited from class org.xiph.speex.AudioFileWriter
buildOggPageHeader, buildSpeexComment, buildSpeexHeader, writeInt, writeInt, writeInt, writeLong, writeLong, writeOggPageHeader, writeShort, writeShort, writeShort, writeSpeexComment, writeSpeexHeader, writeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKETS_PER_OGG_PAGE

public static final int PACKETS_PER_OGG_PAGE
Number of packets in an Ogg page (must be less than 255)

See Also:
Constant Field Values

out

private java.io.OutputStream out
The OutputStream


mode

private int mode
Defines the encoder mode (0=NB, 1=WB and 2-UWB).


sampleRate

private int sampleRate
Defines the sampling rate of the audio input.


channels

private int channels
Defines the number of channels of the audio input (1=mono, 2=stereo).


nframes

private int nframes
Defines the number of frames per speex packet.


vbr

private boolean vbr
Defines whether or not to use VBR (Variable Bit Rate).


size

private int size

streamSerialNumber

private int streamSerialNumber
Ogg Stream Serial Number


dataBuffer

private byte[] dataBuffer
Data buffer


dataBufferPtr

private int dataBufferPtr
Pointer within the Data buffer


headerBuffer

private byte[] headerBuffer
Header buffer


headerBufferPtr

private int headerBufferPtr
Pointer within the Header buffer


pageCount

private int pageCount
Ogg Page count


packetCount

private int packetCount
Speex packet count within an Ogg Page


granulepos

private long granulepos
Absolute granule position (the number of audio samples from beginning of file to end of Ogg Packet).

Constructor Detail

OggSpeexWriter

public OggSpeexWriter()
Builds an Ogg Speex Writer.


OggSpeexWriter

public OggSpeexWriter(int mode,
                      int sampleRate,
                      int channels,
                      int nframes,
                      boolean vbr)
Builds an Ogg Speex Writer.

Parameters:
mode - the mode of the encoder (0=NB, 1=WB, 2=UWB).
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 Detail

setFormat

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

Parameters:
mode - the mode of the encoder (0=NB, 1=WB, 2=UWB).
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 -

setSerialNumber

public void setSerialNumber(int serialNumber)
Sets the Stream Serial Number. Must not be changed mid stream.

Parameters:
serialNumber -

close

public void close()
           throws java.io.IOException
Closes the output file.

Specified by:
close in class AudioFileWriter
Throws:
java.io.IOException - if there was an exception closing the Audio Writer.

open

public void open(java.io.File file)
          throws java.io.IOException
Open the output file.

Specified by:
open in class AudioFileWriter
Parameters:
file - - file to open.
Throws:
java.io.IOException - if there was an exception opening the Audio Writer.

open

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

Specified by:
open in class AudioFileWriter
Parameters:
filename - - file to open.
Throws:
java.io.IOException - if there was an exception opening the Audio Writer.

writeHeader

public void writeHeader(java.lang.String comment)
                 throws java.io.IOException
Writes the header pages that start the Ogg Speex file. Prepares file for data to be written.

Specified by:
writeHeader in class AudioFileWriter
Parameters:
comment - description to be included in the 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

flush

private void flush(boolean eos)
            throws java.io.IOException
Flush the Ogg page out of the buffers into the file.

Parameters:
eos - - end of stream
Throws:
java.io.IOException


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