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

MP3Frame Class Reference

Core class. More...

Collaboration diagram for MP3Frame:

Collaboration graph
[legend]
List of all members.

Public Types

enum  { nowrite, fastwrite, normal }

Public Member Functions

 MP3Frame (MP3Stream *stream, MP3Frame *prev=0)
 ~MP3Frame ()
MP3FrameDestroy ()
MP3FrameNext ()
void Write (Bitstream &bs)
void SetDataBegin (int startpos)
void Enlarge (int num)
void WriteData (Bitstream &bs, MP3Frame *frame, int cutstart, int cutend)
void SetFirst ()
bool isLocked () const
bool CorruptionFound () const
int Bitrate () const
int DataSize () const
void ChangeGain (int n)
bool isSilent () const
void ShowInfo (std::ostream &str) const

Detailed Description

Core class.

Implements operations with MP3 Frames, creates a linked list of frames, works in cooperation with MP3Stream.

Most complexity is hidden here: MP3 files have so-called "bit reservoir". Frame data can be stored in few previous frames, so when a frame is written you have to work with 3 frames: the one you are writing, another one from which you write data and a third one where the data really are.

This class handles that, see function Write().

Warning:
Use this class only through MP3Iterator, unneeded frames could be dealocated without warning.

Definition at line 35 of file mp3frame.h.


Member Enumeration Documentation

anonymous enum
 

Write mode

Enumerator:
nowrite  Don't read audio data
fastwrite  Write frames as they were in input (with the same data)
normal  Rearrange data in frames (needed for cutting or joining of files

Definition at line 40 of file mp3frame.h.


Constructor & Destructor Documentation

MP3Frame::MP3Frame MP3Stream stream,
MP3Frame prev = 0
 

Constructor.

Reads data from MP3Stream, skips corrupted frames, so it always constructs an correct frame. EOF condition is handled in Bitstream via exceptions.

Parameters:
stream MP3Stream to read data from
prev Previous frame, needed to calculate position in stream and sanity checks, can be NULL in case of first frame of file.

Definition at line 17 of file mp3frame.cpp.

Referenced by Next().

MP3Frame::~MP3Frame  ) 
 

Destructor

Definition at line 35 of file mp3frame.cpp.


Member Function Documentation

int MP3Frame::Bitrate  )  const
 

Get frame's bitrate

Returns:
Bitrate in kbps

Definition at line 356 of file mp3frame.cpp.

References FrameHeader::Bitrate().

void MP3Frame::ChangeGain int  n  ) 
 

Change volume of frame

Parameters:
n Volume offset, may be negative

Definition at line 366 of file mp3frame.cpp.

References ChannelHeader::ChangeGain(), and FrameHeader::NumChannels().

bool MP3Frame::CorruptionFound  )  const
 

Whether there was some corruption before frame

Constructor always construct a valid frame, but records if there was some problem (with synchronization, invalid header, etc.).

Returns:
Whether corruption was detected

Definition at line 351 of file mp3frame.cpp.

int MP3Frame::DataSize  )  const
 

Number of bytes of data beloning to frame

These are not bytes in the frame, but data belonging to frame, which can be in a few preceding frames.

Returns:
Number of data bytes

Definition at line 361 of file mp3frame.cpp.

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

MP3Frame * MP3Frame::Destroy  ) 
 

Deletes itself and returns next frame.

Returns:
Next frame

Definition at line 181 of file mp3frame.cpp.

Referenced by MP3Stream::SeekTo(), and MP3Stream::~MP3Stream().

void MP3Frame::Enlarge int  num  ) 
 

Changes bitrate of frame in order to resize it.

When data in stream are moved forward (eg. when small frames on beginning are removed), sometimes they would overflow to next frame, which is forbidden. So the frame has to be resized by changing its bitrate.

Parameters:
num How many bytes must be added
Exceptions:
cannot_proceed When even the maximum bitrate won't fit all data

