Package javaforce.codec.speex.spi
Class Speex2PcmAudioInputStream
java.lang.Object
java.io.InputStream
javax.sound.sampled.AudioInputStream
javaforce.codec.speex.spi.FilteredAudioInputStream
javaforce.codec.speex.spi.Speex2PcmAudioInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Converts an Ogg Speex bitstream into a PCM 16bits/sample audio stream.
- Version:
- $Revision$
- Author:
- Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
-
Field Summary
Fields inherited from class javaforce.codec.speex.spi.FilteredAudioInputStream
buf, count, DEFAULT_BUFFER_SIZE, in, marklimit, markpos, pos, prebuf, precount, preposFields inherited from class javax.sound.sampled.AudioInputStream
format, frameLength, framePos -
Constructor Summary
ConstructorsConstructorDescriptionSpeex2PcmAudioInputStream(InputStream in, AudioFormat format, long length) ConstructorSpeex2PcmAudioInputStream(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 voiddecode(byte[] data, int offset, int len) This is where the actual decoding takes place.protected voidfill()Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks.protected voidinitialise(boolean blocking) Initialises the Ogg Speex to PCM InputStream.longskip(long n) See the general contract of theskipmethod ofInputStream.Methods inherited from class javaforce.codec.speex.spi.FilteredAudioInputStream
checkIfStillOpen, close, makeSpace, mark, markSupported, read, read, resetMethods inherited from class javax.sound.sampled.AudioInputStream
getFormat, getFrameLength, readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
Speex2PcmAudioInputStream
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.
-
Speex2PcmAudioInputStream
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.
-
-
Method Details
-
initialise
Initialises the Ogg Speex to PCM InputStream. Read the Ogg Speex header and extract the speex decoder parameters to initialise the decoder. Then read the Comment header. Ogg Header description:0 - 3: capture_pattern 4: stream_structure_version 5: header_type_flag (2=bos: beginning of sream) 6 - 13: absolute granule position 14 - 17: stream serial number 18 - 21: page sequence no 22 - 25: page checksum 26: page_segments 27 -...: segment_tableSpeex Header description0 - 7: speex_string 8 - 27: speex_version 28 - 31: speex_version_id 32 - 35: header_size 36 - 39: rate 40 - 43: mode (0=narrowband, 1=wb, 2=uwb) 44 - 47: mode_bitstream_version 48 - 51: nb_channels 52 - 55: bitrate 56 - 59: frame_size 60 - 63: vbr 64 - 67: frames_per_packet 68 - 71: extra_headers 72 - 75: reserved1 76 - 79: reserved2
- Parameters:
blocking- whether the method should block until initialisation is successfully completed or not.- Throws:
IOException
-
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
-
decode
This is where the actual decoding takes place.- Parameters:
data- the array of data to decode.offset- the offset from which to start reading the data.len- the length of data to read from the array.- Throws:
StreamCorruptedException- If the input stream not valid Ogg Speex data.
-
skip
See the general contract of theskipmethod ofInputStream.- Overrides:
skipin classFilteredAudioInputStream- Parameters:
n- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if an I/O error occurs.
-
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). The result of calling theavailablemethod of the underlying inputstream is not used, as this data will have to be filtered, and thus may not be the same size after processing (although subclasses that do the filtering should override this method and use the amount of data available in 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:
-