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 unsigned QueryMPEGFrameSize(const t_uint8 p_header[4]);
00030 bool IsSameStream(TMPEGFrameInfo const & p_frame1,TMPEGFrameInfo const & p_frame2);
00031 };
00032
00033 class mp3header
00034 {
00035 t_uint8 bytes[4];
00036 public:
00037
00038 inline void copy(const mp3header & src) {memcpy(bytes,src.bytes,4);}
00039 inline void copy_raw(const void * src) {memcpy(bytes,src,4);}
00040
00041 inline mp3header(const mp3header & src) {copy(src);}
00042 inline mp3header() {}
00043
00044 inline const mp3header & operator=(const mp3header & src) {copy(src); return *this;}
00045
00046 inline void get_bytes(void * out) {memcpy(out,bytes,4);}
00047 inline unsigned get_frame_size() const {return mp3_utils::QueryMPEGFrameSize(bytes);}
00048 inline bool decode(mp3_utils::TMPEGFrameInfo & p_out) {return mp3_utils::ParseMPEGFrameHeader(p_out,bytes);}
00049
00050 unsigned get_samples_per_frame();
00051 };
00052
00053 static inline mp3header mp3header_from_buffer(const void * p_buffer)
00054 {
00055 mp3header temp;
00056 temp.copy_raw(p_buffer);
00057 return temp;
00058 }