Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Bitstream Class Reference

I/O stream with bit access. More...

List of all members.

Public Types

enum  { in, out }

Public Member Functions

 Bitstream (const char *filename, int mode)
 Bitstream (const char **files, int mode)
void Read (unsigned int *data, int numbits)
void Write (const unsigned int *data, int numbits)
void Seek (int numbits)
int Find (unsigned int pattern, int numbits)
void ReadBytes (char *bytes, int num)
void WriteBytes (const char *bytes, int num)
void WriteNullBytes (int num)


Detailed Description

I/O stream with bit access.

EOF condition is reported via eof_final exception Input stream can work with list of files (reads them one by one, throws eof_partial at EOF condition, when there's at least one more file.

It's uses 32bit integers, but should be portable, it handles little/big endian issues. I can't test it, i have just x86 hardware. Could anyone send a Sparc workstation? :o)

Definition at line 24 of file bitstream.h.


Member Enumeration Documentation

anonymous enum
 

Direction

Enumerator:
out  Output stream

Definition at line 29 of file bitstream.h.


Constructor & Destructor Documentation

Bitstream::Bitstream const char *  filename,
int  mode
 

Constructor for one file

Parameters:
filename File to open
mode Input/Output
Exceptions:
open_failed When file does not exist

Definition at line 17 of file bitstream.cpp.

Bitstream::Bitstream const char **  files,
int  mode
 

Constructor for list of files

Warning:
Works only for input stream!
Parameters:
files Null terminated list of files
mode Input/Output
Exceptions:
open_failed When file does not exist

Definition at line 28 of file bitstream.cpp.


Member Function Documentation

int Bitstream::Find unsigned int  pattern,
int  numbits
 

Reads from the stream until pattern is found

Consecutive read will get bits immediately after the pattern

Warning:
The pattern is found only when it begins on byte boundary!
Parameters:
pattern Pattern to find, last bit is the low-order one
numbits Number of bits in pattern
Returns:
Number of skipped bytes

Definition at line 145 of file bitstream.cpp.

References Read(), and ReadBytes().

void Bitstream::Read unsigned int *  data,
int  numbits
 

Read bits from stream.

Bits are stored in integer array, first bit in high-order bit of first integer in array.

Parameters:
data Array to store bits in
numbits Number of bits to read

Definition at line 40 of file bitstream.cpp.

References ReadBytes().

Referenced by Bitarray< mp3_frame_header >::Bitarray(), and Find().

void Bitstream::ReadBytes char *  bytes,
int  num
 

Direct read of bytes

Skips bit-handling and reads bytes directly. Also used by Read().

Exceptions:
eof_partial EOF of non-last input file
eof_final EOF of last input file
Parameters:
bytes Array to store bytes in
num Number of bytes to read

Definition at line 170 of file bitstream.cpp.

Referenced by AudioData::AudioData(), Find(), Read(), and Seek().

void Bitstream::Seek int  numbits  ) 
 

Seek forward by number of bits

Parameters:
numbits How many bits to move forward

Definition at line 118 of file bitstream.cpp.

References ReadBytes().

void Bitstream::Write const unsigned int *  data,
int  numbits
 

Writes bits to stream.

Bits are given in integer array, first bit in high-order bit of first integer in array.

Parameters:
data Array with bits to write
numbits Number of bits to read

Definition at line 89 of file bitstream.cpp.

References WriteBytes().

Referenced by Bitarray< mp3_frame_header >::Write().

void Bitstream::WriteBytes const char *  bytes,
int  num
 

Direct write of bytes

Skips bit-handling and writes bytes directly. Also used by Write().

Parameters:
bytes Array to get bytes from
num Number of bytes to write

Definition at line 201 of file bitstream.cpp.

References out.

Referenced by Write(), and AudioData::Write().

void Bitstream::WriteNullBytes int  num  ) 
 

Write zero bytes to output

Parameters:
num Number of null

Definition at line 207 of file bitstream.cpp.

References out.

Referenced by MP3Stream::WriteData(), and MP3Frame::WriteData().


Generated on Wed Sep 6 00:18:17 2006 for Kraken by  doxygen 1.4.4