foobar2000 SDK  2015-08-03
mp3_utils.h
Go to the documentation of this file.
1 namespace mp3_utils
2 {
3 
4  enum {
9  };
10 
11  typedef t_uint8 byte;
12 
13  enum {MPEG_1, MPEG_2, MPEG_25};
14 
16  {
17  unsigned m_bytes;
18  unsigned m_sample_rate;
19  unsigned m_layer;
20  unsigned m_mpegversion;
21  unsigned m_channels;
22  unsigned m_duration;
23  unsigned m_channel_mode;
24  bool m_crc;
25  };
26 
27 
28  bool ParseMPEGFrameHeader(TMPEGFrameInfo & p_info,const t_uint8 p_header[4]);
29  bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize);
30  bool ValidateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
31 
33  t_uint16 ExtractFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
35  t_uint16 CalculateFrameCRC(const t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
37  void RecalculateFrameCRC(t_uint8 * frameData, t_size frameSize, TMPEGFrameInfo const & frameInfo);
38 
39  unsigned QueryMPEGFrameSize(const t_uint8 p_header[4]);
40  bool IsSameStream(TMPEGFrameInfo const & p_frame1,TMPEGFrameInfo const & p_frame2);
41 };
42 
43 class mp3header
44 {
45  t_uint8 bytes[4];
46 public:
47 
48  inline void copy(const mp3header & src) {memcpy(bytes,src.bytes,4);}
49  inline void copy_raw(const void * src) {memcpy(bytes,src,4);}
50 
51  inline mp3header(const mp3header & src) {copy(src);}
52  inline mp3header() {}
53 
54  inline const mp3header & operator=(const mp3header & src) {copy(src); return *this;}
55 
56  inline void get_bytes(void * out) {memcpy(out,bytes,4);}
57  inline unsigned get_frame_size() const {return mp3_utils::QueryMPEGFrameSize(bytes);}
58  inline bool decode(mp3_utils::TMPEGFrameInfo & p_out) {return mp3_utils::ParseMPEGFrameHeader(p_out,bytes);}
59 
60  unsigned get_samples_per_frame();
61 };
62 
63 static inline mp3header mp3header_from_buffer(const void * p_buffer)
64 {
65  mp3header temp;
66  temp.copy_raw(p_buffer);
67  return temp;
68 }
bool ValidateFrameCRC(const t_uint8 *frameData, t_size frameSize)
Definition: mp3_utils.cpp:256
uint8_t t_uint8
Definition: int_types.h:9
t_uint16 ExtractFrameCRC(const t_uint8 *frameData, t_size frameSize, TMPEGFrameInfo const &frameInfo)
Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize).
Definition: mp3_utils.cpp:232
static mp3header mp3header_from_buffer(const void *p_buffer)
Definition: mp3_utils.h:63
t_uint8 byte
Definition: mp3_utils.h:11
unsigned QueryMPEGFrameSize(const t_uint8 p_header[4])
Definition: mp3_utils.cpp:41
t_uint16 CalculateFrameCRC(const t_uint8 *frameData, t_size frameSize, TMPEGFrameInfo const &frameInfo)
Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize).
Definition: mp3_utils.cpp:238
bool IsSameStream(TMPEGFrameInfo const &p_frame1, TMPEGFrameInfo const &p_frame2)
Definition: mp3_utils.cpp:183
void copy(const mp3header &src)
Definition: mp3_utils.h:48
void copy_raw(const void *src)
Definition: mp3_utils.h:49
bool decode(mp3_utils::TMPEGFrameInfo &p_out)
Definition: mp3_utils.h:58
size_t t_size
Definition: int_types.h:48
mp3header(const mp3header &src)
Definition: mp3_utils.h:51
bool ParseMPEGFrameHeader(TMPEGFrameInfo &p_info, const t_uint8 p_header[4])
Definition: mp3_utils.cpp:48
uint16_t t_uint16
Definition: int_types.h:7
void RecalculateFrameCRC(t_uint8 *frameData, t_size frameSize, TMPEGFrameInfo const &frameInfo)
Assumes valid frame with CRC (frameInfo.m_crc set, frameInfo.m_bytes <= frameSize).
Definition: mp3_utils.cpp:213
unsigned get_frame_size() const
Definition: mp3_utils.h:57
void get_bytes(void *out)
Definition: mp3_utils.h:56
t_uint8 bytes[4]
Definition: mp3_utils.h:45
mp3header()
Definition: mp3_utils.h:52
This is free and unencumbered software released into the public domain Anyone is free to copy
Definition: pfc-license.txt:3
const mp3header & operator=(const mp3header &src)
Definition: mp3_utils.h:54