org.xiph.speex

Class AudioFileWriter

Known Direct Subclasses:
OggSpeexWriter, PcmWaveWriter, RawWriter

public abstract class AudioFileWriter
extends java.lang.Object

Abstract Class that defines an Audio File Writer.
Version:
$Revision: 1.2 $
Author:
Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)

Method Summary

static byte[]
buildOggPageHeader(int headerType, long granulepos, int streamSerialNumber, int pageCount, int packetCount, byte[] packetSizes)
Builds and returns an Ogg Page Header.
static byte[]
buildSpeexComment(String comment)
Builds and returns a Speex Comment.
static byte[]
buildSpeexHeader(int sampleRate, int mode, int channels, boolean vbr, int nframes)
Builds a Speex Header.
abstract void
close()
Closes the output file.
abstract void
open(File file)
Open the output file.
abstract void
open(String filename)
Open the output file.
abstract void
writeHeader(String comment)
Writes the header pages that start the Ogg Speex file.
static void
writeInt(DataOutput out, int v)
Writes a Little-endian int.
static void
writeInt(OutputStream os, int v)
Writes a Little-endian int.
static void
writeInt(byte[] data, int offset, int v)
Writes a Little-endian int.
static void
writeLong(OutputStream os, long v)
Writes a Little-endian long.
static void
writeLong(byte[] data, int offset, long v)
Writes a Little-endian long.
static int
writeOggPageHeader(byte[] buf, int offset, int headerType, long granulepos, int streamSerialNumber, int pageCount, int packetCount, byte[] packetSizes)
Writes an Ogg Page Header to the given byte array.
abstract void
writePacket(byte[] data, int offset, int len)
Writes a packet of audio.
static void
writeShort(DataOutput out, short v)
Writes a Little-endian short.
static void
writeShort(OutputStream os, short v)
Writes a Little-endian short.
static void
writeShort(byte[] data, int offset, int v)
Writes a Little-endian short.
static int
writeSpeexComment(byte[] buf, int offset, String comment)
Writes a Speex Comment to the given byte array.
static int
writeSpeexHeader(byte[] buf, int offset, int sampleRate, int mode, int channels, boolean vbr, int nframes)
Writes a Speex Header to the given byte array.
static void
writeString(byte[] data, int offset, String v)
Writes a String.

Method Details

buildOggPageHeader

public static byte[] buildOggPageHeader(int headerType,
                                        long granulepos,
                                        int streamSerialNumber,
                                        int pageCount,
                                        int packetCount,
                                        byte[] packetSizes)
Builds and returns an Ogg Page Header.
Parameters:
headerType - the header type flag (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
granulepos - the absolute granule position.
streamSerialNumber -
pageCount -
packetCount -
packetSizes -
Returns:
an Ogg Page Header.

buildSpeexComment

public static byte[] buildSpeexComment(String comment)
Builds and returns a Speex Comment.
Parameters:
comment - the comment.
Returns:
a Speex Comment.

buildSpeexHeader

public static byte[] buildSpeexHeader(int sampleRate,
                                      int mode,
                                      int channels,
                                      boolean vbr,
                                      int nframes)
Builds a Speex Header.
Parameters:
sampleRate -
mode -
channels -
vbr -
nframes -
Returns:
a Speex Header.

close

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

open

public abstract void open(File file)
            throws IOException
Open the output file.
Parameters:
file - - file to open.

open

public abstract void open(String filename)
            throws IOException
Open the output file.
Parameters:
filename - - file to open.

writeHeader

public abstract void writeHeader(String comment)
            throws IOException
Writes the header pages that start the Ogg Speex file. Prepares file for data to be written.
Parameters:
comment - description to be included in the header.

writeInt

public static void writeInt(DataOutput out,
                            int v)
            throws IOException
Writes a Little-endian int.
Parameters:
out - the data output to write to.
v - value to write.

writeInt

public static void writeInt(OutputStream os,
                            int v)
            throws IOException
Writes a Little-endian int.
Parameters:
os - - the output stream to write to.
v - - the value to write.

writeInt

public static void writeInt(byte[] data,
                            int offset,
                            int v)
Writes a Little-endian int.
Parameters:
data - the array into which the data should be written.
offset - the offset from which to start writing in the array.
v - the value to write.

writeLong

public static void writeLong(OutputStream os,
                             long v)
            throws IOException
Writes a Little-endian long.
Parameters:
os - - the output stream to write to.
v - - the value to write.

writeLong

public static void writeLong(byte[] data,
                             int offset,
                             long v)
Writes a Little-endian long.
Parameters:
data - the array into which the data should be written.
offset - the offset from which to start writing in the array.
v - the value to write.

writeOggPageHeader

public static int writeOggPageHeader(byte[] buf,
                                     int offset,
                                     int headerType,
                                     long granulepos,
                                     int streamSerialNumber,
                                     int pageCount,
                                     int packetCount,
                                     byte[] packetSizes)
Writes an Ogg Page Header to the given byte array.
Parameters:
buf - the buffer to write to.
offset - the from which to start writing.
headerType - the header type flag (0=normal, 2=bos: beginning of stream, 4=eos: end of stream).
granulepos - the absolute granule position.
streamSerialNumber -
pageCount -
packetCount -
packetSizes -
Returns:
the amount of data written to the buffer.

writePacket

public abstract void writePacket(byte[] data,
                                 int offset,
                                 int len)
            throws IOException
Writes a packet of audio.
Parameters:
data - audio data
offset - the offset from which to start reading the data.
len - the length of data to read.

writeShort

public static void writeShort(DataOutput out,
                              short v)
            throws IOException
Writes a Little-endian short.
Parameters:
out - the data output to write to.
v - value to write.

writeShort

public static void writeShort(OutputStream os,
                              short v)
            throws IOException
Writes a Little-endian short.
Parameters:
os - - the output stream to write to.
v - - the value to write.

writeShort

public static void writeShort(byte[] data,
                              int offset,
                              int v)
Writes a Little-endian short.
Parameters:
data - the array into which the data should be written.
offset - the offset from which to start writing in the array.
v - the value to write.

writeSpeexComment

public static int writeSpeexComment(byte[] buf,
                                    int offset,
                                    String comment)
Writes a Speex Comment to the given byte array.
Parameters:
buf - the buffer to write to.
offset - the from which to start writing.
comment - the comment.
Returns:
the amount of data written to the buffer.

writeSpeexHeader

public static int writeSpeexHeader(byte[] buf,
                                   int offset,
                                   int sampleRate,
                                   int mode,
                                   int channels,
                                   boolean vbr,
                                   int nframes)
Writes a Speex Header to the given byte array.
Parameters:
buf - the buffer to write to.
offset - the from which to start writing.
sampleRate -
mode -
channels -
vbr -
nframes -
Returns:
the amount of data written to the buffer.

writeString

public static void writeString(byte[] data,
                               int offset,
                               String v)
Writes a String.
Parameters:
data - the array into which the data should be written.
offset - the offset from which to start writing in the array.
v - the value to write.

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