/*
// ================================================================
// BitStream.h	PENTIUM VERSION
// Ubi Sound Studios
// 18/03/1997
// Guillaume Michel
// ================================================================
// Bitstream can be on file or in memory
*/

#ifndef _BITSTREAM_
#define _BITSTREAM_

// main structure
typedef struct SND_tdstBitStream {
	unsigned char	*pucInputBuffer;
	unsigned char	*pucBuffer;
	unsigned char	*pucCurrentPointer;
	tdhSndFile		*pFile;

	unsigned long	ulFinalSize; // Size of the sound after decompression

	unsigned long	ulSize;
	unsigned long	ulLastRead;		// number of byte we read
	unsigned long	ulBytePos;		// current byte position in one buffer
	unsigned char	ucBitPos;		// current bit position in one BYTE
	unsigned char	ucCurrentByte;	// current byte in the buffer

	unsigned long	ulDataOffset; 
	unsigned long	ulDolbyMark; // if == 'SURR' then the file is dolby surround one

} SND_tdstBitStream;

// ALLOCATING, OPENING, FREEING...
SndBool SND_fn_bAllocateBitStream(SND_tdstBitStream* pBitStream);
SndBool SND_fn_bFreeBitStream(SND_tdstBitStream* pBitStream);
SndBool SND_fn_bInitBitStream(SND_tdstBitStream* pBitStream);

SndBool SND_fn_bOpenBitStreamFile(SND_tdstBitStream* pBitStream, char* pFilename, unsigned long ulOffset);
SndBool SND_fn_bOpenBitStreamMem(SND_tdstBitStream* pBitStream, unsigned char* pBuffer, unsigned long ulSize);

// CLOSING
SndBool SND_fn_bCloseBitStream(SND_tdstBitStream* pBitStream);

// READING
SndBool SND_fn_bGet1Bit(SND_tdstBitStream* pBitStream, unsigned short *puwValue);
SndBool SND_fn_bGetNBits(SND_tdstBitStream* pBitStream, unsigned short *puwValue, unsigned char ucNbBits);
SndBool SND_fn_bSeekSynch(SND_tdstBitStream* pBitStream);

// PRIVATES FUNCTIONS
SndBool SND_fn_bFillBuffer(SND_tdstBitStream* pBitStream);

#endif
 