1 | #ifndef __AC3_H |
---|
2 | #define __AC3_H |
---|
3 | |
---|
4 | #include "common.h" |
---|
5 | |
---|
6 | namespace ac3 |
---|
7 | { |
---|
8 | class counter |
---|
9 | { |
---|
10 | private: |
---|
11 | u_int16_t st; |
---|
12 | u_int32_t ctx; |
---|
13 | u_int16_t skip; |
---|
14 | u_int64_t frame_num; |
---|
15 | public: |
---|
16 | counter(void):st(0),ctx(0),skip(0),frame_num(0) {} |
---|
17 | |
---|
18 | void parse(const char* p,int l) |
---|
19 | { |
---|
20 | static const u_int16_t frame_size_32khz[]= |
---|
21 | { |
---|
22 | 96,96,120,120,144,144,168,168,192,192,240,240,288,288,336,336,384,384,480,480,576,576,672,672,768,768,960, |
---|
23 | 960,1152,1152,1344,1344,1536,1536,1728,1728,1920,1920 |
---|
24 | }; |
---|
25 | static const u_int16_t frame_size_44khz[]= |
---|
26 | { |
---|
27 | 69,70,87,88,104,105,121,122,139,140,174,175,208,209,243,244,278,279,348,349,417,418,487,488,557,558,696, |
---|
28 | 697,835,836,975,976,1114,1115,1253,1254,1393,1394 |
---|
29 | }; |
---|
30 | static const u_int16_t frame_size_48khz[]= |
---|
31 | { |
---|
32 | 64,64,80,80,96,96,112,112,128,128,160,160,192,192,224,224,256,256,320,320,384,384,448,448,512,512,640,640, |
---|
33 | 768,768,896,896,1024,1024,1152,1152,1280,1280 |
---|
34 | }; |
---|
35 | |
---|
36 | for(int i=0;i<l;) |
---|
37 | { |
---|
38 | if(skip>0) |
---|
39 | { |
---|
40 | int n=l-i; |
---|
41 | if(n>skip) |
---|
42 | n=skip; |
---|
43 | i+=n; |
---|
44 | skip-=n; |
---|
45 | |
---|
46 | if(i>=l) |
---|
47 | break; |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | ctx=(ctx<<8)+((unsigned char*)p)[i]; |
---|
52 | |
---|
53 | switch(st) |
---|
54 | { |
---|
55 | case 0: // wait 0x0b77 marker |
---|
56 | if((ctx&0xffff0000)==0x0b770000) |
---|
57 | { |
---|
58 | st++; |
---|
59 | frame_num++; |
---|
60 | } |
---|
61 | break; |
---|
62 | case 1: |
---|
63 | st++; |
---|
64 | break; |
---|
65 | case 2: |
---|
66 | { |
---|
67 | int frmsizecod=(ctx>>8)&0x3f; |
---|
68 | if(frmsizecod>37) |
---|
69 | frmsizecod=0; |
---|
70 | |
---|
71 | int framesize=0; |
---|
72 | |
---|
73 | switch((ctx>>14)&0x03) |
---|
74 | { |
---|
75 | case 0: framesize=frame_size_48khz[frmsizecod]; break; |
---|
76 | case 1: framesize=frame_size_44khz[frmsizecod]; break; |
---|
77 | case 2: framesize=frame_size_32khz[frmsizecod]; break; |
---|
78 | } |
---|
79 | |
---|
80 | skip=framesize*2-6; |
---|
81 | |
---|
82 | st=0; |
---|
83 | break; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | i++; |
---|
88 | |
---|
89 | } |
---|
90 | } |
---|
91 | u_int64_t get_frame_num(void) const { return frame_num; } |
---|
92 | |
---|
93 | void reset(void) |
---|
94 | { |
---|
95 | st=0; |
---|
96 | ctx=0; |
---|
97 | skip=0; |
---|
98 | frame_num=0; |
---|
99 | } |
---|
100 | }; |
---|
101 | } |
---|
102 | |
---|
103 | #endif |
---|