Package javaforce.codec.speex
Class AudioFileWriter
java.lang.Object
javaforce.codec.speex.AudioFileWriter
- Direct Known Subclasses:
OggSpeexWriter,PcmWaveWriter,RawWriter
Abstract Class that defines an Audio File Writer.
- Version:
- $Revision$
- Author:
- Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 voidclose()Closes the output file.abstract voidOpen the output file.abstract voidOpen the output file.abstract voidwriteHeader(String comment) Writes the header pages that start the Ogg Speex file.static voidwriteInt(byte[] data, int offset, int v) Writes a Little-endian int.static voidwriteInt(DataOutput out, int v) Writes a Little-endian int.static voidwriteInt(OutputStream os, int v) Writes a Little-endian int.static voidwriteLong(byte[] data, int offset, long v) Writes a Little-endian long.static voidwriteLong(OutputStream os, long v) Writes a Little-endian long.static intwriteOggPageHeader(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 voidwritePacket(byte[] data, int offset, int len) Writes a packet of audio.static voidwriteShort(byte[] data, int offset, int v) Writes a Little-endian short.static voidwriteShort(DataOutput out, short v) Writes a Little-endian short.static voidwriteShort(OutputStream os, short v) Writes a Little-endian short.static intwriteSpeexComment(byte[] buf, int offset, String comment) Writes a Speex Comment to the given byte array.static intwriteSpeexHeader(byte[] buf, int offset, int sampleRate, int mode, int channels, boolean vbr, int nframes) Writes a Speex Header to the given byte array.static voidwriteString(byte[] data, int offset, String v) Writes a String.
-
Constructor Details
-
AudioFileWriter
public AudioFileWriter()
-
-
Method Details
-
close
Closes the output file.- Throws:
IOException- if there was an exception closing the Audio Writer.
-
open
Open the output file.- Parameters:
file- - file to open.- Throws:
IOException- if there was an exception opening the Audio Writer.
-
open
Open the output file.- Parameters:
filename- - file to open.- Throws:
IOException- if there was an exception opening the Audio Writer.
-
writeHeader
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.- Throws:
IOException
-
writePacket
Writes a packet of audio.- Parameters:
data- audio dataoffset- the offset from which to start reading the data.len- the length of data to read.- Throws:
IOException
-
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. Ogg Page Header structure:0 - 3: capture_pattern 4: stream_structure_version 5: header_type_flag 6 - 13: absolute granule position 14 - 17: stream serial number 18 - 21: page sequence no 22 - 25: page checksum 26: page_segments 27 - x: segment_table- 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.
-
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.
-
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. Speex Header structure:0 - 7: speex_string 8 - 27: speex_version 28 - 31: speex_version_id 32 - 35: header_size 36 - 39: rate 40 - 43: mode (0=NB, 1=WB, 2=UWB) 44 - 47: mode_bitstream_version 48 - 51: nb_channels 52 - 55: bitrate 56 - 59: frame_size (NB=160, WB=320, UWB=640) 60 - 63: vbr 64 - 67: frames_per_packet 68 - 71: extra_headers 72 - 75: reserved1 76 - 79: reserved2
- 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.
-
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.
-
writeSpeexComment
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.
-
buildSpeexComment
Builds and returns a Speex Comment.- Parameters:
comment- the comment.- Returns:
- a Speex Comment.
-
writeShort
Writes a Little-endian short.- Parameters:
out- the data output to write to.v- value to write.- Throws:
IOException
-
writeInt
Writes a Little-endian int.- Parameters:
out- the data output to write to.v- value to write.- Throws:
IOException
-
writeShort
Writes a Little-endian short.- Parameters:
os- - the output stream to write to.v- - the value to write.- Throws:
IOException
-
writeInt
Writes a Little-endian int.- Parameters:
os- - the output stream to write to.v- - the value to write.- Throws:
IOException
-
writeLong
Writes a Little-endian long.- Parameters:
os- - the output stream to write to.v- - the value to write.- Throws:
IOException
-
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.
-
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(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.
-
writeString
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.
-