1 #ifndef _MP3STAT_H
2 #define _MP3STAT_H
3 
4 #include "input.h"
5 
6 class mp3 : public input
7 {
8   public:
mp3()9     mp3 () : input(), type("audio/mpeg") {;}
~mp3()10     virtual ~mp3() {;}
getType()11     inline virtual std::string getType() const { return(type); }
12     virtual void                statfile (statistic *);
13 
14   private:
15     typedef unsigned long ulong;
16     typedef unsigned int uint;
17     typedef unsigned short ushort;
18     typedef unsigned char uchar;
19     typedef signed char schar;
20   const std::string   type;
21   static int           min_valid;
22   static int           FREEFORMAT;
23   static int           FORBIDDEN;
24   static uint          CONST_MASK;
25   static int           layer_tab[4];
26   static int           bitrate1_tab[16][3];
27   static int           bitrate2_tab[16][3];
28   static double        sampd1_tab[4];
29   static int           samp_1_tab[4];
30   static double        sampd2_tab[4];
31   static int           samp_2_tab[4];
32 
33 
34 
35   struct Header
36   {
37     uint                emphasis:2,	// fix 2 reserved
38                         original:1,	// fix
39                         copyright:1,	// fix
40                         mode_extension:2,	//      (not fix!)
41                         mode:2,	// fix
42                         private_bit:1, padding_bit:1, sampling_frequency:2,	// fix 3 reserved
43                         bitrate_index:4,	//    15 forbidden
44                         protection_bit:1,	// fix
45                         layer_index:2,	// fix 0 reserved
46                         ID:1,	// fix 1==mpeg1.0 0==mpeg2.0
47                         syncword:12;	// fix must 0xfff
48 
isValidHeader49     bool                isValid () const
50     {
51       if (syncword != 0xfff)
52 	return false;
53       if (ID == 1) {		// mpeg 1.0
54 	if ((layer_index != 0) && (bitrate_index != 15) &&
55 	    (sampling_frequency != 3) && (emphasis != 2))
56 	  return true;
57 	return false;
58       } else
59       {				// mpeg 2.0
60 	if ((layer_index != 0) && (bitrate_index != 15) &&
61 	    (sampling_frequency != 3) && (emphasis != 2))
62 	  return true;
63 	return false;
64       }
65     }
sameConstantHeader66     bool                sameConstant (Header h) const
67     {
68       if ((*(uint *) this) == (*(uint *) & h))
69 	return true;
70       if ((syncword == h.syncword) &&
71 	  (ID == h.ID) &&
72 	  (layer_index == h.layer_index) &&
73 	  (protection_bit == h.protection_bit) &&
74 	  (sampling_frequency == h.sampling_frequency) &&
75 	  (mode == h.mode) &&
76 	  (copyright == h.copyright) &&
77 	  (original == h.original) && (emphasis == h.emphasis) && 1)
78 	return true;
79       else
80 	return false;
81     }
bitrateHeader82     int                 bitrate () const
83     {
84       if (ID)
85 	return bitrate1_tab[bitrate_index][layer () - 1];
86       else
87 	return bitrate2_tab[bitrate_index][layer () - 1];
88     }
layerHeader89     int                 layer () const
90     {
91       return layer_tab[layer_index];
92     }
versionHeader93     double              version () const
94     {
95       if (ID)
96 	return 1.0;
97       else
98 	return 2.0;
99     }
100     enum
101     { STEREO, JOINT_STEREO, DUAL_CHANNEL, SINGLE_CHANNEL };
mode_strHeader102     const char         *mode_str () const
103     {
104       switch (mode) {
105       case 0:
106 	return "stereo";
107 	case 1:return "joint stereo";
108 	case 2:return "dual channel";
109 	case 3:return "single chann";
110       }
111       return              0;
112     }
short_mode_strHeader113     const char         *short_mode_str () const
114     {
115       switch (mode) {
116       case 0:
117 	return "st";
118 	case 1:return "js";
119 	case 2:return "dc";
120 	case 3:return "sc";
121       }
122       return              0;
123     }
124     enum
125     { emp_NONE, emp_50_15_MICROSECONDS, emp_RESERVED, emp_CCITT_J_17 };
emphasis_strHeader126     const char         *emphasis_str () const
127     {
128       switch (emphasis) {
129       case 0:
130 	return "no emph";
131 	case 1:return "50/15us";
132 	case 2:return "reservd";
133 	case 3:return "C. J.17";
134       }
135       return              0;
136     }
short_emphasis_strHeader137     const char         *short_emphasis_str () const
138     {
139       switch (emphasis) {
140       case 0:
141 	return "n";
142 	case 1:return "5";
143 	case 2:return "!";
144 	case 3:return "J";
145       }
146       return              0;
147     }
samp_rateHeader148     double              samp_rate () const
149     {
150       if (ID)
151 	return sampd1_tab[sampling_frequency];
152       else
153 	return sampd2_tab[sampling_frequency];
154     }
samp_int_rateHeader155     int                 samp_int_rate () const
156     {
157       if (ID)
158 	return samp_1_tab[sampling_frequency];
159       else
160 	return samp_2_tab[sampling_frequency];
161     }
get_intHeader162     int                 get_int () const
163     {
164       return *((const int *) this);
165     }
166   };
167 
168   static inline Header get_header (const uchar *);
169   static inline void  set_header (uchar *, Header);
170   static inline int   frame_length (Header);
171   int                 find_next_header (const uchar *, int, int);
172   void         scan_mp3 (uchar *, int, statistic *);
173 
174 
175 };
176 
177 #endif
178