//-----------------------------------------------------------------------------
// File: mpglib.h
//-----------------------------------------------------------------------------

#ifndef _MPGLIB_H_
#define _MPGLIB_H_

extern "C" 
{


typedef struct buf {
        unsigned char *pnt;
		long size;
		long pos;
        struct buf *next;
        struct buf *prev;
} buf ;



typedef struct framebuf {
	struct buf *buf;
	long pos;
	struct frame *next;
	struct frame *prev;
} framebuf ;



typedef struct frame {
    int stereo;
    int jsbound;
    int single;
    int lsf;
    int mpeg25;
    int header_change;
    int lay;
    int error_protection;
    int bitrate_index;
    int sampling_frequency;
    int padding;
    int extension;
    int mode;
    int mode_ext;
    int copyright;
    int original;
    int emphasis;
    int framesize; // computed framesize 
} frame ;



#define MAXFRAMESIZE 1792
#define real float
#define		AUDIOBUFSIZE		16384

#define         FALSE                   0
#define         TRUE                    1

#define         SBLIMIT                 32
#define         SSLIMIT                 18

#define         MPG_MD_STEREO           0
#define         MPG_MD_JOINT_STEREO     1
#define         MPG_MD_DUAL_CHANNEL     2
#define         MPG_MD_MONO             3


typedef struct mpstr {
	struct buf *head,*tail;
	int bsize;
	int framesize;
    int fsizeold;
	struct frame fr;
    unsigned char bsspace[2][MAXFRAMESIZE+512]; // MAXFRAMESIZE 
	real hybrid_block[2][2][SBLIMIT*SSLIMIT];
	int hybrid_blc[2];
	unsigned long header;
	int bsnum;
	real synth_buffs[2][2][0x110];
    int  synth_bo;
	
} mpstr ;





extern int tabsel_123[2][3][16];



#define MP3_ERR			-1
#define MP3_OK			 0
#define MP3_NEED_MORE	 1
#define MAX_MP3_ERROR	 5
#define MIN_MP3_OK		10

extern long freqs[9];

BOOL	InitMP3(struct mpstr *mp);
int		decodeMP3(struct mpstr *mp,char *inmemory,int inmemsize,
char*	outmemory,int outmemsize,int *done);
void	ExitMP3(struct mpstr *mp);
int		decode_header(struct frame *fr,unsigned long newhead);






} // extern "C"



#endif