Package javaforce.codec.speex.spi
Class Pcm2SpeexAudioInputStream
java.lang.Object
java.io.InputStream
javax.sound.sampled.AudioInputStream
javaforce.codec.speex.spi.FilteredAudioInputStream
javaforce.codec.speex.spi.Pcm2SpeexAudioInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Converts a PCM 16bits/sample mono audio stream to Ogg Speex
- Version:
- $Revision$
- Author:
- Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default size of the buffer (UWB stereo requires at least 2560b).static final intThe default number of channels if none is given in the constructor.static final intThe default number of Speex frames that will be put in each Ogg packet.static final intThe default number of Ogg packets that will be put in each Ogg page.static final intThe default quality setting for the Speex encoder.static final intThe default sample rate if none is given in the constructor.static final intIndicates the value is unknown or undetermined.Fields inherited from class javaforce.codec.speex.spi.FilteredAudioInputStream
buf, count, in, marklimit, markpos, pos, prebuf, precount, preposFields inherited from class javax.sound.sampled.AudioInputStream
format, frameLength, framePos -
Constructor Summary
ConstructorsConstructorDescriptionPcm2SpeexAudioInputStream(int mode, int quality, InputStream in, AudioFormat format, long length) ConstructorPcm2SpeexAudioInputStream(int mode, int quality, InputStream in, AudioFormat format, long length, int size) ConstructorPcm2SpeexAudioInputStream(InputStream in, AudioFormat format, long length) ConstructorPcm2SpeexAudioInputStream(InputStream in, AudioFormat format, long length, int size) Constructor -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes that can be read from this inputstream without blocking.protected voidfill()Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks.Returns the Encoder.voidsetComment(String comment, boolean appendVersion) Sets the comment for the Ogg Comment Header.voidsetFramesPerPacket(int framesPerPacket) Sets the number of Audio Frames that are to be put in every Speex Packet.voidsetPacketsPerOggPage(int packetsPerOggPage) Sets the number of Speex Packets that are to be put in every Ogg Page.voidsetQuality(int quality) Sets the Speex encoder Quality.voidsetSerialNumber(int serialNumber) Sets the Stream Serial Number.voidsetVbr(boolean vbr) Sets whether of not the encoder is to use VBR.Methods inherited from class javaforce.codec.speex.spi.FilteredAudioInputStream
checkIfStillOpen, close, makeSpace, mark, markSupported, read, read, reset, skipMethods inherited from class javax.sound.sampled.AudioInputStream
getFormat, getFrameLength, readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default size of the buffer (UWB stereo requires at least 2560b).- See Also:
-
DEFAULT_SAMPLERATE
public static final int DEFAULT_SAMPLERATEThe default sample rate if none is given in the constructor.- See Also:
-
DEFAULT_CHANNELS
public static final int DEFAULT_CHANNELSThe default number of channels if none is given in the constructor.- See Also:
-
DEFAULT_QUALITY
public static final int DEFAULT_QUALITYThe default quality setting for the Speex encoder.- See Also:
-
DEFAULT_FRAMES_PER_PACKET
public static final int DEFAULT_FRAMES_PER_PACKETThe default number of Speex frames that will be put in each Ogg packet.- See Also:
-
DEFAULT_PACKETS_PER_OGG_PAGE
public static final int DEFAULT_PACKETS_PER_OGG_PAGEThe default number of Ogg packets that will be put in each Ogg page.- See Also:
-
UNKNOWN
public static final int UNKNOWNIndicates the value is unknown or undetermined.- See Also:
-
-
Constructor Details
-
Pcm2SpeexAudioInputStream
Constructor- Parameters:
in- the underlying input stream.format- the target format of this stream's audio data.length- the length in sample frames of the data in this stream.
-
Pcm2SpeexAudioInputStream
public Pcm2SpeexAudioInputStream(int mode, int quality, InputStream in, AudioFormat format, long length) Constructor- Parameters:
mode- the mode of the encoder (0=NB, 1=WB, 2=UWB).quality- the quality setting of the encoder (between 0 and 10).in- the underlying input stream.format- the target format of this stream's audio data.length- the length in sample frames of the data in this stream.
-
Pcm2SpeexAudioInputStream
Constructor- Parameters:
in- the underlying input stream.format- the target format of this stream's audio data.length- the length in sample frames of the data in this stream.size- the buffer size.- Throws:
IllegalArgumentException- if size <= 0.
-
Pcm2SpeexAudioInputStream
public Pcm2SpeexAudioInputStream(int mode, int quality, InputStream in, AudioFormat format, long length, int size) Constructor- Parameters:
mode- the mode of the encoder (0=NB, 1=WB, 2=UWB).quality- the quality setting of the encoder (between 0 and 10).in- the underlying input stream.format- the target format of this stream's audio data.length- the length in sample frames of the data in this stream.size- the buffer size.- Throws:
IllegalArgumentException- if size <= 0.
-
-
Method Details
-
setSerialNumber
public void setSerialNumber(int serialNumber) Sets the Stream Serial Number. Must not be changed mid stream.- Parameters:
serialNumber-
-
setFramesPerPacket
public void setFramesPerPacket(int framesPerPacket) Sets the number of Audio Frames that are to be put in every Speex Packet. An Audio Frame contains 160 samples for narrowband, 320 samples for wideband and 640 samples for ultra-wideband.- Parameters:
framesPerPacket-- See Also:
-
setPacketsPerOggPage
public void setPacketsPerOggPage(int packetsPerOggPage) Sets the number of Speex Packets that are to be put in every Ogg Page. This value must be less than 256 as the value is encoded in 1 byte in the Ogg Header (just before the array of packet sizes)- Parameters:
packetsPerOggPage-- See Also:
-
setComment
Sets the comment for the Ogg Comment Header.- Parameters:
comment-appendVersion-
-
setQuality
public void setQuality(int quality) Sets the Speex encoder Quality.- Parameters:
quality-
-
setVbr
public void setVbr(boolean vbr) Sets whether of not the encoder is to use VBR.- Parameters:
vbr-
-
getEncoder
Returns the Encoder.- Returns:
- the Encoder.
-
fill
Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks. Assumes that it is being called by a synchronized method. This method also assumes that all data has already been read in, hence pos > count.- Overrides:
fillin classFilteredAudioInputStream- Throws:
IOException
-
available
Returns the number of bytes that can be read from this inputstream without blocking. Theavailablemethod ofFilteredAudioInputStreamreturns the sum of the the number of bytes remaining to be read in the buffer (count - pos) and the result of calling theavailablemethod of the underlying inputstream.- Overrides:
availablein classFilteredAudioInputStream- Returns:
- the number of bytes that can be read from this inputstream without blocking.
- Throws:
IOException- if an I/O error occurs.- See Also:
-