Definition at line 263 of file mp3frame.cpp.

References FrameHeader::Bitrate(), FrameHeader::Enlarge(), and FrameHeader::FrameSize().

Referenced by Write().

bool MP3Frame::isLocked  )  const
 

Whether frame is locked (can't be deleted)

It's was possible that Write() on some frame dealocated that frame, so i had to implement locking mechanism (only used in Write() in normal mode). MP3Stream::SeekTo() checks whether frame is locked, but not Destroy().

Returns:
Whether frame is locked

Definition at line 346 of file mp3frame.cpp.

Referenced by MP3Stream::SeekTo().

bool MP3Frame::isSilent  )  const
 

Whether frame is completely silent

It detects just digital silence acording to data size. Anything else would require decompression of audio.

Todo:
Try to find a more precise silent detection
Returns:
Whether frame is silent

Definition at line 374 of file mp3frame.cpp.

References ChannelHeader::DataSize(), and FrameHeader::NumChannels().

MP3Frame * MP3Frame::Next  ) 
 

Returns next frame (and reads it if it does not exist).

Returns:
Next frame in linked list

Definition at line 192 of file mp3frame.cpp.

References MP3Frame().

Referenced by MP3Iterator::operator++(), and MP3Stream::WriteData().

void MP3Frame::SetDataBegin int  startpos  ) 
 

Calculates offset of frame data.

The offset is difference between position of frame in stream and the position of its first byte (which can be up to mp3::max_databegin lower). When the offset should be higher than mp3::max_databegin, padding bytes are added.

Parameters:
startpos Position of first byte of data in stream

Definition at line 248 of file mp3frame.cpp.

References DataHeader::MaxDataBegin().

Referenced by MP3Stream::WriteData().

void MP3Frame::SetFirst  ) 
 

Makes this frame first in stream.

Needed when frames at the beginning are removed, because Write() on some next frame would cause data from removed frames being written. It don't delete any frames, because they can keep data of the new first frame.

Definition at line 341 of file mp3frame.cpp.

References MP3Stream::SetFirst().

void MP3Frame::ShowInfo std::ostream &  str  )  const
 

Write frame information

Writes version, layer, bitrate, etc.

Parameters:
str Output text stream

Definition at line 386 of file mp3frame.cpp.

References FrameHeader::Bitrate(), FrameHeader::Frequency(), FrameHeader::isIntensStereo(), FrameHeader::isMSstereo(), FrameHeader::isValid(), FrameHeader::Layer(), FrameHeader::Mode(), and FrameHeader::Version().

void MP3Frame::Write Bitstream bs  ) 
 

Write the frame with data.

Action depends on write mode of MP3Stream. In fastwrite mode it simply writes data in this frame. In normal mode it calls MP3Stream::WriteData() with number of bytes it needs.

It locks the frame so it won't be deallocated.

Parameters:
bs Output Bitstream

Definition at line 216 of file mp3frame.cpp.

References Enlarge(), fastwrite, nowrite, DataHeader::SetDataBegin(), AudioData::Write(), MP3Stream::WriteData(), and MP3Stream::WriteMode().

void MP3Frame::WriteData Bitstream bs,
MP3Frame frame,
int  cutstart,
int  cutend
 

Gets data belonging to frame from stream (ie. not data in the stream) and writes them.

Parameters cutstart and cutend are used to write only a part of frame so it fits to data part of other frame.

Warning:
It automatically deletes unneeded frames (whose data were already written), so frame can become invalid.
Parameters:
bs Output bitsteam
frame First frame of stream
cutstart How many bytes remove from beginning of frame
cutend How many bytes bytes remove from end of frame

Definition at line 280 of file mp3frame.cpp.

References DataSize(), m_data, m_next, m_spacesize, m_totalbytes, MP3Stream::SeekTo(), AudioData::Write(), and Bitstream::WriteNullBytes().

Referenced by MP3Stream::WriteData().


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