#ifndef MP3_CTX_H
#define MP3_CTX_H

#include "../../../include/v_lib.h"

#ifndef	M_PI
#define M_PI		3.141592653589793238462
#endif
#ifndef M_SQRT2
#define M_SQRT2		1.414213562373095048802
#endif

#define	NEW_DCT9
#ifdef	FALSE
#undef	FALSE
#endif
#define	FALSE                   0
#ifdef	TRUE
#undef	TRUE
#endif
#define	TRUE                    1
#define	MAX_NAME_SIZE           81
#define	SBLIMIT                 32
#define	SCALE_BLOCK             12
#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
#define	AUSHIFT					3

#define REAL_IS_FLOAT
#define real	float

struct al_table
{
	short bits;
	short d;
};

struct MP3_context_s;

struct frame {
	struct al_table *alloc;
	int (*synth)(struct MP3_context_s *,real *,int,unsigned char *,int *);
    int (*synth_mono)(struct MP3_context_s *,real *,unsigned char *,int *);
    int stereo;
    int jsbound;
    int single;
    int II_sblimit;
    int down_sample_sblimit;
	int lsf;
	int mpeg25;
    int down_sample;
	int header_change;
    int lay;
    int error_protection;
    int bitrate_index;
    long sampling_frequency;
    int padding;
    int extension;
    int mode;
	int mode_ext;
    int copyright;
	int original;
	int emphasis;
	long framesize; /* computed framesize */
};

#define MAXFRAMESIZE 1280
#define MAXFRAMESIZE2 (512+MAXFRAMESIZE)

typedef struct MP3_context_s
{
	int MP3_frames;
	int MP3_eof;
	int MP3_pause;
	int MP3_filesize;
	int MP3_fpos;			/* current file position */
	int MP3_framesize;	/* current framesize */
	int MP3_bitrate;		/* current bitrate */
	int MP3_samplerate;	/* current samplerate */
	int MP3_resync;
	int MP3_channels;
	int MP3_bps;
	int (*audio_read)(struct MP3_context_s *ctx,char *buf,int size);
	vhandle_t input_handle;
	vboolean mp3_loop;
	int fsizeold, ssize;
	unsigned char bsspace[2][MAXFRAMESIZE2];
	unsigned char *bsbufold;
	unsigned char *bsbuf;
	int bsnum;
	int bitindex;
	unsigned char *wordpointer;
	int bitsleft;
	unsigned char *pcm_sample;   /* outbuffer address */
	int pcm_point;           /* outbuffer offset */
	struct frame fr;
	real synth_1to1_buffs[2][2][0x110];
	int synth_1to1_bo;
	real III_hybrid_block[2][2][SBLIMIT * SSLIMIT];
	int III_hybrid_blc[2];
}	MP3_context_t, *MP3_context_p;

#endif
