home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Sound / LAME / Source / formatBitstream.h < prev    next >
C/C++ Source or Header  |  1997-01-22  |  5KB  |  166 lines

  1. #ifndef _FORMAT_BITSTREAM_H
  2. #define _FORMAT_BITSTREAM_H
  3. /*********************************************************************
  4.   Copyright (c) 1995 ISO/IEC JTC1 SC29 WG1, All Rights Reserved
  5.   formatBitstream.h
  6. **********************************************************************/
  7.  
  8. /*
  9.   Revision History:
  10.  
  11.   Date        Programmer                Comment
  12.   ==========  ========================= ===============================
  13.   1995/09/06  mc@fivebats.com           created
  14.  
  15. */
  16. #ifndef MAX_CHANNELS
  17. #define MAX_CHANNELS 2
  18. #endif
  19.  
  20. #ifndef MAX_GRANULES
  21. #define MAX_GRANULES 2
  22. #endif
  23.  
  24. /* Find the ANSI header for these! */
  25. typedef unsigned int   uint32;
  26. typedef unsigned short uint16;
  27.  
  28. /*
  29.   This is the prototype for the function pointer you must
  30.   provide to write bits to the bitstream. It should write
  31.   'length' bits from 'value,' msb first. Bits in value are
  32.   assumed to be right-justified.
  33. */
  34. typedef void (*BitsFcnPtr)( uint32 value, uint16 length );
  35.  
  36. /*
  37.   A BitstreamElement contains encoded data
  38.   to be written to the bitstream.
  39.   'length' bits of 'value' will be written to
  40.   the bitstream msb-first.
  41. */
  42. typedef struct
  43. {
  44.     uint32 value;
  45.     uint16 length;
  46. } BF_BitstreamElement;
  47.  
  48. /*
  49.   A BitstreamPart contains a group
  50.   of 'nrEntries' of BitstreamElements.
  51.   Each BitstreamElement will be written
  52.   to the bitstream in the order it appears
  53.   in the 'element' array.
  54. */
  55. typedef struct
  56. {
  57.     uint32              nrEntries;
  58.     BF_BitstreamElement *element;
  59. } BF_BitstreamPart;
  60.  
  61. /*
  62.   This structure contains all the information needed by the
  63.   bitstream formatter to encode one frame of data. You must
  64.   fill this out and provide a pointer to it when you call
  65.   the formatter.
  66.   Maintainers: If you add or remove part of the side
  67.   information, you will have to update the routines that
  68.   make local copies of that information (in formatBitstream.c)
  69. */
  70.  
  71. typedef struct BF_FrameData
  72. {
  73.     BitsFcnPtr       putbits;  /* your low-level bitstream function */
  74.     int              frameLength;
  75.     int              nGranules;
  76.     int              nChannels;
  77.     BF_BitstreamPart *header;
  78.     BF_BitstreamPart *frameSI;
  79.     BF_BitstreamPart *channelSI[MAX_CHANNELS];
  80.     BF_BitstreamPart *spectrumSI[MAX_GRANULES][MAX_CHANNELS];
  81.     BF_BitstreamPart *scaleFactors[MAX_GRANULES][MAX_CHANNELS];
  82.     BF_BitstreamPart *codedData[MAX_GRANULES][MAX_CHANNELS];
  83.     BF_BitstreamPart *userSpectrum[MAX_GRANULES][MAX_CHANNELS];
  84.     BF_BitstreamPart *userFrameData;
  85. } BF_FrameData;
  86.  
  87. /*
  88.   This structure contains information provided by
  89.   the bitstream formatter. You can use this to
  90.   check to see if your code agrees with the results
  91.   of the call to the formatter.
  92. */
  93. typedef struct BF_FrameResults
  94. {
  95.     int SILength;
  96.     int mainDataLength;
  97.     int nextBackPtr;
  98. } BF_FrameResults;
  99.  
  100. /*
  101.   The following is a shorthand bitstream syntax for
  102.   the type of bitstream this package will create.
  103.   The bitstream has headers and side information that
  104.   are placed at appropriate sections to allow framing.
  105.   The main data is placed where it fits in a manner
  106.   similar to layer3, which means that main data for a
  107.   frame may be written to the bitstream before the
  108.   frame's header and side information is written.
  109.  
  110. BitstreamFrame()
  111. {
  112.     Header();
  113.     FrameSI();
  114.  
  115.     for ( ch )
  116.     ChannelSI();
  117.  
  118.     for ( gr )
  119.     for ( ch )
  120.         SpectrumSI();
  121.  
  122.     MainData();
  123. }
  124.  
  125. MainData()
  126. {
  127.     for ( gr )
  128.     for ( ch )
  129.     {
  130.         Scalefactors();
  131.         CodedData();
  132.         UserSpectrum();
  133.     }
  134.     UserFrameData();
  135. }
  136.  
  137. */
  138.  
  139. /*
  140.   public functions in formatBitstream.c
  141. */
  142.  
  143. /* count the bits in a BitstreamPart */
  144. int  BF_PartLength( BF_BitstreamPart *part );
  145.  
  146. /* encode a frame of audio and write it to your bitstream */
  147. void BF_BitstreamFrame( BF_FrameData *frameInfo, BF_FrameResults *results );
  148.  
  149. /* write any remaining frames to the bitstream, padding with zeros */
  150. void BF_FlushBitstream( BF_FrameData *frameInfo, BF_FrameResults *results );
  151.  
  152. typedef struct BF_PartHolder
  153. {
  154.     int              max_elements;
  155.     BF_BitstreamPart *part;
  156. } BF_PartHolder;
  157.  
  158. BF_PartHolder *BF_newPartHolder( int max_elements );
  159. BF_PartHolder *BF_resizePartHolder( BF_PartHolder *oldPH, int max_elements );
  160. BF_PartHolder *BF_addElement( BF_PartHolder *thePH, BF_BitstreamElement *theElement );
  161. BF_PartHolder *BF_addEntry( BF_PartHolder *thePH, uint32 value, uint16 length );
  162. BF_PartHolder *BF_NewHolderFromBitstreamPart( BF_BitstreamPart *thePart );
  163. BF_PartHolder *BF_LoadHolderFromBitstreamPart( BF_PartHolder *theHolder, BF_BitstreamPart *thePart );
  164. BF_PartHolder *BF_freePartHolder( BF_PartHolder *thePH );
  165. #endif
  166.