#include <wvspeex.h>
Inherits WvAudioDecoder.
Collaboration diagram for WvSpeexDecoder:
Inbut buffer must contain a sequence of Speex packets.
Output buffer will contain a sequence of signed 'float' type values in machine order representing unnormalized PCM audio data.
Missing audio due to lost or damaged packets may be filled in by making predictions (guesses) based on residual energy information from previous ones. The number of lost or damaged packets must be known in order to calculate how much new audio must be synthesized. This technique works well to conceal occasional dropouts but not long strings of lost packets. Still, Speech is still surprizingly recognizable with average packet losses of up to 25% to 50%!
Warning: Never invoke encode() unless the input buffer contains exactly zero or one Speex packets. Speex packets do not contain any delimiters therefore it is not possible to locate the boundary between adjacent packets unless they are encapsulated as individual datagrams in some fashion. Multiple adjacent packets cannot be decoded at once.
For archival purposes or for streaming, consider using WvOggSpeexDecoder.
For encoding music or other non-speech audio, consider using WvOggVorbisDecoder.
Definition at line 260 of file wvspeex.h.
Public Types | |
typedef unsigned | IType |
typedef float | OType |
typedef WvBufBase< IType > | IBuffer |
typedef WvBufBase< OType > | OBuffer |
typedef WvBufViewBase< IType > | IBufferView |
typedef WvBufViewBase< OType > | OBufferView |
Public Member Functions | |
WvSpeexDecoder (int samplingrate, unsigned int channels=1, WvSpeex::CodecMode mode=WvSpeex::DEFAULT_MODE) | |
Creates a Speex Decoder. | |
virtual | ~WvSpeexDecoder () |
virtual bool | missing (OBuffer &outbuf) |
Synthesizes one audio frame to compensate for a missing packet. | |
virtual unsigned int | channels () const |
Returns the number of channels in the stream. | |
int | samplingrate () const |
Returns the sampling rate of the stream. | |
virtual size_t | samplesperframe () const |
Returns the number of samples per frame. | |
WvSpeex::CodecMode | mode () const |
Returns the current encoding mode. | |
bool | postfilter () const |
Determines if the perceptual enhancement post-filter is enabled. | |
void | setpostfilter (bool enable) |
Enables or disables the perceptual enhancement post-filter. | |
bool | encode (IBuffer &inbuf, OBuffer &outbuf, bool flush=false, bool finish=false) |
Typed variant of encode(). | |
bool | encode (WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false) |
Reads data from the input buffer, encodes it, and writes the result to the output buffer. | |
bool | flush (IBuffer &inbuf, OBuffer &outbuf, bool finish=false) |
Typed variant of flush(). | |
bool | flush (WvBuf &inbuf, WvBuf &outbuf, bool finish=false) |
Flushes the encoder and optionally finishes it. | |
bool | finish (OBuffer &outbuf) |
Typed variant of finish(). | |
bool | finish (WvBuf &outbuf) |
Tells the encoder that NO MORE DATA will ever be encoded. | |
bool | isok () const |
Returns true if the encoder has not encountered an error. | |
bool | isfinished () const |
Returns true if the encoder can no longer encode data. | |
WvString | geterror () const |
Returns an error message if any is available. | |
bool | reset () |
Asks an encoder to reset itself to its initial state at creation time, if supported. | |
bool | flushstrbuf (WvStringParm instr, WvBuf &outbuf, bool finish=false) |
Flushes data through the encoder from a string to a buffer. | |
bool | flushstrstr (WvStringParm instr, WvString &outstr, bool finish=false) |
Flushes data through the encoder from a string to a string. | |
bool | encodebufstr (WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false) |
Encodes data from a buffer to a string. | |
bool | flushbufstr (WvBuf &inbuf, WvString &outstr, bool finish=false) |
Flushes data through the encoder from a buffer to a string. | |
WvString | strflushstr (WvStringParm instr, bool finish=false) |
Flushes data through the encoder from a string to a string. | |
WvString | strflushbuf (WvBuf &inbuf, bool finish=false) |
Flushes data through the encoder from a buffer to a string. | |
bool | flushmembuf (const void *inmem, size_t inlen, WvBuf &outbuf, bool finish=false) |
Flushes data through the encoder from memory to a buffer. | |
bool | flushmemmem (const void *inmem, size_t inlen, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from memory to memory. | |
bool | encodebufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false) |
Encodes data from a buffer to memory. | |
bool | flushbufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from a buffer to memory. | |
bool | flushstrmem (WvStringParm instr, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from a string to memory. | |
WvString | strflushmem (const void *inmem, size_t inlen, bool finish=false) |
Flushes data through the encoder from memory to a string. | |
Protected Member Functions | |
virtual bool | _typedencode (IBuffer &inbuf, OBuffer &outbuf, bool flush) |
Typed variant of _encode(). | |
virtual bool | _typedfinish (OBuffer &outbuf) |
Typed variant of _finish(). | |
virtual bool | _encode (WvBuf &inbuf, WvBuf &outbuf, bool flush) |
Wrapper implementation of _encode(). | |
virtual bool | _finish (WvBuf &outbuf) |
Wrapper implementation of _finish(). | |
void | setnotok () |
Sets 'okay' to false explicitly. | |
void | seterror (WvStringParm message) |
Sets an error condition, then setnotok(). | |
void | seterror (WVSTRING_FORMAT_DECL) |
Sets an error condition, then setnotok(). | |
void | setfinished () |
Sets 'finished' to true explicitly. | |
virtual bool | _isok () const |
Template method implementation of isok(). | |
virtual bool | _isfinished () const |
Template method implementation of isfinished(). | |
virtual WvString | _geterror () const |
Template method implementation of geterror(). | |
virtual bool | _reset () |
Template method implementation of reset(). | |
Protected Attributes | |
bool | okay |
bool | finished |
WvString | errstr |
|
Definition at line 38 of file wvtypedencoder.h. |
|
Definition at line 40 of file wvtypedencoder.h. |
|
Definition at line 36 of file wvtypedencoder.h. |
|
Definition at line 39 of file wvtypedencoder.h. |
|
Definition at line 41 of file wvtypedencoder.h. |
|
Definition at line 37 of file wvtypedencoder.h. |
|
Creates a Speex Decoder. For now, if the input bitstream is stereo, outputs the left channel only. This behaviour may change later on. "samplingrate" is the number of samples per second, preferably one of 8000, 16000, or 32000 "channels" is number of channels (must be 1 for now), defaults to 1 "mode" is the Speex codec mode to use or WvSpeex::DEFAULT_MODE to select one automatically based on the sampling rate, this is the default Definition at line 199 of file wvspeex.cc. References get_speex_mode(), and WvSpeexDecoder(). Referenced by WvSpeexDecoder(). |
|
Definition at line 226 of file wvspeex.cc. |
|
Wrapper implementation of _encode().
Implements WvEncoder. Definition at line 107 of file wvtypedencoder.h. |
|
Wrapper implementation of _finish().
Reimplemented from WvEncoder. Definition at line 116 of file wvtypedencoder.h. |
|
Template method implementation of geterror(). Not called if any of the following cases are true:
Most implementations do not need to override this. Returns: the error message, or the null string if _isok() == true
Reimplemented in WvEncoderChain, WvOggSpeexEncoder, and WvOggSpeexDecoder. Definition at line 433 of file wvencoder.h. Referenced by WvEncoder::geterror(). |
|
Template method implementation of isfinished(). Not called if any of the following cases are true:
Most implementations do not need to override this. Returns: true if the encoder is finished
Reimplemented in WvEncoderChain. Definition at line 416 of file wvencoder.h. Referenced by WvEncoder::isfinished(). |
|
Template method implementation of isok(). Not called if any of the following cases are true:
Most implementations do not need to override this. Returns: true if the encoder is ok
Reimplemented in WvEncoderChain, WvOggSpeexEncoder, and WvOggSpeexDecoder. Definition at line 400 of file wvencoder.h. Referenced by WvEncoder::isok(). |
|
|
Typed variant of _encode().
Implements WvTypedEncoder< unsigned char, float >. Definition at line 255 of file wvspeex.cc. References _typedencode(). Referenced by _typedencode(). |
|
Typed variant of _finish().
Reimplemented from WvTypedEncoder< unsigned char, float >. Definition at line 286 of file wvspeex.cc. References _typedfinish(). Referenced by _typedfinish(). |
|
Returns the number of channels in the stream. Returns: the number of channels, non-negative Implements WvAudioDecoder. Definition at line 302 of file wvspeex.h. Referenced by WvOggSpeexDecoder::channels(). |
|
Reimplemented from WvEncoder. Definition at line 76 of file wvtypedencoder.h. |
|
Typed variant of encode().
Definition at line 47 of file wvtypedencoder.h. |
|
Encodes data from a buffer to memory. The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned. "inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success Definition at line 138 of file wvencoder.cc. References WvEncoder::encode(), WvEncoder::encodebufmem(), and WvBufBaseCommonImpl< unsigned >::used(). Referenced by WvEncoder::encodebufmem(), and WvEncoder::flushmemmem(). |
|
Encodes data from a buffer to a string. The output data is appended to the target string. "inbuf" is the input buffer "outstr" is the output string "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success Definition at line 95 of file wvencoder.cc. References WvString::append(), WvEncoder::encode(), and WvEncoder::encodebufstr(). Referenced by WvEncoder::encodebufstr(). |
|
Reimplemented from WvEncoder. Definition at line 86 of file wvtypedencoder.h. |
|
Typed variant of finish().
Definition at line 70 of file wvtypedencoder.h. |
|
Reimplemented from WvEncoder. Definition at line 81 of file wvtypedencoder.h. |
|
Typed variant of flush().
Definition at line 59 of file wvtypedencoder.h. |
|
Flushes data through the encoder from a buffer to memory. The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned. "inbuf" is the input buffer "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success Definition at line 337 of file wvencoder.h. References WvEncoder::flushbufmem(). Referenced by WvEncoder::flushbufmem(), and WvEncoder::flushstrmem(). |
|
Flushes data through the encoder from a buffer to a string. The output data is appended to the target string. "inbuf" is the input buffer "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success Definition at line 249 of file wvencoder.h. References WvEncoder::flushbufstr(). Referenced by WvEncoder::flushbufstr(), and WvEncoder::strflushbuf(). |
|
Flushes data through the encoder from memory to a buffer. "inmem" is the input data pointer "inlen" is the input data length "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success Definition at line 121 of file wvencoder.cc. References WvEncoder::encode(), and WvEncoder::flushmembuf(). Referenced by WvEncoder::flushmembuf(), and WvDsp::uwrite(). |
|
Flushes data through the encoder from memory to memory. The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned. "inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success Definition at line 130 of file wvencoder.cc. References WvEncoder::encodebufmem(), and WvEncoder::flushmemmem(). Referenced by WvEncoder::flushmemmem(). |
|
Flushes data through the encoder from a string to a buffer. "instr" is the input string "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success Definition at line 75 of file wvencoder.cc. References WvEncoder::encode(), WvEncoder::flushstrbuf(), and WvStringParm. Referenced by WvEncoder::flushstrbuf(). |
|
Flushes data through the encoder from a string to memory. The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned. "instr" is the input string "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success Definition at line 148 of file wvencoder.cc. References WvEncoder::flushbufmem(), and WvEncoder::flushstrmem(). Referenced by WvEncoder::flushstrmem(). |
|
Flushes data through the encoder from a string to a string. The output data is appended to the target string. "instr" is the input string "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success Definition at line 84 of file wvencoder.cc. References WvString::append(), WvEncoder::encode(), WvEncoder::flushstrstr(), and WvDynBuf. Referenced by encode64(), WvEncoder::flushstrstr(), and WvEncoder::strflushstr(). |
|
Returns an error message if any is available. Returns: the error message, or the null string is isok() == true Definition at line 21 of file wvencoder.cc. References WvEncoder::_geterror(), WvEncoder::errstr, and WvEncoder::isok(). Referenced by WvOggSpeexDecoder::_geterror(), and WvOggSpeexEncoder::_geterror(). |
|
Returns true if the encoder can no longer encode data. This will be set when the encoder detects and end-of-data mark in its input, or when finish() is called. Returns: true if the encoder is finished Definition at line 101 of file wvencoder.h. References WvEncoder::_isfinished(), and WvEncoder::finished. Referenced by missing(). |
|
Returns true if the encoder has not encountered an error. This should only be used to record permanent failures. Transient errors (eg. bad block, but recoverable) should be detected in a different fashion. Returns: true if the encoder is ok Definition at line 90 of file wvencoder.h. References WvEncoder::_isok(), and WvEncoder::okay. Referenced by WvOggSpeexDecoder::_isok(), WvOggSpeexEncoder::_isok(), WvEncoder::geterror(), and missing(). |
|
Synthesizes one audio frame to compensate for a missing packet. "outbuf" is the output buffer Returns: true on success
Implements WvAudioDecoder. Definition at line 292 of file wvspeex.cc. References WvEncoder::isfinished(), WvEncoder::isok(), and missing(). Referenced by missing(). |
|
Returns the current encoding mode. Returns: the encoding mode Definition at line 234 of file wvspeex.cc. References WvSpeex::CodecMode. Referenced by WvOggSpeexDecoder::mode(). |
|
Determines if the perceptual enhancement post-filter is enabled. Returns: true if it is enabled Definition at line 240 of file wvspeex.cc. Referenced by WvOggSpeexDecoder::postfilter(). |
|
Asks an encoder to reset itself to its initial state at creation time, if supported. This function may be called at any time, even if isok() == false, or isfinished() == true. If the behaviour is not supported or an error occurs, then false is returned and afterwards isok() == false. Returns: true on success
Definition at line 58 of file wvencoder.cc. References WvEncoder::_reset(), WvEncoder::errstr, WvEncoder::finished, WvEncoder::okay, and WvEncoder::seterror(). |
|
Returns the number of samples per frame. Returns: the frame size Implements WvAudioDecoder. Definition at line 316 of file wvspeex.h. Referenced by WvOggSpeexDecoder::samplesperframe(). |
|
Returns the sampling rate of the stream. Returns: the sampling rate Definition at line 309 of file wvspeex.h. Referenced by WvOggSpeexDecoder::samplingrate(). |
|
Sets an error condition, then setnotok().
Definition at line 379 of file wvencoder.h. References WVSTRING_FORMAT_CALL. |
|
Sets an error condition, then setnotok().
Definition at line 375 of file wvencoder.h. References WvEncoder::errstr, WvEncoder::seterror(), and WvEncoder::setnotok(). Referenced by WvEncoder::reset(), and WvEncoder::seterror(). |
|
Sets 'finished' to true explicitly.
Definition at line 383 of file wvencoder.h. References WvEncoder::finished. Referenced by WvBase64Decoder::_encode(), WvOggVorbisDecoder::_typedencode(), WvOggSpeexDecoder::_typedencode(), and WvEncoder::finish(). |
|
Sets 'okay' to false explicitly.
Definition at line 371 of file wvencoder.h. References WvEncoder::okay. Referenced by WvEncoder::seterror(). |
|
Enables or disables the perceptual enhancement post-filter. "enable" is true or false Definition at line 248 of file wvspeex.cc. References setpostfilter(). Referenced by setpostfilter(), and WvOggSpeexDecoder::setpostfilter(). |
|
Flushes data through the encoder from a buffer to a string. "inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors Definition at line 113 of file wvencoder.cc. References WvEncoder::flushbufstr(), and WvEncoder::strflushbuf(). Referenced by WvEncoder::strflushbuf(), and WvEncoder::strflushmem(). |
|
Flushes data through the encoder from memory to a string. "inmem" is the input data pointer "inlen" is the input data length "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors Definition at line 156 of file wvencoder.cc. References WvEncoder::strflushbuf(), and WvEncoder::strflushmem(). Referenced by WvEncoder::strflushmem(). |
|
Flushes data through the encoder from a string to a string. "inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors Definition at line 105 of file wvencoder.cc. References WvEncoder::flushstrstr(), and WvEncoder::strflushstr(). Referenced by WvEncoder::strflushstr(). |
|
the error message Definition at line 72 of file wvencoder.h. Referenced by WvEncoder::geterror(), WvEncoder::reset(), and WvEncoder::seterror(). |
|
true iff setfinished()/finish() was called Definition at line 71 of file wvencoder.h. Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isfinished(), WvEncoder::reset(), and WvEncoder::setfinished(). |
|
false iff setnotok() was called Definition at line 70 of file wvencoder.h. Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isok(), WvEncoder::reset(), and WvEncoder::setnotok(). |