"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSSoundLib/Src/Ogg/LSSVorbisCodec.h

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
00009  * by the Xiph.Org Foundation http://www.xiph.org/                  *
00010 
00011  ********************************************************************
00012 
00013  function: libvorbis codec headers
00014  last mod: $Id: codec.h 17021 2010-03-24 09:29:41Z xiphmont $
00015 
00016  ********************************************************************/
00017 
00018 
00019 #ifndef __LSS_VORBISCODEC_H__
00020 #define __LSS_VORBISCODEC_H__
00021 
00022 #include "../LSSSoundLib.h"
00023 #include "LSSOgg.h"
00024 
00025 namespace lss {
00026 
00030         enum LSS_VORBIS_ERRORS {
00031                 OV_FALSE                                                                        = -1,
00032                 OV_EOF                                                                          = -2,
00033                 OV_HOLE                                                                         = -3,
00034 
00035                 OV_EREAD                                                                        = -128,
00036                 OV_EFAULT                                                                       = -129,
00037                 OV_EIMPL                                                                        = -130,
00038                 OV_EINVAL                                                                       = -131,
00039                 OV_ENOTVORBIS                                                           = -132,
00040                 OV_EBADHEADER                                                           = -133,
00041                 OV_EVERSION                                                                     = -134,
00042                 OV_ENOTAUDIO                                                            = -135,
00043                 OV_EBADPACKET                                                           = -136,
00044                 OV_EBADLINK                                                                     = -137,
00045                 OV_ENOSEEK                                                                      = -138,
00046 
00047                 LSS_VE_FORCEDWORD                                                       = 0x7FFFFFFF
00048         };
00049 
00056         class CVorbisCodec {
00057         public :
00058                 // == Types.
00065                 typedef struct vorbis_info {
00066                         LSINT32                                                                 version;
00067                         LSINT32                                                                 channels;
00068                         LSINT32                                                                 rate;
00069 
00070                         // The below bitrate declarations are hints.
00071                         // Combinations of the three values carry the following implications:
00072                         // All three set to the same value:
00073                         //      Implies a fixed rate bitstream
00074                         // Only nominal set:
00075                         //      Implies a VBR stream that averages the nominal bitrate. No hard
00076                         //      upper/lower limit
00077                         // Upper and or lower set:
00078                         //      Implies a VBR bitstream that obeys the bitrate limits. Nominal
00079                         //      may also be set to give a nominal rate.
00080                         // None set:
00081                         //      The coder does not care to speculate.
00082 
00083                         LSINT32                                                                 bitrate_upper;
00084                         LSINT32                                                                 bitrate_nominal;
00085                         LSINT32                                                                 bitrate_lower;
00086                         LSINT32                                                                 bitrate_window;
00087 
00088                         LSVOID *                                                                codec_setup;
00089                 } * LPvorbis_info, * const LPCvorbis_info;
00090 
00095                 typedef struct vorbis_dsp_state {
00096                         LSINT32                                                                 analysisp;
00097                         vorbis_info *                                                   vi;
00098 
00099                         LSFLOAT **                                                              pcm;
00100                         LSFLOAT **                                                              pcmret;
00101                         LSINT32                                                                 pcm_storage;
00102                         LSINT32                                                                 pcm_current;
00103                         LSINT32                                                                 pcm_returned;
00104 
00105                         LSINT32                                                                 preextrapolate;
00106                         LSINT32                                                                 eofflag;
00107 
00108                         LSINT32                                                                 lW;
00109                         LSINT32                                                                 W;
00110                         LSINT32                                                                 nW;
00111                         LSINT32                                                                 centerW;
00112 
00113                         LSINT64                                                                 granulepos;
00114                         LSINT64                                                                 sequence;
00115 
00116                         LSINT64                                                                 glue_bits;
00117                         LSINT64                                                                 time_bits;
00118                         LSINT64                                                                 floor_bits;
00119                         LSINT64                                                                 res_bits;
00120 
00121                         LSVOID *                                                                backend_state;
00122                 } * LPvorbis_dsp_state, * const LPCvorbis_dsp_state;
00123 
00127                 typedef struct alloc_chain {
00128                         LSVOID *                                                                ptr;
00129                         alloc_chain *                                                   next;
00130                 } * LPalloc_chain, * const LPCalloc_chain;
00131 
00137                 typedef struct vorbis_block {
00138                         // Necessary stream state for linking to the framing abstraction.
00139                         LSFLOAT **                                                              pcm;       // This is a pointer into local storage.
00140                         COgg::oggpack_buffer                                    opb;
00141 
00142                         LSINT32                                                                 lW;
00143                         LSINT32                                                                 W;
00144                         LSINT32                                                                 nW;
00145                         LSINT32                                                                 pcmend;
00146                         LSINT32                                                                 mode;
00147 
00148                         LSINT32                                                                 eofflag;
00149                         LSINT64                                                                 granulepos;
00150                         LSINT64                                                                 sequence;
00151                         vorbis_dsp_state *                                              vd;                     // For read-only access of configuration.
00152 
00153                         // Local storage to avoid remallocing; it's up to the mapping to
00154                         //      structure it.
00155                         LSVOID *                                                                localstore;
00156                         LSINT32                                                                 localtop;
00157                         LSINT32                                                                 localalloc;
00158                         LSINT32                                                                 totaluse;
00159                         alloc_chain *                                                   reap;
00160 
00161                         // Bitmetrics for the frame.
00162                         LSINT32                                                                 glue_bits;
00163                         LSINT32                                                                 time_bits;
00164                         LSINT32                                                                 floor_bits;
00165                         LSINT32                                                                 res_bits;
00166 
00167                         LSVOID *                                                                internal;
00168 
00169                 } * LPvorbis_block, * const LPCvorbis_block;
00170 
00174                 typedef struct vorbis_comment {
00175                         // Unlimited user _pcComment fields.  libvorbis writes 'libvorbis'
00176                         //      to whatever vendor is set in encode.
00177                         LSCHAR **                                                               user_comments;
00178                         LSINT32 *                                                               comment_lengths;
00179                         LSINT32                                                                 comments;
00180                         LSCHAR *                                                                vendor;
00181 
00182                 } * LPvorbis_comment, * const LPCvorbis_comment;
00183 
00184 
00185                 // == Functions.
00186                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00187                 // GENERAL
00188                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00194                 static LSVOID                                                           vorbis_info_init( vorbis_info * _pviVi );
00195 
00201                 static LSVOID                                                           vorbis_info_clear( vorbis_info * _pviVi );
00202 
00210                 static LSINT32                                                          vorbis_info_blocksize( vorbis_info * _pviVi, LSINT32 _i32Zo );
00211 
00217                 static LSVOID                                                           vorbis_comment_init( vorbis_comment * _pvcVc );
00218 
00225                 static LSVOID                                                           vorbis_comment_add( vorbis_comment * _pvcVc, const LSCHAR * _pcComment );
00226 
00234                 static LSVOID                                                           vorbis_comment_add_tag( vorbis_comment * _pvcVc, 
00235                         const LSCHAR * _pcTag, const LSCHAR * _pcContents );
00236 
00245                 static LSCHAR *                                                         vorbis_comment_query( vorbis_comment * _pvcVc, const LSCHAR * _pcTag, LSINT32 _i32Count );
00246 
00254                 static LSINT32                                                          vorbis_comment_query_count( vorbis_comment * _pvcVc, const LSCHAR * _pcTag );
00255 
00261                 static LSVOID                                                           vorbis_comment_clear( vorbis_comment * _pvcVc );
00262 
00270                 static LSINT32                                                          vorbis_block_init( vorbis_dsp_state * _pvdsV, vorbis_block * _pvbVb );
00271 
00278                 static LSINT32                                                          vorbis_block_clear( vorbis_block * _pvbVb );
00279 
00285                 static LSVOID                                                           vorbis_dsp_clear( vorbis_dsp_state * _pvdsV );
00286 
00294                 static LSDOUBLE                                                         vorbis_granule_time( vorbis_dsp_state * _pvdsV, 
00295                         LSINT64 _i64GranulePos );
00296 
00302                 static const LSCHAR *                                           vorbis_version_string();
00303 
00304 
00305 
00306                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00307                 // DSP LAYER
00308                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00316                 static LSINT32                                                          vorbis_analysis_init( vorbis_dsp_state * _pvdsV, vorbis_info * _pviVi );
00317 
00325                 static LSINT32                                                          vorbis_commentheader_out( vorbis_comment * _pvcVc, COgg::ogg_packet * _popOp );
00326 
00337                 static LSINT32                                                          vorbis_analysis_headerout( vorbis_dsp_state * _pvdsV, 
00338                         vorbis_comment * _pvcVc, 
00339                         COgg::ogg_packet * _popOp, 
00340                         COgg::ogg_packet * _popComm, 
00341                         COgg::ogg_packet * _popCode );
00342 
00350                 static LSFLOAT **                                                       vorbis_analysis_buffer( vorbis_dsp_state * _pvdsV, LSINT32 _i32Vals );
00351 
00359                 static LSINT32                                                          vorbis_analysis_wrote( vorbis_dsp_state * _pvdsV, LSINT32 _i32Vals );
00360 
00368                 static LSINT32                                                          vorbis_analysis_blockout( vorbis_dsp_state * _pvdsV, vorbis_block * _pvbVb );
00369 
00377                 static LSINT32                                                          vorbis_analysis( vorbis_block * _pvbVb, COgg::ogg_packet * _popOp );
00378 
00385                 static LSINT32                                                          vorbis_bitrate_addblock( vorbis_block * _pvbVb );
00386 
00394                 static LSINT32                                                          vorbis_bitrate_flushpacket( vorbis_dsp_state * _pvdsVd, 
00395                         COgg::ogg_packet * _popOp );
00396 
00397 
00398 
00399                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00400                 // SYNTHESIS LAYER
00401                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00408                 static LSINT32                                                          vorbis_synthesis_idheader( COgg::ogg_packet * _popOp );
00409 
00418                 static LSINT32                                                          vorbis_synthesis_headerin( vorbis_info * _pviVi, vorbis_comment * _pvcVc, 
00419                         COgg::ogg_packet * _popOp );
00420 
00428                 static LSINT32                                                          vorbis_synthesis_init( vorbis_dsp_state * _pvdsV, vorbis_info * _pviVi );
00429 
00436                 static LSINT32                                                          vorbis_synthesis_restart( vorbis_dsp_state * _pvdsV );
00437 
00445                 static LSINT32                                                          vorbis_synthesis( vorbis_block * _pvbVb, COgg::ogg_packet * _popOp );
00446 
00454                 static LSINT32                                                          vorbis_synthesis_trackonly( vorbis_block * _pvbVb, COgg::ogg_packet * _popOp );
00455 
00463                 static LSINT32                                                          vorbis_synthesis_blockin( vorbis_dsp_state * _pvdsV, vorbis_block * _pvbVb );
00464 
00472                 static LSINT32                                                          vorbis_synthesis_pcmout( vorbis_dsp_state * _pvdsV, LSFLOAT *** _pppfPcm );
00473 
00481                 static LSINT32                                                          vorbis_synthesis_lapout( vorbis_dsp_state * _pvdsV, LSFLOAT *** _pppfPcm );
00482 
00490                 static LSINT32                                                          vorbis_synthesis_read( vorbis_dsp_state * _pvdsV, LSINT32 _i32Samples );
00491 
00499                 static LSINT32                                                          vorbis_packet_blocksize( vorbis_info * _pviVi, COgg::ogg_packet * _popOp );
00500 
00508                 static LSINT32                                                          vorbis_synthesis_halfrate( vorbis_info * _pvdsV, LSINT32 _i32Flag );
00509 
00516                 static LSINT32                                                          vorbis_synthesis_halfrate_p( vorbis_info * _pvdsV );
00517 
00518 
00519 
00520                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00521                 // MISCELLANEOUS
00522                 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00530                 static LSFLOAT *                                                        vorbis_window( vorbis_dsp_state *_pvdsV, LSINT32 _i32Window );
00531 
00532 
00533         protected :
00534                 // == Members.
00535 
00536 
00537                 // == Functions.
00546                 static LSINT32                                                          tagcompare( const LSCHAR * _pcS1, const LSCHAR * _pcS2, LSINT32 _i32N );
00547 
00556                 static LSINT32                                                          _vds_shared_init( CVorbisCodec::vorbis_dsp_state * _pvdsV, CVorbisCodec::vorbis_info * _pviVi, LSINT32 _i32Encp );
00557 
00564                 static LSINT32                                                          ilog2( LSUINT32 _ui32V );
00565 
00573                 static LSINT32                                                          _vorbis_pack_comment( COgg::oggpack_buffer * _pobOpb, CVorbisCodec::vorbis_comment * _pvcVc );
00574 
00582                 static LSVOID                                                           _v_writestring( COgg::oggpack_buffer * _pobOut, const LSCHAR * _pcString, LSINT32 _i32Length );
00583 
00591                 static LSINT32                                                          _vorbis_pack_info( COgg::oggpack_buffer * _pobOpb, CVorbisCodec::vorbis_info * _pviVi );
00592 
00600                 static LSINT32                                                          _vorbis_pack_books( COgg::oggpack_buffer * _pobOpb, CVorbisCodec::vorbis_info * _pviVi );
00601 
00607                 static LSVOID                                                           _preextrapolate_helper( CVorbisCodec::vorbis_dsp_state * _pvdsV );
00608 
00616                 static LSVOID                                                           _v_readstring( COgg::oggpack_buffer * _popbBuffer, LSCHAR * _pcBuf, LSINT32 _i32Bytes );
00617 
00625                 static LSINT32                                                          _vorbis_unpack_info( vorbis_info * _pviVi, COgg::oggpack_buffer * _pobOpb );
00626 
00634                 static LSINT32                                                          _vorbis_unpack_comment( vorbis_comment * _pvcVc, COgg::oggpack_buffer * _pobOpb );
00635 
00643                 static LSINT32                                                          _vorbis_unpack_books( vorbis_info * _pviVi, COgg::oggpack_buffer * _pobOpb );
00644         };
00645 
00646 }       // namespace lss
00647 
00648 #endif  // __LSS_VORBISCODEC_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator