1 /*---- DXhead.h -------------------------------------------- 2 3 4 decoder MPEG Layer III 5 6 handle Xing header 7 8 9 Copyright 1998 Xing Technology Corp. 10 -----------------------------------------------------------*/ 11 // A Xing header may be present in the ancillary 12 // data field of the first frame of an mp3 bitstream 13 // The Xing header (optionally) contains 14 // frames total number of audio frames in the bitstream 15 // bytes total number of bytes in the bitstream 16 // toc table of contents 17 18 // toc (table of contents) gives seek points 19 // for random access 20 // the ith entry determines the seek point for 21 // i-percent duration 22 // seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes 23 // e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes 24 25 26 #define FRAMES_FLAG 0x0001 27 #define BYTES_FLAG 0x0002 28 #define TOC_FLAG 0x0004 29 #define VBR_SCALE_FLAG 0x0008 30 31 #define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG) 32 33 // structure to receive extracted header 34 // toc may be NULL 35 typedef struct { 36 int h_id; // from MPEG header, 0=MPEG2, 1=MPEG1 37 int samprate; // determined from MPEG header 38 int flags; // from Xing header data 39 int frames; // total bit stream frames from Xing header data 40 int bytes; // total bit stream bytes from Xing header data 41 int vbr_scale; // encoded vbr scale from Xing header data 42 unsigned char *toc; // pointer to unsigned char toc_buffer[100] 43 // may be NULL if toc not desired 44 } XHEADDATA; 45 46 47 int GetXingHeader(XHEADDATA *X, unsigned char *buf); 48 // return 0=fail, 1=success 49 // X structure to receive header data (output) 50 // buf bitstream input 51 52 53 int SeekPoint(unsigned char TOC[100], int file_bytes, float percent); 54 // return seekpoint in bytes (may be at eof if percent=100.0) 55 // TOC = table of contents from Xing header 56 // file_bytes = number of bytes in mp3 file 57 // percent = play time percentage of total playtime. May be 58 // fractional (e.g. 87.245) 59 60 61 62 63