mp3_utils.h

Go to the documentation of this file.
00001 namespace mp3_utils
00002 {
00003 
00004         enum {
00005                 MPG_MD_STEREO=0,
00006                 MPG_MD_JOINT_STEREO=1,
00007                 MPG_MD_DUAL_CHANNEL=2,
00008                 MPG_MD_MONO=3,
00009         };
00010 
00011         typedef t_uint8 byte;
00012 
00013         enum {MPEG_1, MPEG_2, MPEG_25};
00014 
00015         struct TMPEGFrameInfo
00016         {
00017                 unsigned m_bytes;
00018                 unsigned m_sample_rate;
00019                 unsigned m_layer;
00020                 unsigned m_mpegversion;
00021                 unsigned m_channels;
00022                 unsigned m_duration;
00023                 unsigned m_channel_mode;
00024                 bool m_crc;
00025         };
00026 
00027 
00028         bool ParseMPEGFrameHeader(TMPEGFrameInfo & p_info,const t_uint8 p_header[4]);
00029         bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize);
00030         bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
00031         
00033         t_uint16 ExtractFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
00035         t_uint16 CalculateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
00037         void RecalculateFrameCRC(t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
00038 
00039         unsigned QueryMPEGFrameSize(const t_uint8 p_header[4]);
00040         bool IsSameStream(TMPEGFrameInfo const & p_frame1,TMPEGFrameInfo const & p_frame2);
00041 };
00042 
00043 class mp3header
00044 {
00045         t_uint8 bytes[4];
00046 public:
00047 
00048         inline void copy(const mp3header & src) {memcpy(bytes,src.bytes,4);}
00049         inline void copy_raw(const void * src) {memcpy(bytes,src,4);}
00050 
00051         inline mp3header(const mp3header & src) {copy(src);}
00052         inline mp3header() {}
00053 
00054         inline const mp3header & operator=(const mp3header & src) {copy(src); return *this;}
00055 
00056         inline void get_bytes(void * out) {memcpy(out,bytes,4);}
00057         inline unsigned get_frame_size() const {return mp3_utils::QueryMPEGFrameSize(bytes);}
00058         inline bool decode(mp3_utils::TMPEGFrameInfo & p_out) {return mp3_utils::ParseMPEGFrameHeader(p_out,bytes);}
00059 
00060         unsigned get_samples_per_frame();
00061 };
00062 
00063 static inline mp3header mp3header_from_buffer(const void * p_buffer)
00064 {
00065         mp3header temp;
00066         temp.copy_raw(p_buffer);
00067         return temp;
00068 }

Generated on Thu Aug 28 21:15:31 2008 for foobar2000 SDK by  doxygen 1.5.5