#ifndef vbrinfoH
#define vbrinfoH

/* -----------------------------------------------------------
 * A Vbr header may be present in the ancillary
 * data field of the first frame of an mp3 bitstream
 * The Vbr header (optionally) contains
 *      frames      total number of audio frames in the bitstream
 *      bytes       total number of bytes in the bitstream
 *      toc         table of contents

 * toc (table of contents) gives seek points
 * for random access
 * the ith entry determines the seek point for
 * i-percent duration
 * seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes
 * e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes
 */

#define XING_HEADER_SIZE 194

#define FRAMES_FLAG     0x0001
#define BYTES_FLAG      0x0002
#define TOC_FLAG        0x0004
#define VBR_SCALE_FLAG  0x0008

#define NUMTOCENTRIES 100

#define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG)

/*structure to receive extracted header */

extern const char VBRTagXing[];// = "Xing";
extern const char VBRTagInfo[];// = "Info";
extern const char VBRTagVBRI[];// = "VBRI";

#define DWORD_Xing *((DWORD*)VBRTagXing)
#define DWORD_Info *((DWORD*)VBRTagInfo)
#define DWORD_VBRI *((DWORD*)VBRTagVBRI)

typedef struct
{
    //VBRI/Xing/Info 共通
    union{
        char  header_str[5]; //Xing/Info/VBRI
        DWORD header_dword;
    };
    int     frames;         // total bit stream frames from Vbr header data
    int     bytes;          // total bit stream bytes from Vbr header data
    //Xing/Info のみ
    BYTE    quality;        //VBRI/Xing/Info LAME のバージョンを問わず有効
                            //LAME タグでは 1 バイトだが VBRI では 2 バイト
    char    lame_str[20+1]; //LAME3.90 以降のときは 9 バイトまで、3.90 未満のときは 20 バイトまで
    //ここから下は LAME3.90 以降のときだけ有効
    BYTE    rev_method;     //4 MSB : revision, 4 LSB : encoding method,  LAME 3.90 未満のときは 0xFF
    BYTE    lowpass;        //lowpass filter
    DWORD   track_peak;     //replaygain
    WORD    track_gain;     //replaygain
    WORD    album_gain;     //replaygain
    BYTE    enc_flags_ath_type; //4 MSB: encoding flag, 4 LSB ath type
    BYTE    bitrate;        //
    BYTE    misc;           //
    BYTE    mp3gain;        //
    WORD    sur_preset;     //surroundinfo
    DWORD   music_length;
    WORD    music_crc;
    WORD    tag_crc;
    DWORD   flags;          // from Vbr header data
    //unsigned char toc[NUMTOCENTRIES]; // may be NULL if toc not desired
    int     enc_delay;      // encoder delay 
    int     enc_padding;    // encoder paddign added at end of stream
    //VBRI のみ
    WORD    vbri_version;
    WORD    vbri_delay;     //delay(?) 16bit float(?)
    WORD    vbri_quality;   //quality(
}VBRTAGINFO;

int GetVbrInfo(VBRTAGINFO *pTagInfo,  unsigned char *buf);

#endif
