Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvoggspeex.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Provides a WvEncoder abstraction for Ogg Speex audio streams
00006  * suitable for encoding voice at low bitrates.
00007  *
00008  * Only monaural audio is supported for now.
00009  */
00010 #ifndef __WVOGGSPEEX_H
00011 #define __WVOGGSPEEX_H
00012 
00013 #include "wvstringlist.h"
00014 #include "wvtypedencoder.h"
00015 #include "wvspeex.h"
00016 #include <ogg/ogg.h>
00017 
00029 class WvOggSpeexEncoder :
00030     public WvTypedEncoder<float, unsigned char>
00031 {
00032     WvSpeexEncoder *speexenc;
00033     ogg_int64_t packetno;
00034     WvString _vendor;
00035     WvStringList _comments;
00036     ogg_stream_state *oggstream;
00037     bool wrote_headers;
00038     
00039     WvInPlaceBuf framebuf;
00040 
00041 public:
00042     static const long RANDOM_SERIALNO = 0;
00043 
00066     WvOggSpeexEncoder(const WvSpeex::BitrateSpec &bitratespec,
00067         int samplingrate, int channels = 1,
00068         WvSpeex::CodecMode mode = WvSpeex::DEFAULT_MODE,
00069         int complexity = WvSpeex::DEFAULT_COMPLEXITY,
00070         long serialno = RANDOM_SERIALNO);
00071 
00072     virtual ~WvOggSpeexEncoder();
00073 
00081     void add_comment(WvStringParm comment);
00082     
00089     void add_comment(WVSTRING_FORMAT_DECL)
00090         { add_comment(WvString(WVSTRING_FORMAT_CALL)); }
00091     
00104     void add_tag(WvStringParm tag, WvStringParm value);
00105 
00110     int samplingrate() const
00111         { return speexenc->samplingrate(); }
00112 
00117     int channels() const
00118         { return speexenc->channels(); }
00119 
00124     int samplesperframe() const
00125         { return speexenc->samplesperframe(); }
00126 
00131     WvSpeex::CodecMode mode() const
00132         { return speexenc->mode(); }
00133 
00138     bool vbr() const
00139         { return speexenc->vbr(); }
00140 
00145     int nominalbitrate() const
00146         { return speexenc->nominalbitrate(); }
00147 
00148 protected:
00149     virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00150         bool flush);
00151     virtual bool _typedfinish(OBuffer &outbuf);
00152     virtual bool _isok() const;
00153     virtual WvString _geterror() const;
00154 
00155 private:
00156     bool write_headers(OBuffer &outbuf);
00157     bool write_eof(OBuffer &outbuf);
00158     bool write_stream(OBuffer &outbuf, bool flush = false);
00159 };
00160 
00161 
00178 class WvOggSpeexDecoder :
00179     public WvTypedEncoder<unsigned char, float>
00180 {
00181     WvSpeexDecoder *speexdec;
00182     bool forcepostfilter;
00183     WvString _vendor;
00184     WvStringList _comments;
00185     bool _vbr; // extracted from header
00186     int _nominalbitrate; // extracted from header
00187 
00188 public:
00196     WvOggSpeexDecoder();
00197     virtual ~WvOggSpeexDecoder();
00198 
00207     bool isheaderok() const;
00208 
00214     WvString vendor() const
00215         { return _vendor; }
00216 
00224     WvStringList &comments()
00225         { return _comments; }
00226 
00232     int channels() const;
00233 
00239     int samplingrate() const;
00240         
00246     int samplesperframe() const;
00247 
00253     WvSpeex::CodecMode mode() const;
00254     
00260     bool vbr() const;
00261 
00267     int nominalbitrate() const;
00268     
00273     bool postfilter() const;
00274 
00279     void setpostfilter(bool enable);
00280 
00281 protected:
00282     virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf,
00283         bool flush);
00284     virtual bool _typedfinish(OBuffer &outbuf);
00285     virtual bool _isok() const;
00286     virtual WvString _geterror() const;
00287 
00288 private:
00289     ogg_sync_state *oggsync;
00290     ogg_stream_state *oggstream;
00291     ogg_page *oggpage;
00292     bool need_serialno;
00293     int need_headers;
00294 
00295     bool process_page(ogg_page *oggpage, OBuffer &outbuf);
00296     bool process_packet(ogg_packet *oggpacket, OBuffer &outbuf);
00297     bool prepare_stream(long serialno);
00298 
00299     bool process_speex_header(ogg_packet *header);
00300     bool process_comment_header(ogg_packet *header);
00301 };
00302 
00303 #endif // __WVOGGSPEEX_H

Generated on Sun Apr 3 14:46:40 2005 for WvStreams by  doxygen 1.4.2