summaryrefslogtreecommitdiff
path: root/www/sh-win/enviro.jpg
blob: eb90f6d47e4e9d3f13b18243f5dc6d7b1b72f415 (plain)
ofshex dumpascii
0000 ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 60 00 60 00 00 ff db 00 43 00 08 06 06 07 06 05 08 ......JFIF.....`.`.....C........
0020 07 07 07 09 09 08 0a 0c 14 0d 0c 0b 0b 0c 19 12 13 0f 14 1d 1a 1f 1e 1d 1a 1c 1c 20 24 2e 27 20 ............................$.'.
0040 22 2c 23 1c 1c 28 37 29 2c 30 31 34 34 34 1f 27 39 3d 38 32 3c 2e 33 34 32 ff db 00 43 01 09 09 ",#..(7),01444.'9=82<.342...C...
0060 09 0c 0b 0c 18 0d 0d 18 32 21 1c 21 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 ........2!.!22222222222222222222
0080 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 ff c0 222222222222222222222222222222..
00a0 00 11 08 01 cd 01 9a 03 01 22 00 02 11 01 03 11 01 ff c4 00 1f 00 00 01 05 01 01 01 01 01 01 00 ........."......................
00c0 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b ff c4 00 b5 10 00 02 01 03 03 02 04 03 05 ................................
00e0 05 04 04 00 00 01 7d 01 02 03 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 14 32 81 91 a1 08 23 ......}........!1A..Qa."q.2....#
0100 42 b1 c1 15 52 d1 f0 24 33 62 72 82 09 0a 16 17 18 19 1a 25 26 27 28 29 2a 34 35 36 37 38 39 3a B...R..$3br........%&'()*456789:
0120 43 44 45 46 47 48 49 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 69 6a 73 74 75 76 77 78 79 7a CDEFGHIJSTUVWXYZcdefghijstuvwxyz
0140 83 84 85 86 87 88 89 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 a6 a7 a8 a9 aa b2 b3 b4 b5 b6 b7 ................................
0160 b8 b9 ba c2 c3 c4 c5 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da e1 e2 e3 e4 e5 e6 e7 e8 e9 ea f1 ................................
0180 f2 f3 f4 f5 f6 f7 f8 f9 fa ff c4 00 1f 01 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 00 01 ................................
01a0 02 03 04 05 06 07 08 09 0a 0b ff c4 00 b5 11 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 77 00 ..............................w.
01c0 01 02 03 11 04 05 21 31 06 12 41 51 07 61 71 13 22 32 81 08 14 42 91 a1 b1 c1 09 23 33 52 f0 15 ......!1..AQ.aq."2...B.....#3R..
01e0 62 72 d1 0a 16 24 34 e1 25 f1 17 18 19 1a 26 27 28 29 2a 35 36 37 38 39 3a 43 44 45 46 47 48 49 br...$4.%.....&'()*56789:CDEFGHI
0200 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 69 6a 73 74 75 76 77 78 79 7a 82 83 84 85 86 87 88 JSTUVWXYZcdefghijstuvwxyz.......
0220 89 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 a6 a7 a8 a9 aa b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 c4 ................................
0240 c5 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da e2 e3 e4 e5 e6 e7 e8 e9 ea f2 f3 f4 f5 f6 f7 f8 f9 ................................
0260 fa ff da 00 0c 03 01 00 02 11 03 11 00 3f 00 d6 f8 85 e3 fd 53 c2 ba f5 bd 86 9f 6b a7 34 2d 67 .............?......S......k.4-g
0280 14 bf bf 83 73 ef 6d ff 00 fc 45 72 df f0 b9 bc 49 ff 00 3e 5a 47 fe 02 ff 00 f6 75 d5 78 92 ef ....s.m...Er....I..>ZG.....u.x..
02a0 ec 7f 14 96 4f ec cd 46 f4 3e 83 b3 76 9d 16 fb 9b 6d db d7 cd 8b fd af e1 ff 00 81 56 44 fe 1a ....O..F.>..v....m..........VD..
02c0 d2 b5 9f 16 be 81 77 aa 6a 13 5f 5f 69 d0 4f 61 75 a8 b3 cb 73 62 df 79 a0 91 77 7d f2 bb 9f e6 ......w.j.__i.Oau...sb.y..w}....
02e0 db b6 bb e9 7b 25 05 cf 1e 97 30 93 9b 6e cc cc ff 00 85 cd e2 1f f9 f2 d2 3f f0 17 ff 00 b3 a7 ....{%....0..n...........?......
0300 ff 00 c2 e4 f1 0f fc f9 69 1f f8 0b ff 00 d9 d5 cd 1f 40 f0 b6 bd fd b9 71 a6 e9 be 4c 70 ce df ........i.........@.....q...Lp..
0320 63 96 ed 6e 5e cf ca 58 bf 8a 55 64 f2 99 be fb 6f fb bb 97 ad 5e 7d 3e c7 c4 1a af 80 ed ef ec c..n^..X..Ud....o....^}>........
0340 91 f4 b9 74 cb 78 a5 bf 57 74 dd 2a 24 bf e8 fb f7 6d fb cb f7 7e f5 5f ee 2f 6e 4f ea c4 de 7d ...t.x..Wt.*$....m...~._./nO...}
0360 cc 7f f8 5c 3e 21 ff 00 9f 2d 23 ff 00 01 7f fb 3a 7f fc 2d ff 00 10 ff 00 cf 96 91 ff 00 80 bf ...\>!...-#.....:..-............
0380 fd 9d 5c 83 41 d0 64 7b 99 64 f0 d5 fd b3 db 68 f7 57 4d 0d fc 32 da c5 2c b1 32 15 64 5f 35 9f ..\.A.d{.d.....h.WM..2..,.2.d_5.
03a0 a3 6d 6f 9f fb b4 92 78 67 43 92 da 58 c5 82 c4 f2 f8 6b fb 69 26 8e 59 37 a4 c3 6f ca bb 9b ee .mo....xgC..X.....k.i&.Y7..o....
03c0 f1 fc 5b 9b e6 fb d4 2f ab bf b0 1f bc ee 57 ff 00 85 b9 af ff 00 cf 9e 91 ff 00 80 bf fd 9d 3b ..[..../......W................;
03e0 fe 16 e6 bd ff 00 3e 5a 4f fe 02 ff 00 f6 75 3f 84 f5 64 d1 7e 1d 43 7b 35 ed ed ac 51 78 89 1d ......>ZO.....u?..d.~.C{5...Qx..
0400 96 c9 77 34 ab e5 2b 79 4d f3 2f ca df e1 50 dd 58 78 6e 6d 27 41 be 93 4c 16 af ae 5d ce 25 91 ..w4..+yM./...P.Xxnm'A..L...].%.
0420 6e 8a 2d ac 7f 6a 5f e1 da 57 e5 4c 2f f0 af d6 ab 92 97 35 9c 05 cd 2b 7c 41 ff 00 0b 6b 5f ff n.-..j_..W.L/......5...+|A...k_.
0440 00 9f 2d 2f ff 00 01 7f fb 3a 77 fc 2d 7d 7f fe 7c b4 bf fc 05 ff 00 ec eb 76 d3 c1 fa 2c da e5 ..-/.....:w.-}..|........v...,..
0460 ad bd de 8e 2d 37 6a d7 56 b1 c0 25 95 7e d3 6a 91 3b 2c bf 33 6e 3f 36 df 99 3e 5f 9a a9 58 78 ....-7j.V..%.~.j.;,.3n?6..>_..Xx
0480 67 46 97 fb 3a 4d 47 4e 7b 4b f9 34 eb c9 df 4c 56 97 73 bc 4f fb af dd 33 79 bf 3a ef 6d 9b be gF..:MGN{K.4...LV.s.O...3y.:.m..
04a0 6d 9f ef 54 5f 0f fc 83 fd e7 72 97 fc 2d 5d 73 fe 7d 74 bf fc 05 ff 00 ec e9 df f0 b5 75 cf f9 m..T_.....r..-]s.}t..........u..
04c0 f5 d2 ff 00 f0 17 ff 00 b3 ab 32 68 fe 1d 82 c3 59 d4 65 d0 35 18 05 9c 56 6e 2d 2e 99 ad 98 b3 ..........2h....Y.e.5...Vn-.....
04e0 4a e8 db 46 e6 f9 1b 6f f1 6e fe 2a d8 b1 81 6f f5 ef 05 62 d5 9a d1 f4 c4 89 af ed e5 95 5b 72 J..F...o.n.*...o...b..........[r
0500 c5 2f ee f7 a3 6d fe 1f f7 a8 7e c5 2b f2 7f 56 0f 7f b9 83 ff 00 0b 4f 5c ff 00 9f 5d 2b ff 00 ./...m....~.+..V.......O\...]+..
0520 01 ff 00 fb 3a 3f e1 68 6b 9f f3 eb a5 ff 00 e0 3f ff 00 67 4f b9 d1 34 58 7c 2d 6f 71 16 99 a8 ....:?.hk.......?..gO..4X|-oq...
0540 5d 3c fa 6f 9f f6 cb 68 59 d6 29 ff 00 8b 73 f9 9b 11 57 66 d6 5d 9f f0 2a 67 8b b4 2d 3f 4b d1 ]<.o...hY.)...s...Wf.]..*g..-?K.
0560 ac ae 6c 2d fe ce 25 6f 2b ca ba 8a 58 ae 4f cb f3 6e de fb 59 3f be ca bf dd aa 8a c3 b6 97 2e ..l-..%o+...X.O..n..Y?..........
0580 e4 f3 54 b6 e3 ff 00 e1 67 6b 5f f3 eb a6 ff 00 e0 3d 3b fe 16 6e b5 ff 00 3e ba 6f fe 03 d7 10 ..T.....gk_......=;..n...>.o....
05a0 b5 32 d6 ff 00 57 a3 fc a8 9f 6b 3e e7 69 ff 00 0b 2b 59 ff 00 9f 5d 37 fe fc 53 ff 00 e1 64 6b .2...W....k>.i...+Y...]7..S...dk
05c0 3f f3 eb a6 ff 00 df 8a e2 96 9e b4 be ad 4b f9 50 7b 59 f7 3b 4f f8 58 ba bf fc fa e9 df f7 e2 ?.............K.P{Y.;O.X........
05e0 8f f8 58 7a bf fc fa e9 bf f8 0f 5c 82 d3 d6 a7 ea f4 bf 95 07 b5 9f 73 af ff 00 85 87 ab ff 00 ..Xz.......\...........s........
0600 cf ae 9d ff 00 7e 29 df f0 b0 75 7f f9 f7 b0 ff 00 c0 7a e4 16 a6 5a 3e af 4b f9 43 da cf b9 d6 .....~)...u.......z...Z>.K.C....
0620 7f c2 7d aa 7f cf bd 87 fe 03 d3 ff 00 e1 3c d5 7f e7 de c3 ff 00 01 eb 92 5a 7a d1 f5 7a 5d 83 ..}...........<..........Zz..z].
0640 da cf b9 d6 7f c2 77 aa 7f cf bd 87 fd f8 a3 fe 13 9d 57 fe 7d ec 3f f0 1e b9 85 a7 ad 1f 57 a5 ......w...........W.}.?.......W.
0660 d8 3d ac fb 9d 3f fc 26 fa 97 fc fb d8 7f e0 3d 3f fe 13 4d 4b fe 7d ec 3f f0 1e b9 75 a9 96 87 .=...?.&.......=?..MK.}.?...u...
0680 42 97 f2 87 b5 9f 73 a4 ff 00 84 cb 52 ff 00 9f 7b 2f fc 07 a7 ff 00 c2 65 a9 7f cf bd 97 fe 03 B.....s.....R...{/......e.......
06a0 d7 34 b4 f5 a5 ec 29 7f 28 7b 59 f7 3a 5f f8 4b ef ff 00 e7 de cb ff 00 01 e8 ff 00 84 b7 50 ff .4....).({Y.:_.K..............P.
06c0 00 9e 56 5f f8 0f 5c fa d3 d6 97 d5 e9 76 0f 6b 3e e6 ff 00 fc 25 57 ff 00 f3 ca cb ff 00 01 e9 ..V_..\......v.k>....%W.........
06e0 ff 00 f0 95 5f ff 00 cf 2b 2f fc 07 ae 7d 6a 65 a3 ea f4 bb 07 b5 9f 73 77 fe 12 8b df f9 e5 6b ...._...+/...}je.......sw......k
0700 ff 00 80 f4 bf f0 92 5e 7f cf 2b 6f fb f0 b5 86 b4 f5 a5 ec 29 76 27 db 4f b9 b9 ff 00 09 15 e7 .......^..+o........)v'.O.......
0720 fc f2 b6 ff 00 bf 0b 47 fc 24 57 9f f3 ca db fe fc 2d 63 25 4a b4 7b 0a 5f ca 1e da 7d cd 7f ed .......G.$W......-c%J.{._...}...
0740 fb af f9 e5 6d ff 00 7e 16 9f fd bd 75 ff 00 3c ad 7f ef d2 d6 3a d3 d6 8f 61 4f b0 bd ac fb 9b ....m..~....u..<.....:...aO.....
0760 1f db 77 5f f3 ca d7 fe fd 2d 3b fb 66 eb fe 79 5b ff 00 df a4 ac a5 a7 ad 1e c2 9f 60 f6 b3 ee ..w_.....-;.f..y[...........`...
0780 6a ff 00 6c dc 7f 76 df fe fd 25 1f da f7 1f dc b7 ff 00 bf 49 59 a9 52 ad 1e c2 9f 60 f6 b3 ee j..l..v...%.........IY.R....`...
07a0 5f fe d4 b8 fe e5 bf fd fa 4a 7f f6 8d c7 f7 2d ff 00 ef d2 56 7a d3 d6 a3 d8 d3 ec 1e d6 7d cd _........J.....-....Vz........}.
07c0 78 65 b8 96 2f 37 75 aa a6 ed bf 34 5f fd 85 53 b6 d6 ac 2f 6f 26 b0 b6 d5 f4 89 ae 63 dd e6 c1 xe../7u....4_..S.../o&......c...
07e0 11 46 61 b7 fb cb b6 a7 8b fe 3c 17 fe ba b7 fe 80 b5 c3 e8 5a 26 9c 9e 33 b8 b6 85 a2 4b 6f 0f .Fa.......<.........Z&..3....Ko.
0800 46 a2 c2 ca 23 20 6b 76 b8 4d d2 b4 8c df 79 9b f8 3e 76 fd 2b 8a a3 51 9b 49 23 b2 11 e6 8a 6d F...#.kv.M....y..>v.+..Q.I#....m
0820 b3 b4 b3 d5 05 fc f7 b0 c0 d6 df e8 72 f9 32 b3 41 f2 ef f9 7f d9 ff 00 6a ad ee 97 fe 7b d9 ff ............r.2.A.......j....{..
0840 00 df 8f fe c6 b9 df 0c 7f c7 c7 89 3f eb f5 ff 00 f6 95 72 3a de 99 7b 3e ad a9 cb a5 69 da 8a ............?......r:..{>....i..
0860 e8 5e 72 7f 6b 5a 46 de 5b 6a 2d fc 4d 02 95 dd f7 7e fb 2b 2f 9b f7 57 fb d4 a7 2b 5b 45 b1 51 .^r.kZF.[j-.M....~.+/..W...+[E.Q
0880 57 be ac f4 39 b5 6f 2b 55 8a c3 74 12 cb 2c 4f 2f cb 07 dd 45 74 5f ee ff 00 b7 5f 3e 6a 33 dc W...9.o+U..t..,O/...Et_...._>j3.
08a0 36 a7 76 7e d3 9c cc e7 f5 35 ec 51 79 0b e2 cd 3f ec d1 79 50 7f 65 7e ea 2f 2b ca d8 bb d3 6a 6.v~.....5.Qy...?..yP.e~./+....j
08c0 6d fe 0f f7 2b c6 b5 0f f9 09 5d 7f d7 67 fe 66 93 d5 27 60 5a 36 8f 4c f8 89 e0 4d 57 c5 3e 21 m...+.....]..g.f..'`Z6.L...MW.>!
08e0 b7 bd b1 9e ca 28 92 ce 28 bf 7c ec 8f bb fe f9 ff 00 6a b0 34 df 86 be 2d d2 be d5 f6 2d 47 4d .....(..(.|.......j.4...-....-GM
0900 8f ed 90 35 ac f9 66 7d d1 37 de 5f b9 5e cb 73 fe b5 3f eb 92 7f e8 14 c5 89 a5 6d b1 2b 37 fb ...5..f}.7._.^.s..?........m.+7.
0920 95 71 c5 d4 8c 54 3a 03 a3 16 ee cf 13 ff 00 85 45 af ff 00 cf d6 9b ff 00 7f 5f ff 00 88 a7 ff .q...T:.........E........._.....
0940 00 c2 a5 d7 ff 00 e7 eb 4d ff 00 bf af ff 00 c4 57 b6 7d 96 e3 fe 7d e5 ff 00 be 28 fb 2d c7 fc ........M.......W.}...}....(.-..
0960 fb cb ff 00 7c 55 fd 7a b7 91 3e c2 07 8b 7f c2 a7 d7 ff 00 e7 eb 4d ff 00 bf af ff 00 c4 53 bf ....|U.z..>...........M.......S.
0980 e1 54 6b 9f f3 f5 a6 ff 00 df d7 ff 00 e2 2b d9 fe cb 71 ff 00 3e f2 ff 00 df 14 7d 96 e3 fe 7d .Tk...........+...q..>.....}...}
09a0 e5 ff 00 be 28 fa f5 6f 20 f6 10 3c 63 fe 15 56 b9 ff 00 3f 5a 6f fd fd 7f fe 22 9f ff 00 0a b3 ....(..o...<c..V...?Zo....".....
09c0 5c ff 00 9f ad 37 fe fe bf ff 00 11 5e c9 f6 5b 8f f9 f7 97 fe f8 a6 79 52 f9 be 57 94 db bf b9 \....7......^..[.......yR..W....
09e0 b2 8f af 56 f2 0f 61 03 cb 74 bf 01 78 9b 45 d4 62 bf d3 ef f4 f8 2e a3 df b5 b7 33 ed f9 36 7f ...V..a..t..x.E.b..........3..6.
0a00 1a 55 5f f8 55 fa d7 fc fd 58 7f df 6f ff 00 c4 57 af fd 96 e3 fe 7d e5 ff 00 be 28 fb 2d c7 fc .U_.U....X..o...W.....}....(.-..
0a20 fb cb ff 00 7c 52 fa ed 5d f4 1f b0 86 c7 91 ff 00 c2 b1 d6 bf e7 ea c3 fe fb 7f fe 22 9d ff 00 ....|R..]..................."...
0a40 0a d3 5a ff 00 9f ab 0f fb ed ff 00 f8 8a f5 af b2 dc 7f cf bc bf f7 c5 1f 65 b8 ff 00 9f 79 7f ..Z......................e....y.
0a60 ef 8a 7f 5e ad e4 2f 61 03 c9 7f e1 5b eb 5f f3 f5 61 ff 00 7d bf ff 00 11 4f ff 00 85 73 ab ff ...^../a....[._..a..}....O...s..
0a80 00 cf c5 87 fd f4 ff 00 fc 45 7a bf d9 6e 3f e7 de 5f fb e2 8f b2 dc 7f cf bc bf f7 c5 27 8e ad .........Ez..n?.._...........'..
0aa0 e4 1e c2 07 95 ff 00 c2 b9 d5 ff 00 e7 e2 cb fe fb 7f fe 22 9d ff 00 0a ef 57 ff 00 9f 8b 2f fb ...................".....W..../.
0ac0 ed ff 00 f8 8a f5 2f b2 dc 7f cf bc bf f7 c5 1f 65 b8 ff 00 9f 79 7f ef 8a 5f 5d ad e5 f7 07 b0 ....../.........e....y..._].....
0ae0 81 e6 1f f0 af b5 7f f9 f8 b2 ff 00 be df ff 00 88 a7 ff 00 c2 03 aa 7f cf c5 97 fd f6 ff 00 fc ................................
0b00 45 7a 67 d9 6e 3f e7 de 5f fb e2 8f b2 dc 7f cf bc bf f7 c5 1f 5d ad e5 f7 07 b0 81 e6 7f f0 80 Ezg.n?.._............]..........
0b20 ea 9f f3 f1 65 ff 00 7d bf ff 00 11 4e ff 00 84 0f 54 ff 00 9f 8b 2f fb ed ff 00 f8 8a f4 af b2 ....e..}....N....T..../.........
0b40 dc 7f cf bc bf f7 c5 1f 65 b8 ff 00 9f 79 7f ef 8a 3e bb 5b cb ee 0f 61 03 ce 3f e1 06 d4 bf e7 ........e....y...>.[...a..?.....
0b60 e2 cb fe fb 7f fe 22 9d ff 00 08 46 a5 ff 00 3f 16 bf f7 d3 ff 00 f1 15 e8 bf 65 b8 ff 00 9f 79 ......"....F...?..........e....y
0b80 7f ef 8a 63 41 2c 49 bd a2 75 ff 00 7d 28 fa ed 5f 20 f6 10 38 0f f8 42 b5 2f f9 f8 b5 ff 00 be ...cA,I..u..}(.._...8..B./......
0ba0 df ff 00 88 a7 ff 00 c2 17 a9 7f cf c5 af fd f6 ff 00 fc 45 77 cb 6b 3b 2e e5 b7 97 fe f9 a5 fb ...................Ew.k;........
0bc0 2d c7 fc fb cb ff 00 7c 51 f5 da be 41 ec 20 70 1f f0 86 df ff 00 cf 5b 5f fb e9 ff 00 f8 8a 77 -......|Q...A..p.......[_......w
0be0 fc 21 f7 ff 00 f3 d6 d7 fe fb 7f fe 22 bb df b2 dc 7f cf bc bf f7 c5 1f 65 b8 ff 00 9f 79 7f ef .!.........."...........e....y..
0c00 8a 3e bb 57 c8 3d 84 0e 17 fe 11 2b ff 00 f9 eb 6b ff 00 7d bf ff 00 11 4f ff 00 84 4a ff 00 fe .>.W.=.....+....k..}....O...J...
0c20 7a db ff 00 df 6f ff 00 c4 57 6f f6 5b 8f f9 f7 97 fe f8 a3 ec b7 1f f3 ef 2f fd f1 43 c6 55 f2 z....o...Wo.[............/..C.U.
0c40 0f 61 03 8a ff 00 84 52 f7 fe 7a db ff 00 df 4f ff 00 c4 53 ff 00 e1 17 bd ff 00 9e b6 ff 00 f7 .a.....R..z....O...S............
0c60 db ff 00 f1 15 d8 b5 ac ea bb 9a de 5f fb e6 9a b0 4b 2a 6f 8a 26 6f f7 12 97 d6 ea 87 b0 81 c8 ............_....K*o.&o.........
0c80 7f c2 33 7b ff 00 3d 6d ff 00 ef b7 a7 7f c2 35 7b ff 00 3d 6d ff 00 ef b7 ae c3 ec b7 1f f3 ef ..3{..=m.......5{..=m...........
0ca0 2f fd f1 47 d9 6e 3f e7 de 5f fb e2 8f ad d5 0f 61 03 92 ff 00 84 72 eb fe 7a db ff 00 df 4d 4f /..G.n?.._......a.....r..z....MO
0cc0 ff 00 84 7e eb fe 7a db ff 00 df 75 d5 7d 96 e3 fe 7d e5 ff 00 be 28 fb 2d c7 fc fb cb ff 00 7c ...~..z....u.}...}....(.-......|
0ce0 51 f5 ba a1 ec 20 72 ff 00 d8 37 5f df 8b fe fb a3 fb 12 eb fb d1 7f df 75 d4 7d 96 e3 fe 7d e5 Q.....r...7_............u.}...}.
0d00 ff 00 be 28 fb 2d c7 fc fb cb ff 00 7c 51 f5 ba a1 ec 20 73 5f d8 97 1f de 8a 9f fd 8d 71 fd e8 ...(.-......|Q.....s_........q..
0d20 ab a2 fb 2d c7 fc fb cb ff 00 7c 52 7d 96 73 ff 00 2c 25 5f f7 92 8f ad d5 0f 61 03 03 fb 22 e3 ...-......|R}.s..,%_......a...".
0d40 fb f1 53 ff 00 b2 ee 3f bf 15 6e 79 6b ff 00 3f 31 ff 00 e3 df fc 4d 1e 5a ff 00 cf cc 7f f8 f7 ..S....?..nyk..?1.....M.Z.......
0d60 ff 00 13 47 d6 ea 87 b0 81 8d fd 97 2f f7 d6 93 fb 3a 5f ef a5 6d 79 6b ff 00 3f 31 ff 00 e3 df ...G......../....:_..myk..?1....
0d80 fc 4d 1e 5a ff 00 cf cc 7f f8 f7 ff 00 13 43 c5 d5 0f 61 03 23 ec 12 ff 00 7d 69 ff 00 62 97 fb .M.Z..........C...a.#....}i..b..
0da0 c9 5a 9e 5a ff 00 cf cc 7f f8 f7 ff 00 13 47 96 bf f3 f3 1f fe 3d ff 00 c4 d2 fa d5 40 f6 10 33 .Z.Z..........G......=......@..3
0dc0 7e ca ff 00 df 4a 7f d9 5f fd 8a bf e5 af fc fc c7 ff 00 8f 7f f1 35 05 cc b6 f6 7e 57 9b 75 17 ~....J.._.............5....~W.u.
0de0 ef 65 f2 93 ef fd fa 3e b5 50 3d 84 0c cb ed 2e ea f3 62 2e ab 7b 6a 89 fc 16 ee 89 ff 00 b2 55 .e.....>.P=.......b..{j........U
0e00 5f f8 47 2e bf e8 3f ab ff 00 df d4 ff 00 e2 2b 7e 8a cd d5 6f 56 91 6a 9d b4 4d 98 56 de 1e 96 _.G...?........+~...oV.j..M.V...
0e20 da ca 78 20 d5 2f 15 ee 65 f3 a5 b8 dc 9e 6b 7d df f6 3f d9 5a 6f fc 23 97 5f f4 1f d5 ff 00 ef ..x../..e.....k}..?.Zo.#._......
0e40 ea 7f f1 15 bf 45 0e a5 fa 20 50 b7 56 62 d8 f8 7b ec 7a 92 5e cb 7f 75 75 2a c5 e5 7f a4 3a 3f .....E....P.Vb..{.z.^..uu*....:?
0e60 c9 bf 7f f7 3f d8 af 0d d4 3f e4 25 75 ff 00 5d 9f f9 9a fa 32 be 73 d4 3f e4 25 75 ff 00 5d 9f ....?....?.%u..]....2.s.?.%u..].
0e80 f9 9a 39 b9 81 46 c7 d2 57 3f eb 53 fe b9 27 fe 81 48 df f1 e6 bf f5 d5 bf f6 5a 5b 9f f5 a9 ff ..9..F..W?.S..'..H........Z[....
0ea0 00 5c 93 ff 00 40 a4 6f f8 f3 8b fe ba b7 fe cb 59 96 60 c9 ab 5f 4b 7f 7b 0e 9d a7 47 75 1d 9c .\...@.o........Y.`.._K.{...Gu..
0ec0 c9 14 fb ee bc a9 19 b6 ab fe e9 76 ed 6f 95 d3 ef 32 fc df f7 d5 5f 6d 4a c2 2d 42 2b 09 6f 6d ...........v.o...2...._mJ.-B+.om
0ee0 d2 f6 55 df 15 bb ca 9e 6b a7 fb 9f f0 07 ae 67 5f f0 bd ee a9 6b ac d9 45 6f a6 5c 45 a8 bf da ..U.....k......g_....k..Eo.\E...
0f00 16 e2 f7 76 eb 59 7e ce b1 7c 89 b3 fd 81 f3 6f f9 77 7d d6 db f3 58 b9 f0 c4 d2 78 8e 5b ed ab ...v.Y~..|.....o.w}...X....x.[..
0f20 2c 13 dd 45 72 c5 ee e7 5f 29 a2 48 be 5f 21 7e 47 ff 00 55 f7 9d bf 8b ee be cf 99 d8 66 e4 5a ,..Er..._).H._!~G..U.........f.Z
0f40 c6 97 34 53 cb 16 a3 66 cb 04 49 2c ac 93 af ee 91 d7 72 3b 7f 75 36 fc f4 90 6b 3a 5d d7 d9 3c ..4S...f..I,......r;.u6...k:]..<
0f60 8d 4a ca 5f b5 6f fb 3e cb 84 7f 37 67 df d9 fd fd 95 cb bf 83 27 3a 2e 8d 63 09 82 23 61 62 22 .J._.o.>...7g........':..c..#ab"
0f80 91 23 66 88 4b 2f 9b 6f 2f ca cb f3 2e e6 b7 6f 9f ef 7c db aa c5 87 86 6f ed 6e 9e e9 26 8e ce .#f.K/.o/......o..|.....o.n..&..
0fa0 79 60 ba 52 45 c4 b7 8d 1c b2 f9 08 8f be 5f f5 bf ea 3f d9 fe 15 ff 00 6a 8b 01 ad ff 00 09 15 y`.RE........._...?.....j.......
0fc0 85 c4 b6 1f d9 d7 16 f7 d1 5e 5d 35 ab 4b 05 c2 b2 c4 e9 13 4b fc 1f ee ff 00 e3 d4 ed 29 9d 7c .........^]5.K......K........).|
0fe0 41 af ae ff 00 93 fd 15 f6 7f c0 25 ff 00 e2 17 fe f9 ac 2d 37 c3 3a 94 5e 20 83 51 99 22 8a 28 A..........%.......-7.:.^..Q.".(
1000 e5 89 ca ff 00 68 cf 78 df 24 57 4b f7 a5 4f fa 6e bf 27 fb 0f 5b 7a 6f fc 8c 5a ff 00 fb 96 5f .....h.x.$WK..O.n.'..[zo..Z...._
1020 fa 04 b4 00 7f 6f 44 9e 2b fe c1 96 06 57 7b 55 b8 8a e3 f8 59 dd db f7 5f ef fc ae ff 00 f0 07 .....oD.+....W{U....Y..._.......
1040 fe e5 2d 97 88 6c 26 d3 34 9b 9b ab 88 2c e5 d4 e0 8a 58 2d e5 9d 77 33 b2 a7 ca 9f de fb f5 15 ..-..l&.4....,....X-..w3........
1060 f6 87 2d e6 a5 7d 72 b3 a4 0d 25 b4 0b 6b 70 83 73 c1 2a b4 ff 00 36 7a ff 00 cb 5f f8 17 ce ad ..-..}r...%..kp.s.*...6z..._....
1080 f2 d6 03 78 2a ef ec 56 70 39 8a e3 fe 25 50 69 b7 19 bf 9e 04 5f 2b 7f cf b2 2f f5 ab f3 fd d7 ...x*..Vp9...%Pi....._+.../.....
10a0 d9 f7 3f db a2 c0 74 d6 9e 20 d2 af 22 b8 95 6e a2 8b ec b2 dc 45 2a 4b 2a 2b 27 94 db 1d df fd ..?...t....."..n.....E*K*+'.....
10c0 8f b8 ff 00 f0 34 ab 17 7a c6 97 63 13 cb 77 a8 d9 db 22 4b e5 3b cb 3a ae c6 db bb 6f fb fb 7e .....4..z..c..w..."K.;.:....o..~
10e0 6a c2 7f 0b 4b 34 b0 24 b2 23 5b a5 d5 d7 9b f3 ff 00 ad b7 b8 97 ed 0e 9b 36 7f 7d 11 3f b8 e9 j...K4.$.#[..............6.}.?..
1100 bf fb ff 00 2c 76 3e 1e d5 74 9b 98 6f 6d a5 86 fa ef f7 b1 3a dd 4c c8 5d 1b ca 54 7d fb 1b e7 ....,v>..t..om......:.L.]..T}...
1120 d9 6b 16 ff 00 97 ef 3b 51 60 36 6e 75 bb 58 f5 4b 5d 36 29 62 9e e2 49 fe cf 2a 24 bf 3c 1f ba .k.....;Q`6nu.X.K]6)b..I..*$.<..
1140 96 54 de 9f f6 ca 9d 7b ab 45 6b a6 db de c0 52 e6 29 ee 2d e2 47 57 f9 1d 25 95 13 76 ff 00 f8 .T.....{.Ek....R.).-.GW..%..v...
1160 1e ea e7 60 f0 34 b1 e9 f0 69 b3 5d 24 96 f1 dd 24 ae d8 da ec 89 63 e4 7d df bb f7 bf 85 b7 2e ...`.4...i.]$...$.....c.}.......
1180 df bf bb ee d6 f5 ed 8d fe a1 a4 41 05 c1 b7 17 4b 73 04 ac cb bf 63 2c 53 ab 67 fd 8d ca bf 73 ...........A....Ks....c,S.g....s
11a0 ff 00 1e fe 2a 40 25 cf 88 ac 20 d7 2c b4 88 ae 2d e5 bd 9e 7f 2a 5b 74 9d 7c d8 93 ca 69 77 ec ....*@%.....,...-....*[t.|...iw.
11c0 ff 00 80 a7 fd f7 52 c7 ae e9 13 da fd aa 3d 5e c2 58 37 ba 79 ab 70 8c bb d1 37 bf cf fe e7 cf ......R.......=^.X7.y.p...7.....
11e0 5c fd ff 00 85 b5 4b e8 3f b2 c9 b1 8f 4f fb 45 ed c7 da 8c af e6 ff 00 a4 2c eb fe ab 6e df 95 \.....K.?....O.E.........,...n..
1200 a7 fe ff 00 f0 d3 ad 7c 2b 70 da 95 95 ed c5 bd ba ec b9 49 24 49 6f a6 bd 6d 89 1c ea 98 79 7a .......|+p.........I$Io..m....yz
1220 7c d2 7d dd bf 2e d2 db bf ba ec 06 d3 f8 86 c5 af be c7 04 f6 ed 2b 41 6f 3a b3 dc 22 2c b1 4b |.}...................+Ao:..",.K
1240 2e cd ca df c5 ff 00 d9 2f f7 aa 1d 37 c4 f6 37 da 52 ea b3 5c d8 5a d8 bc 0b 3e f7 ba 4d ca ac ......../...7..7.R..\.Z...>..M..
1260 cc 8b bf fb 9f 77 fe fa dc 9f c3 f3 e5 c5 e1 6b f8 a6 b8 65 96 16 13 dd 45 70 df 3b fc 8b 15 fb .....w.........k...e....Ep.;....
1280 5c 2f f0 ff 00 1a ca ff 00 f0 24 ff 00 6b e5 6d a7 85 f5 4b 17 d2 ee a3 36 52 dc 69 f6 76 51 2c \/........$..k.m...K....6R.i.vQ,
12a0 4f 2b aa c8 d1 45 3c 4f f3 ed f9 17 f7 fb be ef f0 d0 07 4b 26 b3 a5 c5 f6 5f 37 52 b2 5f b6 7f O+...E<O...........K&...._7R._..
12c0 c7 ae fb 85 fd ff 00 fb 9f df fb e9 55 ad fc 43 63 71 e6 b2 dc 5b c7 14 0d 74 b7 1e 65 c2 2b 44 ............U..Ccq...[...t..e.+D
12e0 f0 36 d6 f9 7f bb fc 7b bf da 5f ef 56 1e b9 e1 bd 63 53 d3 65 b7 4f b1 af 9f 04 a9 e4 c3 7b 2d .6.....{.._.V....cS.e.O.......{-
1300 ac 50 48 ee ec ed f2 a7 ef fe f2 6e df b7 ee 7f b4 d4 f9 fc 2f 7d e7 44 f1 4b 16 2d ae 2e 2e 22 .PH........n......../}.D.K.-..."
1320 2d 23 01 2b 3d e4 17 4a 8f f2 7c bf ea 99 7f 8b f8 5b fd 9a 2c 06 ef f6 f6 90 96 49 7a fa bd 87 -#.+=..J..|......[..,......Iz...
1340 d9 5d 19 d2 e3 ed 09 b5 d1 1f 63 fc ff 00 ef ba 27 fc 0e a1 d6 ce c9 b4 62 9c 9f ed 4b 55 ff 00 .]........c.....'.......b...KU..
1360 be db 63 7f e3 95 47 4f f0 f5 d0 f1 2a eb 77 a9 65 e6 bf 9e fe 52 3f 9b e4 3b 2c 11 26 d6 65 5f ..c...GO....*.w.e....R?..;,.&.e_
1380 e1 81 ff 00 b9 f7 b6 52 7d 86 5d 2f 41 f0 a5 8d c3 2b cb 6b 7b 61 03 b2 7d dd c8 e8 94 2d c0 db .......R}.]/A....+.k{a..}....-..
13a0 d4 f5 03 a7 db 2c e5 3c dd d7 50 41 f7 ff 00 e7 ac ab 16 ff 00 fc 7a a2 7d 5a 28 b5 3b db 69 ca .....,.<..PA..........z.}Z(.;.i.
13c0 45 15 9d ac 57 4f 3b bf cb b1 9a 5f fd 07 ca a8 fc 43 a5 ff 00 6c e9 5f 62 d9 13 23 dc 5b bc a9 E...WO;...._.....C...l._b..#.[..
13e0 2f dd 74 49 51 dd 3f ef 84 ac d7 f0 c9 b4 9f 55 6d 16 2b 3d 3a 2b a8 20 44 8a dd 3c ad ee 8f 2b /.tIQ.?........Um.+=:+..D..<...+
1400 bf dd 4f 93 7a b2 ae f4 f9 93 fe 03 48 0d a8 35 9d 2e eb ec 9e 46 a5 65 2f da b7 fd 9f 65 c2 3f ..O.z.......H..5.....F.e/....e.?
1420 9b b3 ef ec fe fe ca a7 a7 f8 9f 4a d5 35 69 ec ec ef 6c a7 48 a2 89 92 58 ae 15 f7 3b 79 bf 2f ...........J.5i...l.H...X...;y./
1440 fb e8 91 6f ae 7a 0f 06 5f ca fa 98 b8 9a 38 23 bf 82 ee df fe 3e 65 b9 78 bc d8 a0 44 f9 a5 55 ...o.z.._.....8#.....>e.x...D..U
1460 67 ff 00 50 ff 00 f8 ed 5a bc f0 f6 af ab 5f 4d 7f 72 2d ec 2e 02 c1 1c 46 d6 e9 dd d5 57 cf 49 g..P....Z....._M.r-.....F....W.I
1480 5b 77 94 9b 5b 64 ed b3 fd b5 5a 76 03 a4 93 58 d2 e2 b6 6b 99 75 1b 35 81 62 49 5a 56 b8 5d bb [w..[d....Zv...X...k.u.5.bIZV.].
14a0 5f ee 36 ef ee bd 27 f6 ce 97 ff 00 41 2b 2f f8 f7 fb 57 fc 7c 27 fc 7b ff 00 cf 5f f7 3f db ac _.6...'.....A+/...W.|'.{..._.?..
14c0 06 f0 bd e5 af da 9e ce 71 b1 a5 44 8a dc dd 3d be eb 54 dc eb 17 9a 8b ba 2d b2 ca db 76 ff 00 ........q..D...=..T......-...v..
14e0 04 4a 9f de aa 36 be 0c be 5d 3a f6 09 a4 89 5a 7f 29 91 16 ee 57 f9 d2 f2 5b 8d be 6e dd ff 00 .J...6...]:....Z.)...W...[..n...
1500 f2 d5 17 77 de fb cd 45 80 ea 2e 6e ad 75 1f 0e dd dc 5a dc 5b dd 5a cb 6f 2e d9 62 7d ea d5 3e ...w...E...n.u....Z.[.Z.o..b}..>
1520 93 23 49 a1 69 4d 23 33 33 d8 40 ee cd ff 00 5c 96 b2 ac f4 d7 d3 74 1d 4b cd 89 22 96 7d f2 b2 .#I.iM#33.@....\......t.K..".}..
1540 25 cc 93 ff 00 cb 25 5f f5 b2 fc cf f7 7f d8 ff 00 d9 9b 4f 48 ff 00 91 77 47 ff 00 b0 7d bf fe %.....%_...........OH...wG...}..
1560 8a 4a 00 a7 6d af fd a6 c3 c3 d7 5f 66 0b fd b1 b7 e5 dd fe af 7d bb cb ff 00 03 fb 9b 6a eb 6b .J..m......_f........}.......j.k
1580 3a 5c 76 d3 dc b6 a5 64 b0 5b 4b e5 4f 2b 5c 26 d8 9f fb 8c df c2 f5 8d a7 68 ba ac 0b a2 59 dc :\v....d.[K.O+\&.........h....Y.
15a0 a5 92 5a e9 07 f7 53 c5 33 33 4f b2 06 89 37 26 cf 93 ef 6f fb cd ff 00 b3 55 39 3c 29 7f 2d b2 ..Z...S.33O...7&...o.....U9<).-.
15c0 06 5b 44 6b 5b 80 f6 f0 db dc 4b 06 e4 54 95 36 79 ab f3 44 bf bd 67 58 be 7d 9f 32 ee da df 29 .[Dk[.....K..T.6y..D..gX.}.2...)
15e0 60 3a 78 35 2d 3e 7b 84 b7 82 f6 de 59 65 b7 fb 42 22 4a 8e cf 17 f7 ff 00 dc ff 00 6e b1 a2 f1 `:x5->{.....Ye..B"J.........n...
1600 0d fb ff 00 a5 49 a7 5b a6 9d f6 f6 b3 f3 56 ed 9a 5d de 7f d9 d5 f6 f9 5b 3e f7 fb 7f 76 9f a0 .....I.[......V..]......[>...v..
1620 68 52 68 d7 73 c8 7c b5 59 20 89 36 ac af 2e d6 f3 67 95 be 77 f9 9f fd 6f de fe 2f 9f e5 5a 93 hRh.s.|.Y..6.....g..w...o../..Z.
1640 46 f0 d6 9f a7 4b 2d ec 9a 7d 83 6a 4d 75 71 71 f6 a4 89 7c dd b2 ca cc bf 3f df fb 8d b2 80 2d F....K-..}.jMuqq...|.....?.....-
1660 ae bb a4 b2 da b2 ea d6 1b 6f 1f 65 ab 79 eb fb f7 df b3 e5 fe f5 66 8f 15 c4 e5 da 35 b7 64 5b .........o.e.y........f.....5.d[
1680 ff 00 b1 f9 5f 6b fd ee ff 00 3e 28 19 b6 ec ff 00 a6 bb bf dd d9 fd ff 00 92 81 f0 b6 a7 16 8c ...._k....>(....................
16a0 ba 6c 32 5a 3f da b4 78 34 bb a7 79 5d 3c 8d a8 e9 bd 3e 5f de ff 00 ad 6f 93 e5 fb bf ed 7c ab .l2Z?..x4..y]<....>_....o.....|.
16c0 3f 85 75 09 26 b2 74 96 0f dc 5d 5c 5c 3f ce ff 00 71 ef e2 b8 5f e0 fe e4 4f ff 00 02 a0 0e 92 ?.u.&.t...]\\?...q..._...O......
16e0 3d 67 4b 97 ed 5e 56 a5 64 df 63 ff 00 8f ad 97 0b fb 8f f7 ff 00 b9 f7 1e b4 34 f9 62 9d 12 e2 =gK..^V.d.c...............4.b...
1700 09 52 58 a5 89 9d 1d 1f 7a 3a 6d ae 1b 4d f0 75 cd 95 97 d9 9a 38 65 7b 6b 5f b2 c0 d3 5f 5c 4b .RX.....z:m..M.u.....8e{k_..._\K
1720 e6 fc c8 fb f6 ff 00 cb bf fa a5 fb bb b6 36 cf ee 7c dd 7e 87 6d 35 95 a4 51 4c 23 f3 bc a9 1a ..............6..|.~.m5..QL#....
1740 56 51 b5 5d df 73 1e df 7f bb 36 c5 dd f7 b6 af dd a0 02 ee ea 0b 0b 2b 8b db 96 db 6f 04 4f 2c VQ.].s....6............+....o.O,
1760 af b3 ee a2 56 16 9f ae dc 5a d8 dc ae b5 6e eb 7f 1b c4 df 67 5d 8c cc b3 bf ee 93 fb bf 7b 74 ....V....Z....n.....g]........{t
1780 5f f6 cb 73 6d dd 5b 5a 8d 8c 7a 8d 93 da ce cc 62 77 4d e8 a7 ef 22 be ed ad fe cb 7d d6 ff 00 _..sm.[Z..z.....bwM...".....}...
17a0 65 ab 39 fc 25 a4 a8 c5 a5 aa e9 ff 00 2f dd b2 44 89 59 d1 91 92 56 5d 9f 33 23 27 c9 bf fb cd e.9.%......../..D.Y...V].3#'....
17c0 fd ea 10 15 74 ef 12 07 d4 75 18 b5 48 a5 b1 55 9d fc bf b5 18 95 62 55 82 07 64 66 46 db bb e6 ....t....u..H..U......bU..dfF...
17e0 67 ff 00 75 1f fb b5 2b f8 b2 ca de f7 4d b5 b9 86 6b 79 af e2 8d d1 24 68 95 91 a4 1b 55 5a 2d g..u...+.....M...ky....$h....UZ-
1800 de 6e ed df 2f c8 bf fb 35 48 9e 16 b5 6b 6b 88 2e ee 66 bc 7b 8b a5 ba 96 4b 84 8b 73 32 a2 a6 .n../...5H...kk...f.{....K..s2..
1820 cf 95 15 76 b2 2e c6 fe fa b3 7f 7e a4 bb f0 f4 57 37 8f 3a de 5e c1 14 b3 c5 75 24 11 15 db 24 ...v.......~....W7.:.^....u$...$
1840 b1 6c da ed b9 77 7f cb 25 fb ac bf 76 80 2a 5a 78 ca c2 e6 d2 da e7 ec 97 b0 a5 dd ba cd 6a b3 .l...w..%...v.*Zx.............j.
1860 44 a8 d3 ee 75 4d ab f3 7f 7a 54 5f 9b 6a fc fb be ef cd 46 a1 e3 3b 2d 26 de df ed f6 d3 da cf D...uM...zT_.j.....F..;-&.......
1880 2b b2 7d 9e e1 e2 89 fe 5d bf 3e e6 75 89 fe f2 fd c6 fe 3f f6 5b 6d 86 f0 bd 93 da 69 f6 de 74 +.}.....].>.u......?.[m.....i..t
18a0 ff 00 f1 2f b5 fb 2d bb ef 5d e9 b5 e3 65 6f bb f7 95 a0 4f f6 7f d9 a7 36 81 b8 45 22 ea da 8a .../..-..]...eo....O....6..E"...
18c0 de c5 bf fd 3b 7c 4c ec 8f b3 7a ec 64 d8 ab f2 27 dd 4f e1 ff 00 69 b7 80 50 be f1 49 96 08 1b ....;|L...z.d...'.O...i..P..I...
18e0 48 82 e2 48 1a ea c9 1e f5 51 7c a4 59 65 89 b6 6c 77 df f3 45 2a 7d c4 fe 2f fb e2 df 8a 3f e3 H..H.....Q|.Ye..lw..E*}../....?.
1900 df 4d ff 00 b0 95 bf fe 87 4b 37 86 20 92 e1 1e 2d 43 50 8a df cf b7 9e 5b 74 75 65 96 58 b6 ed .M.......K7.....-CP.....[tue.X..
1920 66 77 47 7f f9 64 bf c7 fc 34 9e 28 ff 00 8f 7d 37 fe c2 56 ff 00 fa 1d 00 6e d1 45 14 80 28 a2 fwG..d...4.(...}7..V.....n.E..(.
1940 8a 00 2b e7 3d 43 fe 42 57 5f f5 d9 ff 00 99 af a3 2b e7 3d 43 fe 42 57 5f f5 d9 ff 00 99 aa 89 ..+.=C.BW_.......+.=C.BW_.......
1960 2c fa 4a e7 fd 6a 7f d7 24 ff 00 d0 2a 49 26 68 b6 44 8b 16 cd 8b ff 00 2c d7 fb b5 1d cf fa d4 ,.J..j..$...*I&h.D......,.......
1980 ff 00 ae 49 ff 00 a0 51 73 fe b5 3f eb 92 7f e8 15 23 0f b5 37 f7 22 ff 00 bf 49 47 da 9b fb 91 ...I...Qs..?.....#..7."...IG....
19a0 7f df a4 a8 68 a0 64 df 6a 6f ee 45 ff 00 7e 92 8f b5 37 f7 22 ff 00 bf 49 50 d1 40 13 7d a9 bf ....h.d.jo.E..~...7."...IP.@.}..
19c0 b9 17 fd fa 4a 8d 5c 24 b2 ca 91 42 af 2e dd ce 90 af cf b7 ee d3 68 a0 09 be d4 df dc 8b fe fd ....J.\$...B..........h.........
19e0 25 1f 6a 6f ee 45 ff 00 7e 92 a1 a2 80 26 fb 53 7f 72 2f fb f4 94 7d a9 bf b9 17 fd fa 4a 86 8a %.jo.E..~....&.S.r/...}......J..
1a00 00 9b ed 4d fd c8 bf ef d2 51 f6 a6 fe e4 5f f7 e9 2a 1a 28 02 6f b5 37 f7 22 ff 00 bf 49 47 da ...M.....Q...._..*.(.o.7."...IG.
1a20 9b fb 91 7f df a4 a8 68 a0 09 be d4 df dc 8b fe fd 25 1f 6a 6f ee 45 ff 00 7e 92 a1 a2 80 26 fb .......h.........%.jo.E..~....&.
1a40 53 7f 72 2f fb f4 94 7d a9 bf b9 17 fd fa 4a 86 8a 00 9b ed 4d fd c8 bf ef d2 54 6e e2 6d be 6c S.r/...}......J.....M.....Tn.m.l
1a60 50 36 d6 56 4d d0 2f c8 eb fc 74 da 28 02 6f b5 37 f7 22 ff 00 bf 49 47 da 9b fb 91 7f df a4 a8 P6.VM./...t.(.o.7."...IG........
1a80 68 a0 09 be d4 df dc 8b fe fd 25 1f 6a 6f ee 45 ff 00 7e 92 a1 a2 80 26 fb 53 7f 72 2f fb f4 94 h.........%.jo.E..~....&.S.r/...
1aa0 7d a9 bf b9 17 fd fa 4a 86 8a 00 7b 4e ee 8c ac 91 32 37 f0 79 49 48 b3 b4 51 2c 49 14 0a 8a bb }......J...{N....27.yIH..Q,I....
1ac0 55 12 25 f9 12 9b 45 17 02 6f b5 37 f7 22 ff 00 bf 49 47 da 9b fb 91 7f df a4 a8 68 a0 09 be d4 U.%...E..o.7."...IG........h....
1ae0 df dc 8b fe fd 25 1f 6a 6f ee 45 ff 00 7e 92 a1 a2 80 26 fb 53 7f 72 2f fb f4 94 7d a9 bf b9 17 .....%.jo.E..~....&.S.r/...}....
1b00 fd fa 4a 86 8a 00 9b ed 4d fd c8 bf ef d2 52 7d aa 5f fa 64 bf ee c4 b5 15 14 00 51 45 14 00 51 ..J.....M.....R}._.d.......QE..Q
1b20 45 14 00 51 45 14 00 54 17 36 b6 f7 5e 57 9f 16 ef 2a 54 95 3f df 4f b9 53 d1 40 13 7d a9 bf b9 E..QE..T.6..^W...*T.?.O.S.@.}...
1b40 17 fd fa 4a 3e d4 df dc 8b fe fd 25 43 45 00 4d f6 a6 fe e4 5f f7 e9 2a b5 f5 e4 b1 69 f7 12 c5 ...J>......%CE.M...._..*....i...
1b60 e5 23 a4 4c e9 fb a5 fe ed 3e aa ea 7f f2 0a bb ff 00 af 77 ff 00 d0 28 02 2d 06 57 97 c3 ba 6c .#.L.....>.........w...(.-.W...l
1b80 b2 bb b3 b5 ac 4e ee ff 00 c7 f2 57 81 6a 1f f2 12 ba ff 00 ae cf fc cd 7b d7 87 bf e4 58 d2 bf .....N.....W.j..........{....X..
1ba0 eb ca 2f fd 02 bc 17 50 ff 00 90 95 d7 fd 76 7f e6 6a a2 4b 3e 92 b9 ff 00 5a 9f f5 c9 3f f4 0a ../....P......v..j.K>....Z...?..
1bc0 2e 7f d6 a7 fd 72 4f fd 02 8b 9f f5 a9 ff 00 5c 93 ff 00 40 a2 e7 fd 6a 7f d7 24 ff 00 d0 2a 46 .....rO........\...@...j..$...*F
1be0 43 45 15 5e 09 6e 25 8a 29 56 ca 55 8a 54 47 47 79 62 fb 9f f7 dd 03 2c 51 5c 2d dc 57 f7 9a ce CE.^.n%.)V.U.TGGyb.....,Q\-.W...
1c00 bc 96 90 6a cf 75 1c e9 15 9d d4 37 fb 6d 6d 5f c8 89 d7 7c 5e 6f ce bb 9b 7b 7c af ff 00 03 ab ...j.u.....7.mm_...|^o...{|.....
1c20 97 3e 36 6b 79 35 02 34 6b 99 6d 6d 12 e4 ac a2 39 49 66 81 1b 76 e6 f2 bc a5 5d d1 32 ee 57 6f .>6ky5.4k.mm....9If..v....].2.Wo
1c40 e1 f9 3f ba ec 07 5d 45 72 30 ea fa ac 5a c6 a7 13 da c7 34 f2 5e c5 65 6b 17 da 9b ca 46 fb 2f ..?...]Er0...Z.....4.^.ek....F./
1c60 da 19 7e e7 dd fb ff 00 36 dd ef bf f8 76 52 bf 8c 2e cf da 12 0d 2e 26 92 0f 26 37 dd 75 b7 f7 ..~.....6....vR........&..&7.u..
1c80 ef 74 d6 bb 7e ef dd dd 13 be ef f7 3e 4a 2c 07 5b 45 73 71 78 a5 d8 ca b7 16 51 c0 de 55 c7 d9 .t..~.......>J,.[Esqx.....Q..U..
1ca0 c9 9d 9b 74 b1 4a b1 32 fd dd df eb 59 55 76 ab b3 7f 75 1b e5 aa b6 3e 2f bc d4 6e e2 b2 b6 d1 ...t.J.2....YUv...u....>/..n....
1cc0 bf d3 31 2f 9a b2 ca d1 45 16 cf 29 ff 00 8e 2d fb 36 dc 27 f0 7d ef f6 3e 6a 2c 07 5d 45 73 da ..1/....E..)...-.6.'.}..>j,.]Es.
1ce0 7f 88 67 d6 a4 59 f4 ed 38 49 a7 e6 2f 36 49 6e 36 ca be 6c 4b 2f dc fb ac 8a b2 a6 ef 9b fb df ..g..Y..8I../6In6..lK/..........
1d00 7b f8 db e1 ff 00 14 cb af 4b f2 69 97 29 6d 2d bf da 2d e6 2b 2a a3 a7 cb f2 b3 3a 22 ef f9 bf {........K.i.)m-..-.+*.....:"...
1d20 85 99 7e f7 cd fd f2 c0 74 74 54 5b ee bf e7 c9 ff 00 ef fc 1f fc 5d 1b ee bf e7 c9 ff 00 ef fc ..~.....ttT[..........].........
1d40 1f fc 5d 2b 01 2d 15 16 fb af f9 f2 7f fb ff 00 07 ff 00 17 46 fb af f9 f2 7f fb ff 00 07 ff 00 ..]+.-..............F...........
1d60 17 45 80 96 8a 8b 7d d7 fc f9 3f fd ff 00 83 ff 00 8b a3 7d d7 fc f9 3f fd ff 00 83 ff 00 8b a2 .E....}...?........}...?........
1d80 c0 4b 45 45 be eb fe 7c 9f fe ff 00 c1 ff 00 c5 d1 be eb fe 7c 9f fe ff 00 c1 ff 00 c5 d1 60 25 .KEE...|............|.........`%
1da0 a2 a2 df 75 ff 00 3e 4f ff 00 7f e0 ff 00 e2 e8 df 75 ff 00 3e 4f ff 00 7f e0 ff 00 e2 e8 b0 12 ...u..>O.........u..>O..........
1dc0 d1 51 6f ba ff 00 9f 27 ff 00 bf f0 7f f1 74 6f ba ff 00 9f 27 ff 00 bf f0 7f f1 74 58 09 68 a8 .Qo....'......to....'......tX.h.
1de0 b7 dd 7f cf 93 ff 00 df f8 3f f8 ba 37 dd 7f cf 93 ff 00 df f8 3f f8 ba 2c 04 b4 54 5b ee bf e7 .........?..7........?..,..T[...
1e00 c9 ff 00 ef fc 1f fc 5d 1b ee bf e7 c9 ff 00 ef fc 1f fc 5d 16 02 5a 2a 2d f7 5f f3 e4 ff 00 f7 .......]...........]..Z*-._.....
1e20 fe 0f fe 2e 8d f7 5f f3 e4 ff 00 f7 fe 0f fe 2e 8b 01 2d 15 16 fb af f9 f2 7f fb ff 00 07 ff 00 ......_...........-.............
1e40 17 46 fb af f9 f2 7f fb ff 00 07 ff 00 17 45 80 96 8a 8b 7d d7 fc f9 3f fd ff 00 83 ff 00 8b a3 .F............E....}...?........
1e60 7d d7 fc f9 3f fd ff 00 83 ff 00 8b a2 c0 4b 45 45 be eb fe 7c 9f fe ff 00 c1 ff 00 c5 d1 be eb }...?.........KEE...|...........
1e80 fe 7c 9f fe ff 00 c1 ff 00 c5 d1 60 25 a2 a2 df 75 ff 00 3e 4f ff 00 7f e0 ff 00 e2 e8 df 75 ff .|.........`%...u..>O.........u.
1ea0 00 3e 4f ff 00 7f e0 ff 00 e2 e8 b0 12 d1 51 6f ba ff 00 9f 27 ff 00 bf f0 7f f1 74 6f ba ff 00 .>O...........Qo....'......to...
1ec0 9f 27 ff 00 bf f0 7f f1 74 58 09 68 a8 b7 dd 7f cf 93 ff 00 df f8 3f f8 ba 37 dd 7f cf 93 ff 00 .'......tX.h..........?..7......
1ee0 df f8 3f f8 ba 2c 04 b4 54 5b ee bf e7 c9 ff 00 ef fc 1f fc 5d 1b ee bf e7 c9 ff 00 ef fc 1f fc ..?..,..T[..........]...........
1f00 5d 16 02 5a 2a 2d f7 5f f3 e4 ff 00 f7 fe 0f fe 2e 8d f7 5f f3 e4 ff 00 f7 fe 0f fe 2e 8b 01 2d ]..Z*-._..........._...........-
1f20 15 16 fb af f9 f2 7f fb ff 00 07 ff 00 17 46 fb af f9 f2 7f fb ff 00 07 ff 00 17 45 80 96 aa ea ..............F............E....
1f40 7f f2 0a bb ff 00 af 77 ff 00 d0 2a 78 9c 4d 12 cb b7 6e ed f9 4f f7 19 97 ff 00 65 a8 35 3f f9 .......w...*x.M...n..O.....e.5?.
1f60 05 5d ff 00 d7 bb ff 00 e8 14 01 5f c3 df f2 2c 69 5f f5 e5 17 fe 81 5e 0b a8 7f c8 4a eb fe bb .]........._...,i_.....^....J...
1f80 3f f3 35 ef 5e 1e ff 00 91 63 4a ff 00 af 28 bf f4 0a f0 5d 43 fe 42 57 5f f5 d9 ff 00 99 aa 89 ?.5.^....cJ...(....]C.BW_.......
1fa0 2c fa 4a e7 fd 6a 7f d7 24 ff 00 d0 28 b9 ff 00 5a 9f f5 c9 3f f4 0a 2e 7f d6 a7 fd 72 4f fd 02 ,.J..j..$...(...Z...?.......rO..
1fc0 8b 9f f5 a9 ff 00 5c 93 ff 00 40 a9 19 0d 45 6b ff 00 20 fb 2f fa f5 8b ff 00 45 25 4b 51 5a ff ......\...@...Ek..../.....E%KQZ.
1fe0 00 c8 3e cb fe bd 62 ff 00 d1 49 4f a0 c6 c1 6d 05 ac b7 12 c4 bb 5a ea 5f 36 5f 9f ef 36 d5 4f ..>...b...IO...m......Z._6_..6.O
2000 fd 05 56 b3 e6 f0 de 93 72 f7 0d 2d ab ba 5c 2b ab c4 67 6f 2b e7 5d ac c8 9b f6 23 36 f6 f9 97 ..V.....r..-..\+..go+.]....#6...
2020 e6 f9 db fb f5 72 ea e1 42 3f fa 64 56 88 af b1 a5 97 fb df 7b 6a ff 00 e3 bf e7 ee d5 f3 6d ff .....r..B?.dV.......{j........m.
2040 00 e8 67 b7 ff 00 c7 3f f8 8a 14 5b 13 64 93 e8 b6 17 5e 7e e8 9d 5e 7b 8f b4 33 45 2b 2b 79 bb ..g....?...[.d....^~..^{..3E++y.
2060 51 77 23 2f cc 9f 2a ec f9 29 8b a0 69 71 47 e5 ad af 19 88 b7 ef 1b e6 f2 a5 69 55 9f fd ad ec Qw#/..*..)..iqG...........iU....
2080 cf bb f8 bf 8a 93 cd b7 ff 00 a1 9e df ff 00 1c ff 00 e2 2b 37 57 d6 6e 74 9b 8b 08 a0 b9 7b 87 ...................+7W.nt.....{.
20a0 9e e2 05 7d e8 9e 57 93 2c aa 9d 91 5f 77 cd ff 00 ed 50 e2 d0 ae 69 b6 81 a5 cb 1f 96 d6 bc 66 ...}..W.,..._w....P...i........f
20c0 52 bf bc 6f 97 cd 95 65 66 4f f6 b7 aa be ef e1 fe 1a 34 ed 03 4e d2 ee 7e d3 6b 14 de 7f cd be R..o...efO........4..N..~.k.....
20e0 59 6e 25 95 9f 76 dd df 33 bf fd 32 8b fe f9 ad 4a 29 14 64 43 e1 bd 26 d9 ed9 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
/*  Shine is an MP3 encoder
 *  Copyright (C) 1999-2000  Gabriel Bouvigne
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details. */

#include "plugin.h"

PLUGIN_HEADER
PLUGIN_IRAM_DECLARE

static struct plugin_api* rb;

MEM_FUNCTION_WRAPPERS(rb);

#define SAMP_PER_FRAME       1152
#define SAMPL2                576
#define SBLIMIT                32
#define HTN                    16
#define memcpy         rb->memcpy
#define memset         rb->memset
#define putlong(c, s)  if(s+sz <= 32) { cc = (cc << s) | c;      sz+= s; } \
                       else           { putbits(cc, sz); cc = c; sz = s; }

enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian };

typedef unsigned  long uint32;
typedef unsigned short uint16;
typedef unsigned  char  uint8;


typedef struct {
    int   type; /* 0=(22.05,24,16kHz) 1=(44.1,48,32kHz) */
    int   mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono  */
    int   bitrate;
    int   padding;
    int   num_bands;
    long  bitr_id;
    int   smpl_id;
} mpeg_t;

/* Side information */
typedef struct {
    uint32 part2_3_length;
    int    count1;          /* number of 0-1-quadruples  */
    uint32 global_gain;
    uint32 table_select[4];
    uint32 region_0_1;
    uint32 address1;
    uint32 address2;
    uint32 address3;
    long   quantStep;
    long   additStep;
    long   max_val;
} side_info_t;

typedef struct {
    enum e_byte_order byte_order;
    side_info_t       cod_info[2][2];
    mpeg_t            mpg;
    long              frac_per_frame;
    long              byte_per_frame;
    long              slot_lag;
    int               sideinfo_len;
    int               mean_bits;
    int               ResvSize;
    int               channels;
    int               granules;
    int               resample;
    long              samplerate;
} config_t;

typedef struct {
    int     bitpos;     /* current bitpos for writing   */
    uint32  bbuf[263];
} BF_Data;

struct huffcodetab {
  int          len;     /* max. index                   */
  const uint8  *table;  /* pointer to array[len][len]   */
  const uint8  *hlen;   /* pointer to array[len][len]   */
};

struct huffcodebig {
  int          len;     /* max. index                   */
  int          linbits; /* number of linbits            */
  int          linmax;  /* max number stored in linbits */
};

#define shft4(x)    ((x +     8) >>  4)
#define shft9(x)    ((x +   256) >>  9)
#define shft13(x)   ((x +  4096) >> 13)
#define shft15(x)   ((x + 16384) >> 15)
#define shft16(x)   ((x + 32768) >> 16)
#define shft_n(x,n) ((x) >> n)
#define SQRT        724 /* sqrt(2) * 512 */

short     mfbuf       [2*(1152+512)]          IBSS_ATTR; /*  3328 Bytes */
int       sb_data     [2][2][18][SBLIMIT]     IBSS_ATTR; /* 13824 Bytes */
int       mdct_freq   [SAMPL2]                IBSS_ATTR; /*  9216 Bytes */
short     enc_data    [SAMPL2]                IBSS_ATTR; /*  4608 Bytes */
uint32    scalefac    [23]                    IBSS_ATTR; /*    92 Bytes */
BF_Data   CodedData                           IBSS_ATTR; /*  1056 Bytes */
int       ca          [8]                     IBSS_ATTR; /*    32 Bytes */
int       cs          [8]                     IBSS_ATTR; /*    32 Bytes */
int       cx          [9]                     IBSS_ATTR; /*    36 Bytes */
int       win         [18][4]                 IBSS_ATTR; /*   288 Bytes */
short     enwindow    [15*27+24]              IBSS_ATTR; /*   862 Bytes */
short     int2idx     [4096]                  IBSS_ATTR; /*  8192 Bytes */
uint8     ht_count    [2][2][16]              IBSS_ATTR; /*    64 Bytes */
uint32    tab01       [ 16]                   IBSS_ATTR; /*    64 Bytes */
uint32    tab23       [  9]                   IBSS_ATTR; /*    36 Bytes */
uint32    tab56       [ 16]                   IBSS_ATTR; /*    64 Bytes */
uint32    tab1315     [256]                   IBSS_ATTR; /*  1024 Bytes */
uint32    tab1624     [256]                   IBSS_ATTR; /*  1024 Bytes */
uint32    tab789      [ 36]                   IBSS_ATTR; /*   144 Bytes */
uint32    tabABC      [ 64]                   IBSS_ATTR; /*   256 Bytes */
uint8     t1HB        [  4]                   IBSS_ATTR;
uint8     t2HB        [  9]                   IBSS_ATTR;
uint8     t3HB        [  9]                   IBSS_ATTR;
uint8     t5HB        [ 16]                   IBSS_ATTR;
uint8     t6HB        [ 16]                   IBSS_ATTR;
uint8     t7HB        [ 36]                   IBSS_ATTR;
uint8     t8HB        [ 36]                   IBSS_ATTR;
uint8     t9HB        [ 36]                   IBSS_ATTR;
uint8     t10HB       [ 64]                   IBSS_ATTR;
uint8     t11HB       [ 64]                   IBSS_ATTR;
uint8     t12HB       [ 64]                   IBSS_ATTR;
uint8     t13HB       [256]                   IBSS_ATTR;
uint8     t15HB       [256]                   IBSS_ATTR;
uint16    t16HB       [256]                   IBSS_ATTR;
uint16    t24HB       [256]                   IBSS_ATTR;
uint8     t1l         [  8]                   IBSS_ATTR;
uint8     t2l         [  9]                   IBSS_ATTR;
uint8     t3l         [  9]                   IBSS_ATTR;
uint8     t5l         [ 16]                   IBSS_ATTR;
uint8     t6l         [ 16]                   IBSS_ATTR;
uint8     t7l         [ 36]                   IBSS_ATTR;
uint8     t8l         [ 36]                   IBSS_ATTR;
uint8     t9l         [ 36]                   IBSS_ATTR;
uint8     t10l        [ 64]                   IBSS_ATTR;
uint8     t11l        [ 64]                   IBSS_ATTR;
uint8     t12l        [ 64]                   IBSS_ATTR;
uint8     t13l        [256]                   IBSS_ATTR;
uint8     t15l        [256]                   IBSS_ATTR;
uint8     t16l        [256]                   IBSS_ATTR;
uint8     t24l        [256]                   IBSS_ATTR;
struct huffcodetab ht [HTN]                   IBSS_ATTR;

static const uint8 ht_count_const[2][2][16] =
{ { { 1,  5,  4,  5,  6,  5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 },     /* table0 */
    { 1,  5,  5,  7,  5,  8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } },   /* hleng0 */
  { {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },     /* table1 */
    { 4,  5,  5,  6,  5,  6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */

static const uint8  t1HB_const[4]  = {1,1,1,0}; 
static const uint8  t2HB_const[9]  = {1,2,1,3,1,1,3,2,0};
static const uint8  t3HB_const[9]  = {3,2,1,1,1,1,3,2,0};
static const uint8  t5HB_const[16] = {1,2,6,5,3,1,4,4,7,5,7,1,6,1,1,0};
static const uint8  t6HB_const[16] = {7,3,5,1,6,2,3,2,5,4,4,1,3,3,2,0};

static const uint8  t7HB_const[36] =
{  1, 2,10,19,16,10, 3, 3, 7,10, 5, 3,11, 4,13,17, 8, 4,
  12,11,18,15,11, 2, 7, 6, 9,14, 3, 1, 6, 4, 5, 3, 2, 0 };

static const uint8  t8HB_const[36] =
{  3, 4, 6,18,12, 5, 5, 1, 2,16, 9, 3, 7, 3, 5,14, 7, 3,
  19,17,15,13,10, 4,13, 5, 8,11, 5, 1,12, 4, 4, 1, 1, 0 };

static const uint8  t9HB_const[36] =
{  7, 5, 9,14,15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5,
  15, 6, 9,10, 5, 1,11, 7, 9, 6, 4, 1,14, 4, 6, 2, 6, 0 };

static const uint8 t10HB_const[64] =
{1,2,10,23,35,30,12,17,3,3,8,12,18,21,12,7,11,9,15,21,32,
 40,19,6,14,13,22,34,46,23,18,7,20,19,33,47,27,22,9,3,31,22,
 41,26,21,20,5,3,14,13,10,11,16,6,5,1,9,8,7,8,4,4,2,0 };

static const uint8 t11HB_const[64] =
{3,4,10,24,34,33,21,15,5,3,4,10,32,17,11,10,11,7,13,18,30,
 31,20,5,25,11,19,59,27,18,12,5,35,33,31,58,30,16,7,5,28,26,
 32,19,17,15,8,14,14,12,9,13,14,9,4,1,11,4,6,6,6,3,2,0 };

static const uint8 t12HB_const[64] =
{9,6,16,33,41,39,38,26,7,5,6,9,23,16,26,11,17,7,11,14,21,
30,10,7,17,10,15,12,18,28,14,5,32,13,22,19,18,16,9,5,40,17,
31,29,17,13,4,2,27,12,11,15,10,7,4,1,27,12,8,12,6,3,1,0 };

static const uint8 t13HB_const[256] =
{1,5,14,21,34,51,46,71,42,52,68,52,67,44,43,19,3,4,12,19,31,26,44,33,31,24,32,
 24,31,35,22,14,15,13,23,36,59,49,77,65,29,40,30,40,27,33,42,16,22,20,37,61,56,
 79,73,64,43,76,56,37,26,31,25,14,35,16,60,57,97,75,114,91,54,73,55,41,48,53,
 23,24,58,27,50,96,76,70,93,84,77,58,79,29,74,49,41,17,47,45,78,74,115,94,90,
 79,69,83,71,50,59,38,36,15,72,34,56,95,92,85,91,90,86,73,77,65,51,44,43,42,43,
 20,30,44,55,78,72,87,78,61,46,54,37,30,20,16,53,25,41,37,44,59,54,81,66,76,57,
 54,37,18,39,11,35,33,31,57,42,82,72,80,47,58,55,21,22,26,38,22,53,25,23,38,70,
 60,51,36,55,26,34,23,27,14,9,7,34,32,28,39,49,75,30,52,48,40,52,28,18,17,9,5,
 45,21,34,64,56,50,49,45,31,19,12,15,10,7,6,3,48,23,20,39,36,35,53,21,16,23,13,
 10,6,1,4,2,16,15,17,27,25,20,29,11,17,12,16,8,1,1,0,1 };

static const uint8 t15HB_const[256] =
{7,12,18,53,47,76,124,108,89,123,108,119,107,81,122,63,13,5,16,27,46,36,61,51,
 42,70,52,83,65,41,59,36,19,17,15,24,41,34,59,48,40,64,50,78,62,80,56,33,29,28,
 25,43,39,63,55,93,76,59,93,72,54,75,50,29,52,22,42,40,67,57,95,79,72,57,89,69,
 49,66,46,27,77,37,35,66,58,52,91,74,62,48,79,63,90,62,40,38,125,32,60,56,50,
 92,78,65,55,87,71,51,73,51,70,30,109,53,49,94,88,75,66,122,91,73,56,42,64,44,
 21,25,90,43,41,77,73,63,56,92,77,66,47,67,48,53,36,20,71,34,67,60,58,49,88,76,
 67,106,71,54,38,39,23,15,109,53,51,47,90,82,58,57,48,72,57,41,23,27,62,9,86,
 42,40,37,70,64,52,43,70,55,42,25,29,18,11,11,118,68,30,55,50,46,74,65,49,39,
 24,16,22,13,14,7,91,44,39,38,34,63,52,45,31,52,28,19,14,8,9,3,123,60,58,53,47,
 43,32,22,37,24,17,12,15,10,2,1,71,37,34,30,28,20,17,26,21,16,10,6,8,6,2,0};

static const uint16 t16HB_const[256] =
{1,5,14,44,74,63,110,93,172,149,138,242,225,195,376,17,3,4,12,20,35,62,53,47,
 83,75,68,119,201,107,207,9,15,13,23,38,67,58,103,90,161,72,127,117,110,209,
 206,16,45,21,39,69,64,114,99,87,158,140,252,212,199,387,365,26,75,36,68,65,
 115,101,179,164,155,264,246,226,395,382,362,9,66,30,59,56,102,185,173,265,142,
 253,232,400,388,378,445,16,111,54,52,100,184,178,160,133,257,244,228,217,385,
 366,715,10,98,48,91,88,165,157,148,261,248,407,397,372,380,889,884,8,85,84,81,
 159,156,143,260,249,427,401,392,383,727,713,708,7,154,76,73,141,131,256,245,
 426,406,394,384,735,359,710,352,11,139,129,67,125,247,233,229,219,393,743,737,
 720,885,882,439,4,243,120,118,115,227,223,396,746,742,736,721,712,706,223,436,
 6,202,224,222,218,216,389,386,381,364,888,443,707,440,437,1728,4,747,211,210,
 208,370,379,734,723,714,1735,883,877,876,3459,865,2,377,369,102,187,726,722,
 358,711,709,866,1734,871,3458,870,434,0,12,10,7,11,10,17,11,9,13,12,10,7,5,3,
 1,3};

static const uint16 t24HB_const[256] =
{15,13,46,80,146,262,248,434,426,669,653,649,621,517,1032,88,14,12,21,38,71,
 130,122,216,209,198,327,345,319,297,279,42,47,22,41,74,68,128,120,221,207,194,
 182,340,315,295,541,18,81,39,75,70,134,125,116,220,204,190,178,325,311,293,
 271,16,147,72,69,135,127,118,112,210,200,188,352,323,306,285,540,14,263,66,
 129,126,119,114,214,202,192,180,341,317,301,281,262,12,249,123,121,117,113,
 215,206,195,185,347,330,308,291,272,520,10,435,115,111,109,211,203,196,187,
 353,332,313,298,283,531,381,17,427,212,208,205,201,193,186,177,169,320,303,
 286,268,514,377,16,335,199,197,191,189,181,174,333,321,305,289,275,521,379,
 371,11,668,184,183,179,175,344,331,314,304,290,277,530,383,373,366,10,652,346,
 171,168,164,318,309,299,287,276,263,513,375,368,362,6,648,322,316,312,307,302,
 292,284,269,261,512,376,370,364,359,4,620,300,296,294,288,282,273,266,515,380,
 374,369,365,361,357,2,1033,280,278,274,267,264,259,382,378,372,367,363,360,
 358,356,0,43,20,19,17,15,13,11,9,7,6,4,7,5,3,1,3};

static const uint32 tab1315_const[256] =
{ 0x010003,0x050005,0x070006,0x080008,0x090008,0x0a0009,0x0a000a,0x0b000a,
  0x0a000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0d000c,0x0e000d,0x0e000e,
  0x040005,0x060005,0x080007,0x090008,0x0a0009,0x0a0009,0x0b000a,0x0b000a,
  0x0b000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0e000c,0x0e000d,0x0e000d,
  0x070006,0x080007,0x090007,0x0a0008,0x0b0009,0x0b0009,0x0c000a,0x0c000a,
  0x0b000a,0x0c000b,0x0c000b,0x0d000c,0x0d000c,0x0e000d,0x0f000d,0x0f000d,
  0x080007,0x090008,0x0a0008,0x0b0009,0x0b0009,0x0c000a,0x0c000a,0x0c000b,
  0x0c000b,0x0d000b,0x0d000c,0x0d000c,0x0d000c,0x0e000d,0x0f000d,0x0f000d,
  0x090008,0x090008,0x0b0009,0x0b0009,0x0c000a,0x0c000a,0x0d000b,0x0d000b,
  0x0c000b,0x0d000b,0x0d000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000d,
  0x0a0009,0x0a0009,0x0b0009,0x0c000a,0x0c000a,0x0c000a,0x0d000b,0x0d000b,
  0x0d000b,0x0d000b,0x0e000c,0x0d000c,0x0f000d,0x0f000d,0x10000d,0x10000e,
  0x0a000a,0x0b0009,0x0c000a,0x0c000a,0x0d000a,0x0d000b,0x0d000b,0x0d000b,
  0x0d000b,0x0e000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000e,0x10000e,
  0x0b000a,0x0b000a,0x0c000a,0x0d000b,0x0d000b,0x0d000b,0x0e000b,0x0e000c,
  0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x0f000d,0x10000d,0x12000d,0x12000e,
  0x0a000a,0x0a000a,0x0b000a,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0e000c,
  0x0e000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000e,0x11000e,0x11000e,
  0x0b000a,0x0b000a,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0d000c,0x0f000c,
  0x0e000c,0x0f000d,0x0f000d,0x10000d,0x10000d,0x10000e,0x12000e,0x11000e,
  0x0b000b,0x0c000b,0x0c000b,0x0d000b,0x0d000c,0x0e000c,0x0e000c,0x0f000c,
  0x0e000c,0x0f000d,0x10000d,0x0f000d,0x10000d,0x11000e,0x12000f,0x13000e,
  0x0c000b,0x0c000b,0x0c000b,0x0d000b,0x0e000c,0x0e000c,0x0e000c,0x0e000c,
  0x0f000d,0x0f000d,0x0f000d,0x10000d,0x11000e,0x11000e,0x11000e,0x12000f,
  0x0c000c,0x0d000c,0x0d000b,0x0e000c,0x0e000c,0x0f000c,0x0e000d,0x0f000d,
  0x10000d,0x10000d,0x11000d,0x11000d,0x11000e,0x12000e,0x12000f,0x12000f,
  0x0d000c,0x0d000c,0x0e000c,0x0f000c,0x0f000c,0x0f000d,0x10000d,0x10000d,
  0x10000d,0x10000e,0x10000e,0x11000e,0x12000e,0x11000e,0x12000f,0x12000f,
  0x0e000d,0x0e000d,0x0e000d,0x0f000d,0x0f000d,0x0f000d,0x11000d,0x10000d,
  0x10000e,0x13000e,0x11000e,0x11000e,0x11000f,0x13000f,0x12000e,0x12000f,
  0x0d000d,0x0e000d,0x0f000d,0x10000d,0x10000d,0x10000d,0x11000d,0x10000e,
  0x11000e,0x11000e,0x12000e,0x12000e,0x15000f,0x14000f,0x15000f,0x12000f };

static const uint32 tab01_const[16] =
{ 0x10004,0x50005,0x50005,0x70006,0x50005,0x80006,0x70006,0x90007,
  0x50005,0x70006,0x70006,0x90007,0x70006,0x90007,0x90007,0xa0008 };

static const uint32 tab23_const[ 9] =
{ 0x10002,0x40003,0x70007,0x40004,0x50004,0x70007,0x60006,0x70007,0x80008 };

static const uint32 tab56_const[16] =
{ 0x10003,0x40004,0x70006,0x80008,0x40004,0x50004,0x80006,0x90007,
  0x70005,0x80006,0x90007,0xa0008,0x80007,0x80007,0x90008,0xa0009 };

static const uint32 tab789_const[36] =
{0x00100803,0x00401004,0x00701c06,0x00902407,0x00902409,0x00a0280a,0x00401004,
 0x00601005,0x00801806,0x00902807,0x00902808,0x00a0280a,0x00701c05,0x00701806,
 0x00902007,0x00a02808,0x00a02809,0x00b02c0a,0x00802407,0x00902807,0x00a02808,
 0x00b02c09,0x00b02c09,0x00b0300a,0x00802408,0x00902408,0x00a02809,0x00b02c09,
 0x00b0300a,0x00c0300b,0x00902809,0x00a02809,0x00b02c0a,0x00c02c0a,0x00c0340b,
 0x00c0340b};

static const uint32 tabABC_const[64] =
{0x00100804,0x00401004,0x00701806,0x00902008,0x00a02409,0x00a0280a,0x00a0240a,
 0x00b0280a,0x00401004,0x00601405,0x00801806,0x00902007,0x00a02809,0x00b02809,
 0x00a0240a,0x00a0280a,0x00701806,0x00801c06,0x00902007,0x00a02408,0x00b02809,
 0x00c02c0a,0x00b02809,0x00b0280a,0x00802007,0x00902007,0x00a02408,0x00b02c08,
 0x00c02809,0x00c0300a,0x00b0280a,0x00c02c0a,0x00902408,0x00a02808,0x00b02809,
 0x00c02c09,0x00c02c0a,0x00c0300a,0x00c02c0a,0x00c0300b,0x00a02409,0x00b02809,
 0x00c02c0a,0x00c0300a,0x00d0300a,0x00d0340b,0x00c0300a,0x00d0340b,0x00902409,
 0x00a02409,0x00b02409,0x00c0280a,0x00c02c0a,0x00c0300b,0x00d0300b,0x00d0300c,
 0x00a0240a,0x00a0240a,0x00b0280a,0x00c02c0b,0x00c0300b,0x00d0300b,0x00d0300b,
 0x00d0300c};

static const uint32 tab1624_const[256] =
{0x00010004,0x00050005,0x00070007,0x00090008,0x000a0009,0x000a000a,0x000b000a,
 0x000b000b,0x000c000b,0x000c000c,0x000c000c,0x000d000c,0x000d000c,0x000d000c,
 0x000e000d,0x000a000a,0x00040005,0x00060006,0x00080007,0x00090008,0x000a0009,
 0x000b000a,0x000b000a,0x000b000b,0x000c000b,0x000c000b,0x000c000c,0x000d000c,
 0x000e000c,0x000d000c,0x000e000c,0x000a000a,0x00070007,0x00080007,0x00090008,
 0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000b,0x000d000b,0x000c000b,
 0x000d000b,0x000d000c,0x000d000c,0x000e000c,0x000e000d,0x000b0009,0x00090008,
 0x00090008,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a,0x000c000b,
 0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c,0x000f000c,
 0x000c0009,0x000a0009,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a,
 0x000d000a,0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c,
 0x000f000c,0x000f000d,0x000b0009,0x000a000a,0x000a0009,0x000b000a,0x000b000a,
 0x000c000a,0x000d000a,0x000d000b,0x000e000b,0x000d000b,0x000e000b,0x000e000c,
 0x000f000c,0x000f000c,0x000f000c,0x0010000c,0x000c0009,0x000b000a,0x000b000a,
 0x000b000a,0x000c000a,0x000d000a,0x000d000b,0x000d000b,0x000d000b,0x000e000b,
 0x000e000c,0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000d,0x000c0009,
 0x000b000b,0x000b000a,0x000c000a,0x000c000a,0x000d000b,0x000d000b,0x000d000b,
 0x000e000b,0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000d,
 0x0011000d,0x000c000a,0x000b000b,0x000c000b,0x000c000b,0x000d000b,0x000d000b,
 0x000d000b,0x000e000b,0x000e000b,0x000f000b,0x000f000c,0x000f000c,0x000f000c,
 0x0010000c,0x0010000d,0x0010000d,0x000c000a,0x000c000b,0x000c000b,0x000c000b,
 0x000d000b,0x000d000b,0x000e000b,0x000e000b,0x000f000c,0x000f000c,0x000f000c,
 0x000f000c,0x0010000c,0x000f000d,0x0010000d,0x000f000d,0x000d000a,0x000c000c,
 0x000d000b,0x000c000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000e000c,
 0x000f000c,0x0010000c,0x0010000c,0x0010000d,0x0011000d,0x0011000d,0x0010000d,
 0x000c000a,0x000d000c,0x000d000c,0x000d000b,0x000d000b,0x000e000b,0x000e000c,
 0x000f000c,0x0010000c,0x0010000c,0x0010000c,0x0010000c,0x0010000d,0x0010000d,
 0x000f000d,0x0010000d,0x000d000a,0x000d000c,0x000e000c,0x000e000c,0x000e000c,
 0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000c,0x0010000d,
 0x0010000d,0x0010000d,0x0010000d,0x0012000d,0x000d000a,0x000f000c,0x000e000c,
 0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000c,0x0010000c,0x0010000d,
 0x0012000d,0x0011000d,0x0011000d,0x0011000d,0x0013000d,0x0011000d,0x000d000a,
 0x000e000d,0x000f000c,0x000d000c,0x000e000c,0x0010000c,0x0010000c,0x000f000c,
 0x0010000d,0x0010000d,0x0011000d,0x0012000d,0x0011000d,0x0013000d,0x0011000d,
 0x0010000d,0x000d000a,0x000a0009,0x000a0009,0x000a0009,0x000b0009,0x000b0009,
 0x000c0009,0x000c0009,0x000c0009,0x000d0009,0x000d0009,0x000d0009,0x000d000a,
 0x000d000a,0x000d000a,0x000d000a,0x000a0006};

static const uint8 t1l_const[8]  = {1,3,2,3,1,4,3,5};
static const uint8 t2l_const[9]  = {1,3,6,3,3,5,5,5,6};
static const uint8 t3l_const[9]  = {2,2,6,3,2,5,5,5,6};
static const uint8 t5l_const[16] = {1,3,6,7,3,3,6,7,6,6,7,8,7,6,7,8};
static const uint8 t6l_const[16] = {3,3,5,7,3,2,4,5,4,4,5,6,6,5,6,7};

static const uint8 t7l_const[36] =
{1,3,6,8,8,9,3,4,6,7,7,8,6,5,7,8,8,9,7,7,8,9,9,9,7,7,8,9,9,10,8,8,9,10,10,10};

static const uint8 t8l_const[36] =
{2,3,6,8,8,9,3,2,4,8,8,8,6,4,6,8,8,9,8,8,8,9,9,10,8,7,8,9,10,10,9,8,9,9,11,11};

static const uint8 t9l_const[36] =
{3,3,5,6,8,9,3,3,4,5,6,8,4,4,5,6,7,8,6,5,6,7,7,8,7,6,7,7,8,9,8,7,8,8,9,9};

static const uint8 t10l_const[64] =
{1,3,6,8,9,9,9,10,3,4,6,7,8,9,8,8,6,6,7,8,9,10,9,9,7,7,8,9,10,10,9,10,8,8,9,10,
 10,10,10,10,9,9,10,10,11,11,10,11,8,8,9,10,10,10,11,11,9,8,9,10,10,11,11,11};

static const uint8 t11l_const[64] =
{2,3,5,7,8,9,8,9,3,3,4,6,8,8,7,8,5,5,6,7,8,9,8,8,7,6,7,9,8,10,8,9,8,8,8,9,9,10,
 9,10,8,8,9,10,10,11,10,11,8,7,7,8,9,10,10,10,8,7,8,9,10,10,10,10};

static const uint8 t12l_const[64] =
{4,3,5,7,8,9,9,9,3,3,4,5,7,7,8,8,5,4,5,6,7,8,7,8,6,5,6,6,7,8,8,8,7,6,7,7,8,
 8,8,9,8,7,8,8,8,9,8,9,8,7,7,8,8,9,9,10,9,8,8,9,9,9,9,10};

static const uint8 t13l_const[256] =
{1,4,6,7,8,9,9,10,9,10,11,11,12,12,13,13,3,4,6,7,8,8,9,9,9,9,10,10,11,12,12,12,
 6,6,7,8,9,9,10,10,9,10,10,11,11,12,13,13,7,7,8,9,9,10,10,10,10,11,11,11,11,12,
 13,13,8,7,9,9,10,10,11,11,10,11,11,12,12,13,13,14,9,8,9,10,10,10,11,11,11,11,
 12,11,13,13,14,14,9,9,10,10,11,11,11,11,11,12,12,12,13,13,14,14,10,9,10,11,11,
 11,12,12,12,12,13,13,13,14,16,16,9,8,9,10,10,11,11,12,12,12,12,13,13,14,15,15,
 10,9,10,10,11,11,11,13,12,13,13,14,14,14,16,15,10,10,10,11,11,12,12,13,12,13,
 14,13,14,15,16,17,11,10,10,11,12,12,12,12,13,13,13,14,15,15,15,16,11,11,11,12,
 12,13,12,13,14,14,15,15,15,16,16,16,12,11,12,13,13,13,14,14,14,14,14,15,16,15,
 16,16,13,12,12,13,13,13,15,14,14,17,15,15,15,17,16,16,12,12,13,14,14,14,15,14,
 15,15,16,16,19,18,19,16};

static const uint8 t15l_const[256] =
{3,4,5,7,7,8,9,9,9,10,10,11,11,11,12,13,4,3,5,6,7,7,8,8,8,9,9,10,10,10,11,11,5,
 5,5,6,7,7,8,8,8,9,9,10,10,11,11,11,6,6,6,7,7,8,8,9,9,9,10,10,10,11,11,11,7,6,
 7,7,8,8,9,9,9,9,10,10,10,11,11,11,8,7,7,8,8,8,9,9,9,9,10,10,11,11,11,12,9,7,8,
 8,8,9,9,9,9,10,10,10,11,11,12,12,9,8,8,9,9,9,9,10,10,10,10,10,11,11,11,12,9,8,
 8,9,9,9,9,10,10,10,10,11,11,12,12,12,9,8,9,9,9,9,10,10,10,11,11,11,11,12,12,
 12,10,9,9,9,10,10,10,10,10,11,11,11,11,12,13,12,10,9,9,9,10,10,10,10,11,11,11,
 11,12,12,12,13,11,10,9,10,10,10,11,11,11,11,11,11,12,12,13,13,11,10,10,10,10,
 11,11,11,11,12,12,12,12,12,13,13,12,11,11,11,11,11,11,11,12,12,12,12,13,13,12,
 13,12,11,11,11,11,11,11,12,12,12,12,12,13,13,13,13};

static const uint8 t16l_const[256] =
{1,4,6,8,9,9,10,10,11,11,11,12,12,12,13,9,3,4,6,7,8,9,9,9,10,10,10,11,12,11,12,
 8,6,6,7,8,9,9,10,10,11,10,11,11,11,12,12,9,8,7,8,9,9,10,10,10,11,11,12,12,12,
 13,13,10,9,8,9,9,10,10,11,11,11,12,12,12,13,13,13,9,9,8,9,9,10,11,11,12,11,12,
 12,13,13,13,14,10,10,9,9,10,11,11,11,11,12,12,12,12,13,13,14,10,10,9,10,10,11,
 11,11,12,12,13,13,13,13,15,15,10,10,10,10,11,11,11,12,12,13,13,13,13,14,14,14,
 10,11,10,10,11,11,12,12,13,13,13,13,14,13,14,13,11,11,11,10,11,12,12,12,12,13,
 14,14,14,15,15,14,10,12,11,11,11,12,12,13,14,14,14,14,14,14,13,14,11,12,12,12,
 12,12,13,13,13,13,15,14,14,14,14,16,11,14,12,12,12,13,13,14,14,14,16,15,15,15,
 17,15,11,13,13,11,12,14,14,13,14,14,15,16,15,17,15,14,11,9,8,8,9,9,10,10,10,
 11,11,11,11,11,11,11,8};

static const uint8 t24l_const[256] =
{4,4,6,7,8,9,9,10,10,11,11,11,11,11,12,9,4,4,5,6,7,8,8,9,9,9,10,10,10,10,10,8,
 6,5,6,7,7,8,8,9,9,9,9,10,10,10,11,7,7,6,7,7,8,8,8,9,9,9,9,10,10,10,10,7,8,7,7,
 8,8,8,8,9,9,9,10,10,10,10,11,7,9,7,8,8,8,8,9,9,9,9,10,10,10,10,10,7,9,8,8,8,8,
 9,9,9,9,10,10,10,10,10,11,7,10,8,8,8,9,9,9,9,10,10,10,10,10,11,11,8,10,9,9,9,
 9,9,9,9,9,10,10,10,10,11,11,8,10,9,9,9,9,9,9,10,10,10,10,10,11,11,11,8,11,9,9,
 9,9,10,10,10,10,10,10,11,11,11,11,8,11,10,9,9,9,10,10,10,10,10,10,11,11,11,11,
 8,11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,8,11,10,10,10,10,10,10,10,11,
 11,11,11,11,11,11,8,12,10,10,10,10,10,10,11,11,11,11,11,11,11,11,8,8,7,7,7,7,
 7,7,7,7,7,7,8,8,8,8,4};

static const struct huffcodetab ht_const[HTN] =
{ { 0, NULL, NULL}, /* Apparently not used */
  { 2, t1HB,  t1l},
  { 3, t2HB,  t2l},
  { 3, t3HB,  t3l},
  { 0, NULL, NULL}, /* Apparently not used */
  { 4, t5HB,  t5l},
  { 4, t6HB,  t6l},
  { 6, t7HB,  t7l},
  { 6, t8HB,  t8l},
  { 6, t9HB,  t9l},
  { 8, t10HB, t10l},
  { 8, t11HB, t11l},
  { 8, t12HB, t12l},
  {16, t13HB, t13l},
  { 0, NULL,  NULL}, /* Apparently not used */
  {16, t15HB, t15l} };

static const struct huffcodebig ht_big[HTN] =
{ { 16,  1,    1 },
  { 16,  2,    3 },
  { 16,  3,    7 },
  { 16,  4,   15 },
  { 16,  6,   63 },
  { 16,  8,  255 },
  { 16, 10, 1023 },
  { 16, 13, 8191 },
  { 16,  4,   15 },
  { 16,  5,   31 },
  { 16,  6,   63 },
  { 16,  7,  127 },
  { 16,  8,  255 },
  { 16,  9,  511 },
  { 16, 11, 2047 },
  { 16, 13, 8191 } };

static const struct
{
  uint32 region0_cnt;
  uint32 region1_cnt;
} subdv_table[23] =
{ {0, 0}, /*  0 bands */
  {0, 0}, /*  1 bands */
  {0, 0}, /*  2 bands */
  {0, 0}, /*  3 bands */
  {0, 0}, /*  4 bands */
  {0, 1}, /*  5 bands */
  {1, 1}, /*  6 bands */
  {1, 1}, /*  7 bands */
  {1, 2}, /*  8 bands */
  {2, 2}, /*  9 bands */
  {2, 3}, /* 10 bands */
  {2, 3}, /* 11 bands */
  {3, 4}, /* 12 bands */
  {3, 4}, /* 13 bands */
  {3, 4}, /* 14 bands */
  {4, 5}, /* 15 bands */
  {4, 5}, /* 16 bands */
  {4, 6}, /* 17 bands */
  {5, 6}, /* 18 bands */
  {5, 6}, /* 19 bands */
  {5, 7}, /* 20 bands */
  {6, 7}, /* 21 bands */
  {6, 7}, /* 22 bands */
};

static const uint32 sfBand[6][23] =
{
/* Table B.2.b: 22.05 kHz */
{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
/* Table B.2.c: 24 kHz */
{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
/* Table B.2.a: 16 kHz */
{0,6,12,18,24,30,36,44,45,66,80,96,116,140,168,200,238,248,336,396,464,522,576},
/* Table B.8.b: 44.1 kHz */
{0,4, 8,12,16,20,24,30,36,44,52,62, 74, 90,110,134,162,196,238,288,342,418,576},
/* Table B.8.c: 48 kHz */
{0,4, 8,12,16,20,24,30,36,42,50,60, 72, 88,106,128,156,190,230,276,330,384,576},
/* Table B.8.a: 32 kHz */
{0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} };


static const short int2idx_const[4096] = /*  int2idx[i] = sqrt(i*sqrt(i)); */
{
  0,  1,  2,  2,  3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  8,  8,  8,  9,  9,
  9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16,
 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21,
 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26,
 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31,
 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36,
 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 40,
 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45,
 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49,
 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53,
 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 57, 57, 57,
 57, 57, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61,
 61, 61, 61, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 65,
 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68,
 68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 72, 72, 72,
 72, 72, 72, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75,
 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 79, 79, 79,
 79, 79, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82,
 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 86, 86, 86,
 86, 86, 86, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89,
 89, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 93,
 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 96, 96, 96,
 96, 96, 96, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99,
 99, 99,100,100,100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,102,
103,103,103,103,103,103,104,104,104,104,104,104,104,105,105,105,105,105,105,106,
106,106,106,106,106,107,107,107,107,107,107,107,108,108,108,108,108,108,109,109,
109,109,109,109,110,110,110,110,110,110,110,111,111,111,111,111,111,112,112,112,
112,112,112,112,113,113,113,113,113,113,114,114,114,114,114,114,115,115,115,115,
115,115,115,116,116,116,116,116,116,117,117,117,117,117,117,117,118,118,118,118,
118,118,118,119,119,119,119,119,119,120,120,120,120,120,120,120,121,121,121,121,
121,121,122,122,122,122,122,122,122,123,123,123,123,123,123,123,124,124,124,124,
124,124,125,125,125,125,125,125,125,126,126,126,126,126,126,126,127,127,127,127,
127,127,128,128,128,128,128,128,128,129,129,129,129,129,129,129,130,130,130,130,
130,130,131,131,131,131,131,131,131,132,132,132,132,132,132,132,133,133,133,133,
133,133,133,134,134,134,134,134,134,134,135,135,135,135,135,135,136,136,136,136,
136,136,136,137,137,137,137,137,137,137,138,138,138,138,138,138,138,139,139,139,
139,139,139,139,140,140,140,140,140,140,140,141,141,141,141,141,141,141,142,142,
142,142,142,142,142,143,143,143,143,143,143,143,144,144,144,144,144,144,144,145,
145,145,145,145,145,145,146,146,146,146,146,146,146,147,147,147,147,147,147,147,
148,148,148,148,148,148,148,149,149,149,149,149,149,149,150,150,150,150,150,150,
150,151,151,151,151,151,151,151,152,152,152,152,152,152,152,153,153,153,153,153,
153,153,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,156,156,156,
156,156,156,156,157,157,157,157,157,157,157,158,158,158,158,158,158,158,159,159,
159,159,159,159,159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161,
162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,164,164,164,164,164,
164,164,165,165,165,165,165,165,165,166,166,166,166,166,166,166,167,167,167,167,
167,167,167,167,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,170,
170,170,170,170,170,170,171,171,171,171,171,171,171,172,172,172,172,172,172,172,
172,173,173,173,173,173,173,173,174,174,174,174,174,174,174,174,175,175,175,175,
175,175,175,176,176,176,176,176,176,176,176,177,177,177,177,177,177,177,178,178,
178,178,178,178,178,178,179,179,179,179,179,179,179,180,180,180,180,180,180,180,
180,181,181,181,181,181,181,181,182,182,182,182,182,182,182,182,183,183,183,183,
183,183,183,184,184,184,184,184,184,184,184,185,185,185,185,185,185,185,186,186,
186,186,186,186,186,186,187,187,187,187,187,187,187,187,188,188,188,188,188,188,
188,189,189,189,189,189,189,189,189,190,190,190,190,190,190,190,190,191,191,191,
191,191,191,191,192,192,192,192,192,192,192,192,193,193,193,193,193,193,193,193,
194,194,194,194,194,194,194,195,195,195,195,195,195,195,195,196,196,196,196,196,
196,196,196,197,197,197,197,197,197,197,197,198,198,198,198,198,198,198,199,199,
199,199,199,199,199,199,200,200,200,200,200,200,200,200,201,201,201,201,201,201,
201,201,202,202,202,202,202,202,202,202,203,203,203,203,203,203,203,204,204,204,
204,204,204,204,204,205,205,205,205,205,205,205,205,206,206,206,206,206,206,206,
206,207,207,207,207,207,207,207,207,208,208,208,208,208,208,208,208,209,209,209,
209,209,209,209,209,210,210,210,210,210,210,210,210,211,211,211,211,211,211,211,
211,212,212,212,212,212,212,212,212,213,213,213,213,213,213,213,213,214,214,214,
214,214,214,214,214,215,215,215,215,215,215,215,215,216,216,216,216,216,216,216,
216,217,217,217,217,217,217,217,217,218,218,218,218,218,218,218,218,219,219,219,
219,219,219,219,219,220,220,220,220,220,220,220,220,221,221,221,221,221,221,221,
221,222,222,222,222,222,222,222,222,223,223,223,223,223,223,223,223,224,224,224,
224,224,224,224,224,225,225,225,225,225,225,225,225,226,226,226,226,226,226,226,
226,227,227,227,227,227,227,227,227,228,228,228,228,228,228,228,228,229,229,229,
229,229,229,229,229,229,230,230,230,230,230,230,230,230,231,231,231,231,231,231,
231,231,232,232,232,232,232,232,232,232,233,233,233,233,233,233,233,233,234,234,
234,234,234,234,234,234,234,235,235,235,235,235,235,235,235,236,236,236,236,236,
236,236,236,237,237,237,237,237,237,237,237,238,238,238,238,238,238,238,238,238,
239,239,239,239,239,239,239,239,240,240,240,240,240,240,240,240,241,241,241,241,
241,241,241,241,242,242,242,242,242,242,242,242,242,243,243,243,243,243,243,243,
243,244,244,244,244,244,244,244,244,245,245,245,245,245,245,245,245,245,246,246,
246,246,246,246,246,246,247,247,247,247,247,247,247,247,248,248,248,248,248,248,
248,248,248,249,249,249,249,249,249,249,249,250,250,250,250,250,250,250,250,250,
251,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,253,253,253,253,
253,253,253,253,253,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255,
255,255,256,256,256,256,256,256,256,256,257,257,257,257,257,257,257,257,257,258,
258,258,258,258,258,258,258,259,259,259,259,259,259,259,259,259,260,260,260,260,
260,260,260,260,261,261,261,261,261,261,261,261,261,262,262,262,262,262,262,262,
262,263,263,263,263,263,263,263,263,263,264,264,264,264,264,264,264,264,265,265,
265,265,265,265,265,265,265,266,266,266,266,266,266,266,266,267,267,267,267,267,
267,267,267,267,268,268,268,268,268,268,268,268,268,269,269,269,269,269,269,269,
269,270,270,270,270,270,270,270,270,270,271,271,271,271,271,271,271,271,271,272,
272,272,272,272,272,272,272,273,273,273,273,273,273,273,273,273,274,274,274,274,
274,274,274,274,275,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,
276,276,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,279,
279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,281,281,281,
281,281,281,281,281,282,282,282,282,282,282,282,282,282,283,283,283,283,283,283,
283,283,283,284,284,284,284,284,284,284,284,284,285,285,285,285,285,285,285,285,
286,286,286,286,286,286,286,286,286,287,287,287,287,287,287,287,287,287,288,288,
288,288,288,288,288,288,288,289,289,289,289,289,289,289,289,289,290,290,290,290,
290,290,290,290,291,291,291,291,291,291,291,291,291,292,292,292,292,292,292,292,
292,292,293,293,293,293,293,293,293,293,293,294,294,294,294,294,294,294,294,294,
295,295,295,295,295,295,295,295,295,296,296,296,296,296,296,296,296,296,297,297,
297,297,297,297,297,297,297,298,298,298,298,298,298,298,298,299,299,299,299,299,
299,299,299,299,300,300,300,300,300,300,300,300,300,301,301,301,301,301,301,301,
301,301,302,302,302,302,302,302,302,302,302,303,303,303,303,303,303,303,303,303,
304,304,304,304,304,304,304,304,304,305,305,305,305,305,305,305,305,305,306,306,
306,306,306,306,306,306,306,307,307,307,307,307,307,307,307,307,308,308,308,308,
308,308,308,308,308,309,309,309,309,309,309,309,309,309,310,310,310,310,310,310,
310,310,310,311,311,311,311,311,311,311,311,311,312,312,312,312,312,312,312,312,
312,313,313,313,313,313,313,313,313,313,314,314,314,314,314,314,314,314,314,315,
315,315,315,315,315,315,315,315,316,316,316,316,316,316,316,316,316,317,317,317,
317,317,317,317,317,317,318,318,318,318,318,318,318,318,318,318,319,319,319,319,
319,319,319,319,319,320,320,320,320,320,320,320,320,320,321,321,321,321,321,321,
321,321,321,322,322,322,322,322,322,322,322,322,323,323,323,323,323,323,323,323,
323,324,324,324,324,324,324,324,324,324,325,325,325,325,325,325,325,325,325,325,
326,326,326,326,326,326,326,326,326,327,327,327,327,327,327,327,327,327,328,328,
328,328,328,328,328,328,328,329,329,329,329,329,329,329,329,329,330,330,330,330,
330,330,330,330,330,330,331,331,331,331,331,331,331,331,331,332,332,332,332,332,
332,332,332,332,333,333,333,333,333,333,333,333,333,334,334,334,334,334,334,334,
334,334,335,335,335,335,335,335,335,335,335,335,336,336,336,336,336,336,336,336,
336,337,337,337,337,337,337,337,337,337,338,338,338,338,338,338,338,338,338,338,
339,339,339,339,339,339,339,339,339,340,340,340,340,340,340,340,340,340,341,341,
341,341,341,341,341,341,341,341,342,342,342,342,342,342,342,342,342,343,343,343,
343,343,343,343,343,343,344,344,344,344,344,344,344,344,344,344,345,345,345,345,
345,345,345,345,345,346,346,346,346,346,346,346,346,346,347,347,347,347,347,347,
347,347,347,347,348,348,348,348,348,348,348,348,348,349,349,349,349,349,349,349,
349,349,350,350,350,350,350,350,350,350,350,350,351,351,351,351,351,351,351,351,
351,352,352,352,352,352,352,352,352,352,352,353,353,353,353,353,353,353,353,353,
354,354,354,354,354,354,354,354,354,355,355,355,355,355,355,355,355,355,355,356,
356,356,356,356,356,356,356,356,357,357,357,357,357,357,357,357,357,357,358,358,
358,358,358,358,358,358,358,359,359,359,359,359,359,359,359,359,359,360,360,360,
360,360,360,360,360,360,361,361,361,361,361,361,361,361,361,361,362,362,362,362,
362,362,362,362,362,363,363,363,363,363,363,363,363,363,363,364,364,364,364,364,
364,364,364,364,365,365,365,365,365,365,365,365,365,365,366,366,366,366,366,366,
366,366,366,367,367,367,367,367,367,367,367,367,367,368,368,368,368,368,368,368,
368,368,369,369,369,369,369,369,369,369,369,369,370,370,370,370,370,370,370,370,
370,370,371,371,371,371,371,371,371,371,371,372,372,372,372,372,372,372,372,372,
372,373,373,373,373,373,373,373,373,373,374,374,374,374,374,374,374,374,374,374,
375,375,375,375,375,375,375,375,375,375,376,376,376,376,376,376,376,376,376,377,
377,377,377,377,377,377,377,377,377,378,378,378,378,378,378,378,378,378,379,379,
379,379,379,379,379,379,379,379,380,380,380,380,380,380,380,380,380,380,381,381,
381,381,381,381,381,381,381,382,382,382,382,382,382,382,382,382,382,383,383,383,
383,383,383,383,383,383,383,384,384,384,384,384,384,384,384,384,385,385,385,385,
385,385,385,385,385,385,386,386,386,386,386,386,386,386,386,386,387,387,387,387,
387,387,387,387,387,387,388,388,388,388,388,388,388,388,388,389,389,389,389,389,
389,389,389,389,389,390,390,390,390,390,390,390,390,390,390,391,391,391,391,391,
391,391,391,391,391,392,392,392,392,392,392,392,392,392,393,393,393,393,393,393,
393,393,393,393,394,394,394,394,394,394,394,394,394,394,395,395,395,395,395,395,
395,395,395,395,396,396,396,396,396,396,396,396,396,397,397,397,397,397,397,397,
397,397,397,398,398,398,398,398,398,398,398,398,398,399,399,399,399,399,399,399,
399,399,399,400,400,400,400,400,400,400,400,400,400,401,401,401,401,401,401,401,
401,401,402,402,402,402,402,402,402,402,402,402,403,403,403,403,403,403,403,403,
403,403,404,404,404,404,404,404,404,404,404,404,405,405,405,405,405,405,405,405,
405,405,406,406,406,406,406,406,406,406,406,406,407,407,407,407,407,407,407,407,
407,407,408,408,408,408,408,408,408,408,408,408,409,409,409,409,409,409,409,409,
409,410,410,410,410,410,410,410,410,410,410,411,411,411,411,411,411,411,411,411,
411,412,412,412,412,412,412,412,412,412,412,413,413,413,413,413,413,413,413,413,
413,414,414,414,414,414,414,414,414,414,414,415,415,415,415,415,415,415,415,415,
415,416,416,416,416,416,416,416,416,416,416,417,417,417,417,417,417,417,417,417,
417,418,418,418,418,418,418,418,418,418,418,419,419,419,419,419,419,419,419,419,
419,420,420,420,420,420,420,420,420,420,420,421,421,421,421,421,421,421,421,421,
421,422,422,422,422,422,422,422,422,422,422,423,423,423,423,423,423,423,423,423,
423,424,424,424,424,424,424,424,424,424,424,425,425,425,425,425,425,425,425,425,
425,426,426,426,426,426,426,426,426,426,426,427,427,427,427,427,427,427,427,427,
427,428,428,428,428,428,428,428,428,428,428,429,429,429,429,429,429,429,429,429,
429,430,430,430,430,430,430,430,430,430,430,431,431,431,431,431,431,431,431,431,
431,432,432,432,432,432,432,432,432,432,432,433,433,433,433,433,433,433,433,433,
433,434,434,434,434,434,434,434,434,434,434,435,435,435,435,435,435,435,435,435,
435,435,436,436,436,436,436,436,436,436,436,436,437,437,437,437,437,437,437,437,
437,437,438,438,438,438,438,438,438,438,438,438,439,439,439,439,439,439,439,439,
439,439,440,440,440,440,440,440,440,440,440,440,441,441,441,441,441,441,441,441,
441,441,442,442,442,442,442,442,442,442,442,442,443,443,443,443,443,443,443,443,
443,443,443,444,444,444,444,444,444,444,444,444,444,445,445,445,445,445,445,445,
445,445,445,446,446,446,446,446,446,446,446,446,446,447,447,447,447,447,447,447,
447,447,447,448,448,448,448,448,448,448,448,448,448,448,449,449,449,449,449,449,
449,449,449,449,450,450,450,450,450,450,450,450,450,450,451,451,451,451,451,451,
451,451,451,451,452,452,452,452,452,452,452,452,452,452,453,453,453,453,453,453,
453,453,453,453,453,454,454,454,454,454,454,454,454,454,454,455,455,455,455,455,
455,455,455,455,455,456,456,456,456,456,456,456,456,456,456,457,457,457,457,457,
457,457,457,457,457,457,458,458,458,458,458,458,458,458,458,458,459,459,459,459,
459,459,459,459,459,459,460,460,460,460,460,460,460,460,460,460,460,461,461,461,
461,461,461,461,461,461,461,462,462,462,462,462,462,462,462,462,462,463,463,463,
463,463,463,463,463,463,463,463,464,464,464,464,464,464,464,464,464,464,465,465,
465,465,465,465,465,465,465,465,466,466,466,466,466,466,466,466,466,466,466,467,
467,467,467,467,467,467,467,467,467,468,468,468,468,468,468,468,468,468,468,469,
469,469,469,469,469,469,469,469,469,469,470,470,470,470,470,470,470,470,470,470,
471,471,471,471,471,471,471,471,471,471,472,472,472,472,472,472,472,472,472,472,
472,473,473,473,473,473,473,473,473,473,473,474,474,474,474,474,474,474,474,474,
474,475,475,475,475,475,475,475,475,475,475,475,476,476,476,476,476,476,476,476,
476,476,477,477,477,477,477,477,477,477,477,477,477,478,478,478,478,478,478,478,
478,478,478,479,479,479,479,479,479,479,479,479,479,479,480,480,480,480,480,480,
480,480,480,480,481,481,481,481,481,481,481,481,481,481,482,482,482,482,482,482,
482,482,482,482,482,483,483,483,483,483,483,483,483,483,483,484,484,484,484,484,
484,484,484,484,484,484,485,485,485,485,485,485,485,485,485,485,486,486,486,486,
486,486,486,486,486,486,486,487,487,487,487,487,487,487,487,487,487,488,488,488,
488,488,488,488,488,488,488,488,489,489,489,489,489,489,489,489,489,489,490,490,
490,490,490,490,490,490,490,490,490,491,491,491,491,491,491,491,491,491,491,492,
492,492,492,492,492,492,492,492,492,492,493,493,493,493,493,493,493,493,493,493,
494,494,494,494,494,494,494,494,494,494,494,495,495,495,495,495,495,495,495,495,
495,496,496,496,496,496,496,496,496,496,496,496,497,497,497,497,497,497,497,497,
497,497,497,498,498,498,498,498,498,498,498,498,498,499,499,499,499,499,499,499,
499,499,499,499,500,500,500,500,500,500,500,500,500,500,501,501,501,501,501,501,
501,501,501,501,501,502,502,502,502,502,502,502,502,502,502,503,503,503,503,503,
503,503,503,503,503,503,504,504,504,504,504,504,504,504,504,504,504,505,505,505,
505,505,505,505,505,505,505,506,506,506,506,506,506,506,506,506,506,506,507,507,
507,507,507,507,507,507,507,507,507,508,508,508,508,508,508,508,508,508,508,509,
509,509,509,509,509,509,509,509,509,509,510,510,510,510,510,510,510,510,510,510,
510,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512 };

static const int order[32] = 
{ 0, 1, 16, 17, 8, 9, 24, 25, 4, 5, 20, 21, 12, 13, 28, 29,
  2, 3, 18, 19,10,11, 26, 27, 6, 7, 22, 23, 14, 15, 30, 31 };

static const int bitr_index[2][15] =
{ {0, 8,16,24,32,40,48,56, 64, 80, 96,112,128,144,160},
  {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320} };

static const int num_bands[3][15]  =
{ {0,10,10,10,10,12,14,16, 20, 22, 24, 26, 28, 30, 32},
  {0,10,10,10,10,10,12,14, 18, 24, 26, 28, 30, 32, 32},
  {0,10,12,14,18,24,26,28, 30, 32, 32, 32, 32, 32, 32} };

static const int cx_const[9] =
{ 16135, 10531,  5604, 15396, -2845,-12551, 14189,  8192, 16384 };

static const int ca_const[8] =
{-16859,-15458,-10269, -5961, -3099, -1342,  -465,  -121 };

static const int cs_const[8] =
{ 28098, 28893, 31117, 32221, 32621, 32740, 32765, 32768 };

static const short enwindow_const[15*27+24] = 
{ 0,   65,  593,  1766, 22228, 2115, 611, 62,
  8,  119, 1419, 10564,-11659,-1635,-154, -9,
 -8, -119,-1419,-10564, 11659, 1635, 154,  9, 464,  100,  91,
  0,   69,  604,  1635, 23148, 2363, 643, 62,
  7,  107, 1368, 10449,-12733,-1818,-180,-11,
 -7, -107,-1368,-10449, 12733, 1818, 180, 11, 420,  200, 164,
  0,   72,  608,  1465, 23979, 2600, 671, 63,
  7,   94, 1305, 10265,-13818,-2004,-207,-12,
 -7,  -94,-1305,-10265, 13818, 2004, 207, 12, 380,  297, 220,
  0,   76,  606,  1256, 24718, 2825, 693, 63,
  6,   81, 1232, 10016,-14908,-2192,-236,-14,
 -6,  -81,-1232,-10016, 14908, 2192, 236, 14, 342,  392, 262,
  0,   78,  597,  1007, 25359, 3033, 712, 63,
  6,   68, 1150,  9706,-15995,-2380,-267,-15,
 -6,  -68,-1150, -9706, 15995, 2380, 267, 15, 307,  483, 289,
  0,   80,  580,   719, 25901, 3224, 726, 62,
  6,   54, 1060,  9343,-17072,-2565,-299,-17,
 -6,  -54,-1060, -9343, 17072, 2565, 299, 17, 274,  569, 304,
 -1,   82,  555,   391, 26339, 3395, 735, 61,
  5,   40,  963,  8930,-18131,-2747,-332,-19,
 -5,  -40, -963, -8930, 18131, 2747, 332, 19, 242,  650, 307,
 -1,   83,  523,    26, 26672, 3545, 740, 60,
  5,   27,  861,  8474,-19164,-2923,-366,-21,
 -5,  -27, -861, -8474, 19164, 2923, 366, 21, 212,  724, 300,
 -1,   83,  482,  -376, 26900, 3672, 739, 58,
  4,   14,  756,  7981,-20163,-3092,-401,-24,
 -4,  -14, -756, -7981, 20163, 3092, 401, 24, 183,  792, 283,
 -1,   82,  433,  -812, 27022, 3776, 735, 56,
  4,    1,  648,  7456,-21122,-3250,-435,-26,
 -4,   -1, -648, -7456, 21122, 3250, 435, 26, 155,  851, 258,
 -1,   81,  376, -1281, 27038, 3855, 726, 54,
  3,  -11,  539,  6907,-22032,-3397,-470,-28,
 -3,   11, -539, -6907, 22032, 3397, 470, 28, 128,  903, 226,
 -1,   78,  312, -1778, 26951, 3910, 713, 52,
  3,  -22,  430,  6338,-22887,-3530,-503,-31,
 -3,   22, -430, -6338, 22887, 3530, 503, 31, 102,  946, 188,
 -2,   75,  239, -2302, 26761, 3941, 696, 49,
  3,  -33,  322,  5757,-23678,-3648,-537,-34,
 -3,   33, -322, -5757, 23678, 3648, 537, 34,  76,  980, 145,
 -2,   70,  160, -2848, 26472, 3948, 676, 47,
  3,  -42,  217,  5167,-24399,-3749,-568,-36,
 -3,   42, -217, -5167, 24399, 3749, 568, 36,  50, 1004,  99,
 -2,   65,   74, -3412, 26087, 3931, 653, 44,
  2,  -51,  115,  4577,-25045,-3830,-599,-39,
 -2,   51, -115, -4577, 25045, 3830, 599, 39,  25, 1019,  50,

 25610,3891,627,42,-3990,-18,58,-2,
 21226,-21226,10604,-10604,1860,-1860,1458,-1458,576,-576,130,-130,60,-60,8,-8
};

static const int win_const[18][4] = {
  { -3072, -134, -146, 3352 },
  { -2747, -362, -471, 3579 },
  { -2387, -529, -831, 3747 },
  { -2004, -632,-1214, 3850 },
  { -1609, -666,-1609, 3884 },
  { -1214, -632,-2004, 3850 },
  {  -831, -529,-2387, 3747 },
  {  -471, -362,-2747, 3579 },
  {  -146, -134,-3072, 3352 },
  {   134,-3072,-3352, -146 },
  {   362,-2747,-3579, -471 },
  {   529,-2387,-3747, -831 },
  {   632,-2004,-3850,-1214 },
  {   666,-1609,-3884,-1609 },
  {   632,-1214,-3850,-2004 },
  {   529, -831,-3747,-2387 },
  {   362, -471,-3579,-2747 },
  {   134, -146,-3352,-3072 } };


static char*       wav_filename;
static int         mp3file, wavfile, wav_size, frames;
static uint32      enc_buffer[16384]; /* storage for 65536 Bytes */
static int         enc_chunk = 0;     /* encode chunk counter    */
static int         enc_size;
static config_t    cfg;

/* forward declarations */
int  HuffmanCode( short *ix, int *xr, uint32 begin, uint32 end, int table);
int  HuffmanCod1( short *ix, int *xr, uint32 begin, uint32 end, int table);
void putbits(uint32 val, uint32 nbit);
int  find_best_2( short *ix, uint32 start, uint32 end, const uint32 *table,
                  uint32 len, int *bits);
int  find_best_3( short *ix, uint32 start, uint32 end, const uint32 *table,
                  uint32 len, int *bits);
int  count_bit1 ( short *ix, uint32 start, uint32 end, int *bits );
int  count_bigv ( short *ix, uint32 start, uint32 end, int table0, int table1,
                  int *bits);


bool checkString(int fd, char *string)
{
  char temp[4];

  rb->read(fd, temp, 4);

  return (*(long*)temp == *(long*)string) ? 1 : 0;
}

int Read16BitsLowHigh(int fd)
{
  char first, second;

  rb->read(fd, &first,  1);
  rb->read(fd, &second, 1);

  return ((int)second << 8) | (first & 0xff);
}


int Read32BitsLowHigh(int fd)
{
  int first  = 0xffff & Read16BitsLowHigh(fd);
  int second = 0xffff & Read16BitsLowHigh(fd);

  return (second << 16) + first;
}

int wave_open(void)
{
  unsigned short  wFormatTag;
  unsigned long   dAvgBytesPerSec;
  unsigned short  wBlockAlign;
  unsigned short  bits_per_samp;
  long            header_size;

  if((wavfile = rb->open(wav_filename, O_RDONLY)) < 0)
    return -1;
  
  if(!checkString(wavfile,"RIFF")) return -2;
  Read32BitsLowHigh(wavfile); /* complete wave chunk size */
  if(!checkString(wavfile,"WAVE")) return -3;
  if(!checkString(wavfile,"fmt ")) return -4;
  
  header_size = Read32BitsLowHigh(wavfile); /* chunk size */
  wFormatTag  = Read16BitsLowHigh(wavfile);
  
  cfg.channels    = Read16BitsLowHigh(wavfile);
  cfg.samplerate  = Read32BitsLowHigh(wavfile);
  dAvgBytesPerSec = Read32BitsLowHigh(wavfile);
  wBlockAlign     = Read16BitsLowHigh(wavfile);
  bits_per_samp   = Read16BitsLowHigh(wavfile);
  
  if(wFormatTag != 0x0001)         return -5;
  if(bits_per_samp != 16)          return -6;
  if(cfg.channels > 2)             return -7;
  if(!checkString(wavfile,"data")) return -8;
  
  header_size = 0x28;
  wav_size = rb->filesize(wavfile);
  rb->lseek(wavfile, header_size, SEEK_SET);
  
  return 0;
}

int read_samples(uint32 *buffer, int num_samples)
{
  int s, samples = rb->read(wavfile, buffer, 4 * num_samples) / 4;
  /* Pad last sample with zeros */
  for(s=samples; s<num_samples; s++)
    buffer[s] = 0;

  return samples;
}

inline uint32 myswap32(uint32 val)
{
  const uint8* v = (const uint8*)&val;

  return ((uint32)v[0]<<24) | ((uint32)v[1]<<16) | ((uint32)v[2]<<8) | v[3];
}

void encodeSideInfo( side_info_t si[2][2] )
{
  int gr, ch, header;
  uint32  cc=0, sz=0;
  
  header  = 0xfff00000;
  header |= cfg.mpg.type    << 19; /* mp3 type: 1  */
  header |= 1               << 17; /* mp3 layer: 1 */
  header |= 1               << 16; /* mp3 crc: 0   */
  header |= cfg.mpg.bitr_id << 12;
  header |= cfg.mpg.smpl_id << 10;
  header |= cfg.mpg.padding <<  9;
  header |= cfg.mpg.mode    <<  6;
  header |= 1               <<  2; /* mp3 original: 1 */
  putbits( header, 32 );

  if(cfg.mpg.type)
  { /* MPEG1 */
    if(cfg.channels == 2)  { putlong( 0, 20); }
    else                   { putlong( 0, 18); }

    for(gr=0; gr<cfg.granules; gr++)
      for(ch=0; ch<cfg.channels; ch++)
      {
        side_info_t *gi = &si[gr][ch];

        putlong( gi->part2_3_length,  12 );
        putlong( gi->address3>>1,      9 );
        putlong( gi->global_gain,      8 );
        putlong( gi->table_select[0], 10 );
        putlong( gi->table_select[1],  5 );
        putlong( gi->table_select[2],  5 );
        putlong( gi->region_0_1,       7 );
        putlong( gi->table_select[3],  3 );
      }
  }
  else
  { /* MPEG2 */
    if(cfg.channels == 2)  { putlong( 0, 10); }
    else                   { putlong( 0,  9); }

    for(ch=0; ch<cfg.channels; ch++)
    {
      side_info_t *gi = &si[0][ch];

      putlong( gi->part2_3_length,    12);
      putlong( gi->address3>>1,        9);
      putlong( gi->global_gain,        8);
      putlong( gi->table_select[0],   15);
      putlong( gi->table_select[1],    5);
      putlong( gi->table_select[2],    5);
      putlong( gi->region_0_1,         7);
      putlong( gi->table_select[3],    2);
    }
  }
  /* flush remaining bits */
  putbits(cc, sz);
}

/* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS,
   as well as the definitions of the side information on pages 26 and 27. */
void Huffmancodebits( short *ix, int *xr, side_info_t *gi )
{
  int    region1   = gi->address1;
  int    region2   = gi->address2;
  int    bigvals   = gi->address3;
  int    count1    = bigvals + (gi->count1 << 2);
  int    stuffBits = 0;
  int    bits      = 0;

  if(region1 > 0)
    bits += HuffmanCode(ix, xr,   0    , region1, gi->table_select[0]);

  if(region2 > region1)
    bits += HuffmanCode(ix, xr, region1, region2, gi->table_select[1]);

  if(bigvals > region2)
    bits += HuffmanCode(ix, xr, region2, bigvals, gi->table_select[2]);
 
  if(count1 > bigvals)
    bits += HuffmanCod1(ix, xr, bigvals,  count1, gi->table_select[3]);

  if((stuffBits = gi->part2_3_length - bits) > 0)
  {
    int stuffWords = stuffBits >> 5;
    int remainBits = stuffBits & 31;

    if( remainBits )
      putbits( ~0, remainBits );

    while( stuffWords-- )
      putbits( ~0, 32 ); /* Huffman code tables leed to padding ones */
  }
}

int HuffmanCod1( short *ix, int *xr, uint32 begin, uint32 end, int tbl)
{
  uint32  cc=0, sz=0;
  uint32  i, d, p;
  int     sumbit=0, s=0, l=0, v, w, x, y;
  #define sgnv (xr[i+0] < 0 ? 1 : 0)
  #define sgnw (xr[i+1] < 0 ? 1 : 0)
  #define sgnx (xr[i+2] < 0 ? 1 : 0)
  #define sgny (xr[i+3] < 0 ? 1 : 0)

  for(i=begin; i<end; i+=4)
  {
    v = ix[i+0];
    w = ix[i+1];
    x = ix[i+2];
    y = ix[i+3];
    p = (v << 3) + (w << 2) + (x << 1) + y;

    switch(p)
    {
      case  0: l=0; s = 0; break;
      case  1: l=1; s = sgnv; break;
      case  2: l=1; s =               sgnw; break;
      case  3: l=2; s = (sgnv << 1) + sgnw; break;
      case  4: l=1; s =                             sgnx; break;
      case  5: l=2; s = (sgnv << 1)               + sgnx; break;
      case  6: l=2; s =               (sgnw << 1) + sgnx; break;
      case  7: l=3; s = (sgnv << 2) + (sgnw << 1) + sgnx; break;
      case  8: l=1; s =                                           sgny; break;
      case  9: l=2; s = (sgnv << 1)                             + sgny; break;
      case 10: l=2; s =               (sgnw << 1)               + sgny; break;
      case 11: l=3; s = (sgnv << 2) + (sgnw << 1)               + sgny; break;
      case 12: l=2; s =                             (sgnx << 1) + sgny; break;
      case 13: l=3; s = (sgnv << 2)               + (sgnx << 1) + sgny; break;
      case 14: l=3; s =               (sgnw << 2) + (sgnx << 1) + sgny; break;
      case 15: l=4; s = (sgnv << 3) + (sgnw << 2) + (sgnx << 1) + sgny; break;
    }

    d = (ht_count[tbl][0][p] << l) + s;
    l =  ht_count[tbl][1][p];
    putlong( d, l );
    sumbit += l;
  }

  /* flush remaining bits */
  putbits(cc, sz);

  return sumbit;
}

/* Implements the pseudocode of page 98 of the IS */
int HuffmanCode( short *ix, int *xr, uint32 begin, uint32 end, int table)
{
  uint32       cc=0, sz=0, code;
  uint32       i, xl=0, yl=0, idx;
  int          x, y, bit, sumbit=0;
  #define sign_x (xr[i+0] < 0 ? 1 : 0)
  #define sign_y (xr[i+1] < 0 ? 1 : 0)

  if(table == 0)
    return 0;

  if( table > 15 )
  { /* ESC-table is used */
    uint32 linbits  = ht_big[table-16].linbits;
    uint16 *hffcode = table < 24 ? t16HB : t24HB;
    uint8  *hlen    = table < 24 ? t16l  : t24l;

    for(i=begin; i<end; i+=2)
    {
      x = ix[ i ];
      y = ix[i+1];

      if(x > 14) { xl = x - 15;  x = 15; }
      if(y > 14) { yl = y - 15;  y = 15; }

      idx  = x * 16 + y;
      code = hffcode[idx];
      bit  = hlen   [idx];

      if(x)
      {
        if(x > 14)
        {
          code = (code << linbits) | xl;
          bit += linbits;
        }

        code = (code << 1) | sign_x;
        bit += 1;
      }

      if(y)
      {
        if(y > 14)
        {
          code = (code << linbits) | yl;
          bit += linbits;
        }

        code = (code << 1) | sign_y;
        bit += 1;
      }

      putlong( code, bit );
      sumbit += bit;
    }
  }
  else
  { /* No ESC-words */
    const struct huffcodetab *h = &ht[table];

    for(i=begin; i<end; i+=2)
    {
      x = ix[i];
      y = ix[i+1];

      idx  = x * h->len + y;
      code = h->table[idx];
      bit  = h->hlen [idx];

      if(x)
      {
        code = (code << 1) | sign_x;
        bit += 1;
      }

      if(y)
      {
        code = (code << 1) | sign_y;
        bit += 1;
      }

      putlong( code, bit );
      sumbit += bit;
    }
  }

  /* flush remaining bits */
  putbits(cc, sz);

  return sumbit;
}

void putbits(uint32 val, uint32 nbit)
{
  int new_bitpos = CodedData.bitpos + nbit;
  int ptrpos     = CodedData.bitpos >> 5;

  val = val & (0xffffffff >> (32 - nbit));

  /* data fit in one uint32 */
  if(((new_bitpos - 1) >> 5) == ptrpos)
    CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31);
  else
  {
    CodedData.bbuf[ptrpos  ] |= val >> ((new_bitpos - 32) & 31);
    CodedData.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31);
  }

  CodedData.bitpos = new_bitpos;
}

/***************************************************************************/
/*  Choose the Huffman table that will encode ix[begin..end] with          */
/*  the fewest bits.                                                       */
/*  Note: This code contains knowledge about the sizes and characteristic  */
/*  of the Huffman tables as defined in the IS (Table B.7), and will not   */
/*  work with any arbitrary tables.                                        */
/***************************************************************************/
int choose_table( short *ix, uint32 begin, uint32 end, int *bits )
{
  uint32 i;
  int    max, table0, table1;
  
  for(i=begin,max=0; i<end; i++)
    if(ix[i] > max)
      max = ix[i];

  if(max < 16)
  {
    /* tables without linbits */
    /* indx: 0  1  2  3  4  5  6  7  8  9 10 11 12  13 14  15 */
    /*  len: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */
    switch(max)
    {
      case 0:  return  0;
      case 1:  return       count_bit1(ix, begin, end, bits);
      case 2:  return  2 + find_best_2(ix, begin, end, tab23, 3, bits);
      case 3:  return  5 + find_best_2(ix, begin, end, tab56, 4, bits);
      case 4:
      case 5:  return  7 + find_best_3(ix, begin, end, tab789, 6, bits);
      case 6:
      case 7:  return 10 + find_best_3(ix, begin, end, tabABC, 8, bits);
      default: return 13 + find_best_2(ix, begin, end, tab1315, 16, bits) * 2;
    }
  }
  else
  {
    /* tables with linbits */
    max -= 15;

    for(table0=0; table0<8; table0++)
      if(ht_big[table0].linmax >= max)
        break;

    for(table1=8; table1<16; table1++)
      if(ht_big[table1].linmax >= max)
        break;

    return 16 + count_bigv(ix, begin, end, table0, table1, bits);
  }
}

int find_best_2(short *ix, uint32 start, uint32 end, const uint32 *table,
                uint32 len, int *bits)
{
  uint32 i, sum = 0;

  for(i=start; i<end; i+=2)
    sum += table[ix[i] * len + ix[i+1]];

  if((sum & 0xffff) <= (sum >> 16))
  {
    *bits = (sum & 0xffff);
    return 1;
  }
  else
  {
    *bits = sum >> 16;
    return 0;
  }
}

int find_best_3(short *ix, uint32 start, uint32 end, const uint32 *table,
                uint32 len, int *bits)
{
  uint32 i, j, sum  = 0;
  int          sum1 = 0;
  int          sum2 = 0;
  int          sum3 = 0;

  /* avoid overflow in packed additions: 78*13 < 1024 */
  for(i=start; i<end; )
  {
    j = i + 2*78 > end ? end : i + 2*78;

    for(sum=0; i<j; i+=2)
      sum += table[ix[i] * len + ix[i+1]];

    sum1 += (sum >> 20);
    sum2 += (sum >> 10) & 0x3ff;
    sum3 += (sum >>  0) & 0x3ff;
  }

  i = 0;
  if(sum1 > sum2) { sum1 = sum2;  i = 1; }
  if(sum1 > sum3) { sum1 = sum3;  i = 2; }

  *bits = sum1;

  return i;
}

/*************************************************************************/
/* Function: Count the number of bits necessary to code the subregion.   */
/*************************************************************************/
int count_bit1(short *ix, uint32 start, uint32 end, int *bits )
{
  uint32 i, sum = 0;

  for(i=start; i<end; i+=2)
    sum += t1l[4 + ix[i] * 2 + ix[i+1]];

  *bits = sum;

  return 1; /* this is table1 */
}

int count_bigv(short *ix, uint32 start, uint32 end, int table0,
               int table1, int *bits )
{
  uint32  i, sum0, sum1, sum=0, bigv=0, x, y;

  /* ESC-table is used */
  for(i=start; i<end; i+=2)
  {
    x = ix[i];
    y = ix[i+1];

    if(x > 14) { x = 15; bigv++; }
    if(y > 14) { y = 15; bigv++; }

    sum += tab1624[x * 16 + y];
  }

  sum0 = (sum  >>  16)  + bigv * ht_big[table0].linbits;
  sum1 = (sum & 0xffff) + bigv * ht_big[table1].linbits;

  if(sum0 <= sum1)
  {
    *bits = sum0;
    return table0;
  }
  else
  {
    *bits = sum1;
    return table1;
  }
}

/*************************************************************************/
/* Function: Calculation of rzero, count1, address3                      */
/* (Partitions ix into big values, quadruples and zeros).                */
/*************************************************************************/
int calc_runlen( short *ix, side_info_t *si )
{
  int  p, i, sum = 0;

  for(i=SAMPL2; i-=2; )
    if(*(uint32*)&ix[i-2]) /* !!!! short *ix; !!!!! */
      break;

  si->count1 = 0;

  for( ; i>3; i-=4)
  {
    int v = ix[i-1];
    int w = ix[i-2];
    int x = ix[i-3];
    int y = ix[i-4];
    
    if((v | w | x | y) <= 1)
    {
      p = (y<<3) + (x<<2) + (w<<1) + (v);

      sum += tab01[p];

      si->count1++;
    }
    else break;
  }

  si->address3 = i;

  if((sum >> 16) < (sum & 0xffff))
  {
    si->table_select[3] = 0;
    return sum >> 16;
  }
  else
  {
    si->table_select[3] = 1;
    return sum & 0xffff;
  }
}


/*************************************************************************/
/*   Function: Quantization of the vector xr ( -> ix)                    */
/*************************************************************************/
int quantize_int(int *xr, short *ix, side_info_t *si)
{
  int   i, s, frac_pow[] = { 0x10000, 0xd745, 0xb505, 0x9838 };

  s = frac_pow[si->quantStep & 3] >> si->quantStep / 4;

  /* check for integer overflow */
  if(((si->max_val + 256) >> 8) * s >= (1622 << 8))
    return 0;

  for(i=SAMPL2; i--; )
    ix[i] = int2idx[(abs(xr[i]) * s + 0x8000) >> 16];

  return 1;
}

/*************************************************************************/
/* subdivides the bigvalue region which will use separate Huffman tables */
/*************************************************************************/
void subdivide(side_info_t *si)
{
  int scfb, count0, count1;
  
  if( !si->address3 )
  { /* no bigvalue region */
    si->region_0_1 = 0;
    si->address1   = 0;
    si->address2   = 0;
  }
  else
  {
    /* Calculate scale factor band index */
    for(scfb=0; scalefac[scfb] < si->address3; )
      scfb++;

    count0 = subdv_table[scfb].region0_cnt;
    count1 = subdv_table[scfb].region1_cnt;

    si->region_0_1 = (count0 << 3) | count1;
    si->address1   = scalefac[count0 + 1];
    si->address2   = scalefac[count0 + 1 + count1 + 1];
  }
}

/*******************************************************************/
/* Count the number of bits necessary to code the bigvalues region */
/*******************************************************************/
int bigv_bitcount(short *ix, side_info_t *gi)
{
  int b1=0, b2=0, b3=0;

  /* Select huffman code tables for bigvalues regions */
  gi->table_select[0] = 0;
  gi->table_select[1] = 0;
  gi->table_select[2] = 0;

  if( gi->address1 > 0 )            /* region0 */
    gi->table_select[0] = choose_table(ix, 0           , gi->address1, &b1);

  if( gi->address2 > gi->address1 ) /* region1 */
    gi->table_select[1] = choose_table(ix, gi->address1, gi->address2, &b2);

  if( gi->address3 > gi->address2 ) /* region2 */
    gi->table_select[2] = choose_table(ix, gi->address2, gi->address3, &b3);

  return b1+b2+b3;
}

int quantize_and_count_bits(int *xr, short *ix, side_info_t *si)
{
  int bits = 10000;

  if(quantize_int(xr, ix, si))
  {
    bits = calc_runlen(ix, si);      /* rzero,count1,address3  */
    subdivide(si);                   /* bigvalues sfb division */
    bits += bigv_bitcount(ix,si);    /* bit count */
  }

  return bits;
}

/***********************************************************************/
/* The code selects the best quantStep for a particular set of scalefacs                                                            */
/***********************************************************************/ 
int inner_loop(int *xr, int max_bits, side_info_t *si)
{
  int bits;

  while((bits=quantize_and_count_bits(xr, enc_data, si)) < max_bits-64)
  {
    if(si->quantStep == 0)
      break;

    if(si->quantStep <= 2)
      si->quantStep  = 0;
    else
      si->quantStep -= 2;
  }

  while(bits > max_bits)
  {
    si->quantStep++;
    bits = quantize_and_count_bits(xr, enc_data, si);
  }

  return bits;
}

void iteration_loop(int *xr, side_info_t *si, int gr_cnt)
{
  int remain, tar_bits, max_bits = cfg.mean_bits;

  /* distribute reserved bits to remaining granules */
  tar_bits = max_bits + (cfg.ResvSize / gr_cnt & ~7);
  if(tar_bits > max_bits + max_bits/2)
    tar_bits = max_bits + max_bits/2;

  si->part2_3_length = inner_loop(xr, tar_bits, si);
  si->global_gain    = si->quantStep + 142 - si->additStep;

  /* unused bits of the reservoir can be used for remaining granules */
  cfg.ResvSize += max_bits - si->part2_3_length;

  /* end: distribute the reserved bits to one or two granules */
  if(gr_cnt == 1)
  {
    si->part2_3_length += cfg.ResvSize;
    /* mp3 format allows max 12bits for granule length */
    if(si->part2_3_length > 4092)
    {
      remain = (si->part2_3_length - 4092 + 31) >> 5;
      si->part2_3_length    -= remain << 5;
      si[-1].part2_3_length += remain << 5;

      while(remain--)
        putbits(~0, 32);
    }
  }
}


/* returns sum_j=0^31 a[j]*cos(PI*j*(k+1/2)/32), 0<=k<32 */
void window_subband1(short *wk, int sb0[SBLIMIT], int sb1[SBLIMIT]) ICODE_ATTR;
void window_subband1(short *wk, int sb0[SBLIMIT], int sb1[SBLIMIT])
{
  int   k, i, u, v;
  short *wp, *x1, *x2;

#ifdef CPU_COLDFIRE
  int s0, s1, t0, t1;

  for(k=0; k<18; k++, wk+=64, sb0+=SBLIMIT, sb1+=SBLIMIT)
  {
    wp = enwindow;
    x1 = wk;
    x2 = x1 - 124;

    for(i=-15; i<0; i++)
    {
      asm volatile(
      "move.l (-224*4,%[x2]), %%d4\n"   /* d4 = x2[-224] */
      "movem.l (%[wp]), %%d0-%%d3\n"    /* load 8 values */
      "mac.w %%d0u, %%d4u,                       %%acc0\n"
      "mac.w %%d0u, %%d4l, (-160*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d0l, %%d4u,                       %%acc0\n"
      "mac.w %%d0l, %%d4l, ( -96*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d1u, %%d4u,                       %%acc0\n"
      "mac.w %%d1u, %%d4l, ( -32*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d1l, %%d4u,                       %%acc0\n"
      "mac.w %%d1l, %%d4l, (  32*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d2u, %%d4u,                       %%acc0\n"
      "mac.w %%d2u, %%d4l, (  96*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d2l, %%d4u,                       %%acc0\n"
      "mac.w %%d2l, %%d4l, ( 160*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d3u, %%d4u,                       %%acc0\n"
      "mac.w %%d3u, %%d4l, ( 224*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d3l, %%d4u,                       %%acc0\n"
      "mac.w %%d3l, %%d4l, (-256*4,%[x1]), %%d4, %%acc1\n"
      "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */
      "mac.w %%d0u, %%d4u,                       %%acc0\n"
      "mac.w %%d0u, %%d4l, (-192*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d0l, %%d4u,                       %%acc0\n"
      "mac.w %%d0l, %%d4l, (-128*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d1u, %%d4u,                       %%acc0\n"
      "mac.w %%d1u, %%d4l, ( -64*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d1l, %%d4u,                       %%acc0\n"
      "mac.w %%d1l, %%d4l, (   0*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d2u, %%d4u,                       %%acc0\n"
      "mac.w %%d2u, %%d4l, (  64*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d2l, %%d4u,                       %%acc0\n"
      "mac.w %%d2l, %%d4l, ( 128*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d3u, %%d4u,                       %%acc0\n"
      "mac.w %%d3u, %%d4l, ( 192*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d3l, %%d4u,                       %%acc0\n"
      "mac.w %%d3l, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n"
      "movclr.l %%acc0, %%d0\n"
      "move.l %%d0, %[s0]\n"
      "movclr.l %%acc1, %%d0\n"
      "move.l %%d0, %[s1]\n"

      "movem.l (%[wp]), %%d0-%%d3\n"    /* load 8 values */
      "mac.w %%d0u, %%d4u,                       %%acc0\n"
      "mac.w %%d0u, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d0l, %%d4u,                       %%acc0\n"
      "mac.w %%d0l, %%d4l, (  96*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d1u, %%d4u,                       %%acc0\n"
      "mac.w %%d1u, %%d4l, (  32*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d1l, %%d4u,                       %%acc0\n"
      "mac.w %%d1l, %%d4l, ( -32*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d2u, %%d4u,                       %%acc0\n"
      "mac.w %%d2u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d2l, %%d4u,                       %%acc0\n"
      "mac.w %%d2l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d3u, %%d4u,                       %%acc0\n"
      "mac.w %%d3u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n"
      "mac.w %%d3l, %%d4u,                       %%acc0\n"
      "mac.w %%d3l, %%d4l, ( 256*4,%[x2]), %%d4, %%acc1\n"
      "movem.l (32,%[wp]), %%d0-%%d3\n"  /* load 8 values */
      "mac.w %%d0u, %%d4u,                       %%acc0\n"
      "mac.w %%d0u, %%d4l, ( 192*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d0l, %%d4u,                       %%acc0\n"
      "mac.w %%d0l, %%d4l, ( 128*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d1u, %%d4u,                       %%acc0\n"
      "mac.w %%d1u, %%d4l, (  64*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d1l, %%d4u,                       %%acc0\n"
      "mac.w %%d1l, %%d4l, (   0*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d2u, %%d4u,                       %%acc0\n"
      "mac.w %%d2u, %%d4l, ( -64*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d2l, %%d4u,                       %%acc0\n"
      "mac.w %%d2l, %%d4l, (-128*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d3u, %%d4u,                       %%acc0\n"
      "mac.w %%d3u, %%d4l, (-192*4,%[x2]), %%d4, %%acc1\n"
      "mac.w %%d3l, %%d4u,                       %%acc0\n"
      "mac.w %%d3l, %%d4l,                       %%acc1\n"
      "movclr.l %%acc0, %%d0\n"
      "move.l %%d0, %[t0]\n"
      "movclr.l %%acc1, %%d0\n"
      "move.l %%d0, %[t1]\n"

      : [x1] "+a" (x1), [x2] "+a" (x2), [s0] "+m" (s0), [t0] "+m" (t0),
                                        [s1] "+m" (s1), [t1] "+m" (t1)
      : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4");

      sb0[30+i*2] =  shft4(t0)          + shft13(s0) * wp[24];
      sb0[31+i*2] = shft13(t0) * wp[25] - shft13(s0) * wp[26];
      sb1[30+i*2] =  shft4(t1)          + shft13(s1) * wp[24];
      sb1[31+i*2] = shft13(t1) * wp[25] - shft13(s1) * wp[26];
      wp += 27;
      x1 -=  2;
      x2 +=  2;
    }

    asm volatile(
    "move.l ( -32*4,%[x1]), %%d4\n"   /* d4 = x1[-32] */
    "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */

    "mac.w %%d0u, %%d4u,                       %%acc0\n"
    "mac.w %%d0u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d0l, %%d4u,                       %%acc0\n"
    "mac.w %%d0l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1u, %%d4u,                       %%acc0\n"
    "mac.w %%d1u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1l, %%d4u,                       %%acc0\n"
    "mac.w %%d1l, %%d4l, (  32*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2u, %%d4u,                       %%acc0\n"
    "mac.w %%d2u, %%d4l, (  96*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2l, %%d4u,                       %%acc0\n"
    "mac.w %%d2l, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3u, %%d4u,                       %%acc0\n"
    "mac.w %%d3u, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3l, %%d4u,                       %%acc0\n"
    "mac.w %%d3l, %%d4l, ( -16*4,%[x1]), %%d4, %%acc1\n"
    "movclr.l %%acc0, %%d0\n"
    "move.l %%d0, %[s0]\n"
    "movclr.l %%acc1, %%d0\n"
    "move.l %%d0, %[s1]\n"

    "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */
    "mac.w %%d0u, %%d4u,                       %%acc0\n"
    "mac.w %%d0u, %%d4l, ( -48*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1u, %%d4u,                       %%acc0\n"
    "mac.w %%d1u, %%d4l, (  16*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1l, %%d4u,                       %%acc0\n"
    "mac.w %%d1l, %%d4l, ( -80*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2u, %%d4u,                       %%acc0\n"
    "mac.w %%d2u, %%d4l, (  48*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2u, %%d4u,                       %%acc0\n"
    "mac.w %%d2u, %%d4l, (-112*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3u, %%d4u,                       %%acc0\n"
    "mac.w %%d3u, %%d4l, (  80*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3l, %%d4u,                       %%acc0\n"
    "mac.w %%d3l, %%d4l, (-144*4,%[x1]), %%d4, %%acc1\n"
    "movem.l (32,%[wp]), %%d0-%%d3\n" /* load 8 values */
    "mac.w %%d0u, %%d4u,                       %%acc0\n"
    "mac.w %%d0u, %%d4l, ( 112*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d0u, %%d4u,                       %%acc0\n"
    "mac.w %%d0u, %%d4l, (-176*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1u, %%d4u,                       %%acc0\n"
    "mac.w %%d1u, %%d4l, ( 144*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d1l, %%d4u,                       %%acc0\n"
    "mac.w %%d1l, %%d4l, (-208*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2u, %%d4u,                       %%acc0\n"
    "mac.w %%d2u, %%d4l, ( 176*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d2u, %%d4u,                       %%acc0\n"
    "mac.w %%d2u, %%d4l, (-240*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3u, %%d4u,                       %%acc0\n"
    "mac.w %%d3u, %%d4l, ( 208*4,%[x1]), %%d4, %%acc1\n"
    "mac.w %%d3l, %%d4u,                       %%acc0\n"
    "mac.w %%d3l, %%d4l,                       %%acc1\n"
    "movclr.l %%acc0, %%d0\n"
    "move.l %%d0, %[t0]\n"
    "movclr.l %%acc1, %%d0\n"
    "move.l %%d0, %[t1]\n"

    : [x1] "+a" (x1), [s0] "+m" (s0), [t0] "+m" (t0),
                      [s1] "+m" (s1), [t1] "+m" (t1)
    : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4");

    u  = shft4(s0 - t0);
    v  = shft4(s0 + t0);
    t0 = sb0[14];
    s0 = sb0[15] - t0;

    sb0[31] = v + t0;   /* A0 */
    sb0[30] = u + s0;   /* A1 */
    sb0[15] = u - s0;   /* A2 */
    sb0[14] = v - t0;   /* A3 */

    u  = shft4(s1 - t1);
    v  = shft4(s1 + t1);
    t1 = sb1[14];
    s1 = sb1[15] - t1;

    sb1[31] = v + t1;   /* A0 */
    sb1[30] = u + s1;   /* A1 */
    sb1[15] = u - s1;   /* A2 */
    sb1[14] = v - t1;   /* A3 */
  }
#else
  int ch, s, t, *a;

  for(ch=0; ch<cfg.channels; ch++)
  {
    a = ch ? sb1 : sb0;
    for(k=0; k<18; k++, wk+=64, a+=SBLIMIT)
    {
      wp = enwindow;
      x1 = wk;
      x2 = x1 - 124;

      /* x1[-572] .... x1[448] = 1022 */
      /* 18*4*16*32 */
      for(i=-15; i<0; i++)
      {
        s  = (int)x2[-224*2] * wp[ 0];  t  = (int)x1[ 224*2] * wp[ 0];
        s += (int)x2[-160*2] * wp[ 1];  t += (int)x1[ 160*2] * wp[ 1];
        s += (int)x2[- 96*2] * wp[ 2];  t += (int)x1[  96*2] * wp[ 2];
        s += (int)x2[- 32*2] * wp[ 3];  t += (int)x1[  32*2] * wp[ 3];
        s += (int)x2[  32*2] * wp[ 4];  t += (int)x1[- 32*2] * wp[ 4];
        s += (int)x2[  96*2] * wp[ 5];  t += (int)x1[- 96*2] * wp[ 5];
        s += (int)x2[ 160*2] * wp[ 6];  t += (int)x1[-160*2] * wp[ 6];
        s += (int)x2[ 224*2] * wp[ 7];  t += (int)x1[-224*2] * wp[ 7];
        s += (int)x1[-256*2] * wp[ 8];  t += (int)x2[ 256*2] * wp[16];
        s += (int)x1[-192*2] * wp[ 9];  t += (int)x2[ 192*2] * wp[17];
        s += (int)x1[-128*2] * wp[10];  t += (int)x2[ 128*2] * wp[18];
        s += (int)x1[- 64*2] * wp[11];  t += (int)x2[  64*2] * wp[19];
        s += (int)x1[   0*2] * wp[12];  t += (int)x2[   0*2] * wp[20];
        s += (int)x1[  64*2] * wp[13];  t += (int)x2[- 64*2] * wp[21];
        s += (int)x1[ 128*2] * wp[14];  t += (int)x2[-128*2] * wp[22];
        s += (int)x1[ 192*2] * wp[15];  t += (int)x2[-192*2] * wp[23];

        a[30+i*2] =  shft4(t)          + shft13(s) * wp[24];
        a[31+i*2] = shft13(t) * wp[25] - shft13(s) * wp[26];
        wp += 27;
        x1 -=  2;
        x2 +=  2;
      }

      t  =  (int)x1[- 16*2]            * wp[ 8];  s  = (int)x1[ -32*2] * wp[0];
      t += ((int)x1[- 48*2]-x1[ 16*2]) * wp[10];  s += (int)x1[ -96*2] * wp[1];
      t += ((int)x1[- 80*2]+x1[ 48*2]) * wp[12];  s += (int)x1[-160*2] * wp[2];
      t += ((int)x1[-112*2]-x1[ 80*2]) * wp[14];  s += (int)x1[-224*2] * wp[3];
      t += ((int)x1[-144*2]+x1[112*2]) * wp[16];  s += (int)x1[  32*2] * wp[4];
      t += ((int)x1[-176*2]-x1[144*2]) * wp[18];  s += (int)x1[  96*2] * wp[5];
      t += ((int)x1[-208*2]+x1[176*2]) * wp[20];  s += (int)x1[ 160*2] * wp[6];
      t += ((int)x1[-240*2]-x1[208*2]) * wp[22];  s += (int)x1[ 224*2] * wp[7];

      u = shft4(s - t);
      v = shft4(s + t);
      t = a[14];
      s = a[15] - t;

      a[31] = v + t;   /* A0 */
      a[30] = u + s;   /* A1 */
      a[15] = u - s;   /* A2 */
      a[14] = v - t;   /* A3 */
    }
    wk -= 18 * 64 - 1; /* rewind wk (to next channel start) */
  }
#endif
}

void window_subband2(short *x1, int a[SBLIMIT]) ICODE_ATTR;
void window_subband2(short *x1, int a[SBLIMIT])
{
  int   xr;
  short *wp = enwindow;
  short *x2 = x1 - 124;

  wp += 27 * 15;
  x1 -=  2 * 15;
  x2 +=  2 * 15;

  xr = a[28] - a[0];  a[0] += a[28];  a[28] = shft9(xr) * wp[-2*27+25];
  xr = a[29] - a[1];  a[1] += a[29];  a[29] = shft9(xr) * wp[-2*27+25];
  xr = a[26] - a[2];  a[2] += a[26];  a[26] = shft9(xr) * wp[-4*27+25];
  xr = a[27] - a[3];  a[3] += a[27];  a[27] = shft9(xr) * wp[-4*27+25];
  xr = a[24] - a[4];  a[4] += a[24];  a[24] = shft9(xr) * wp[-6*27+25];
  xr = a[25] - a[5];  a[5] += a[25];  a[25] = shft9(xr) * wp[-6*27+25];
  xr = a[22] - a[6];  a[6] += a[22];  a[22] = shft9(xr) * SQRT        ;
  xr = a[23] - a[7];  a[7] += a[23];  a[23] = shft9(xr) * SQRT  - a[7];
  a[ 7] -= a[ 6];
  a[22] -= a[ 7];
  a[23] -= a[22];
    
  xr = a[ 6];  a[ 6] = a[31] - xr;  a[31] = a[31] + xr;
  xr = a[ 7];  a[ 7] = a[30] - xr;  a[30] = a[30] + xr;
  xr = a[22];  a[22] = a[15] - xr;  a[15] = a[15] + xr;
  xr = a[23];  a[23] = a[14] - xr;  a[14] = a[14] + xr;

  xr = a[20] - a[ 8];  a[ 8] += a[20];  a[20] = shft9(xr) * wp[-10*27+25];
  xr = a[21] - a[ 9];  a[ 9] += a[21];  a[21] = shft9(xr) * wp[-10*27+25];
  xr = a[18] - a[10];  a[10] += a[18];  a[18] = shft9(xr) * wp[-12*27+25];
  xr = a[19] - a[11];  a[11] += a[19];  a[19] = shft9(xr) * wp[-12*27+25];
  xr = a[16] - a[12];  a[12] += a[16];  a[16] = shft9(xr) * wp[-14*27+25];
  xr = a[17] - a[13];  a[13] += a[17];  a[17] = shft9(xr) * wp[-14*27+25];
  xr =-a[20] + a[24];  a[20] += a[24];  a[24] = shft9(xr) * wp[-12*27+25];
  xr =-a[21] + a[25];  a[21] += a[25];  a[25] = shft9(xr) * wp[-12*27+25];
  xr = a[ 4] - a[ 8];  a[ 4] += a[ 8];  a[ 8] = shft9(xr) * wp[-12*27+25];
  xr = a[ 5] - a[ 9];  a[ 5] += a[ 9];  a[ 9] = shft9(xr) * wp[-12*27+25];
  xr = a[ 0] - a[12];  a[ 0] += a[12];  a[12] = shft9(xr) * wp[ -4*27+25];
  xr = a[ 1] - a[13];  a[ 1] += a[13];  a[13] = shft9(xr) * wp[ -4*27+25];
  xr = a[16] - a[28];  a[16] += a[28];  a[28] = shft9(xr) * wp[ -4*27+25];
  xr =-a[17] + a[29];  a[17] += a[29];  a[29] = shft9(xr) * wp[ -4*27+25];
  
  xr = SQRT * shft9(a[ 2] - a[10]);  a[ 2] += a[10];  a[10] = xr;
  xr = SQRT * shft9(a[ 3] - a[11]);  a[ 3] += a[11];  a[11] = xr;
  xr = SQRT * shft9(a[26] - a[18]);  a[18] += a[26];  a[26] = xr - a[18];
  xr = SQRT * shft9(a[27] - a[19]);  a[19] += a[27];  a[27] = xr - a[19];
  
  xr = a[ 2];  a[19] -= a[ 3];  a[ 3] -= xr;  a[ 2] = a[31] - xr;  a[31] += xr;
  xr = a[ 3];  a[11] -= a[19];  a[18] -= xr;  a[ 3] = a[30] - xr;  a[30] += xr;
  xr = a[18];  a[27] -= a[11];  a[19] -= xr;  a[18] = a[15] - xr;  a[15] += xr;
  
  xr = a[19];  a[10] -= xr;  a[19] = a[14] - xr;  a[14] += xr;
  xr = a[10];  a[11] -= xr;  a[10] = a[23] - xr;  a[23] += xr;
  xr = a[11];  a[26] -= xr;  a[11] = a[22] - xr;  a[22] += xr;
  xr = a[26];  a[27] -= xr;  a[26] = a[ 7] - xr;  a[ 7] += xr;
  
  xr = a[27];  a[27] = a[6] - xr;  a[6] += xr;
  
  xr = SQRT * shft9(a[ 0] - a[ 4]);  a[ 0] += a[ 4];  a[ 4] = xr;
  xr = SQRT * shft9(a[ 1] - a[ 5]);  a[ 1] += a[ 5];  a[ 5] = xr;
  xr = SQRT * shft9(a[16] - a[20]);  a[16] += a[20];  a[20] = xr;
  xr = SQRT * shft9(a[17] - a[21]);  a[17] += a[21];  a[21] = xr;
  xr =-SQRT * shft9(a[ 8] - a[12]);  a[ 8] += a[12];  a[12] = xr - a[ 8];
  xr =-SQRT * shft9(a[ 9] - a[13]);  a[ 9] += a[13];  a[13] = xr - a[ 9];
  xr =-SQRT * shft9(a[25] - a[29]);  a[25] += a[29];  a[29] = xr - a[25];
  xr =-SQRT * shft9(a[24] + a[28]);  a[24] -= a[28];  a[28] = xr - a[24];
  
  xr = a[24] - a[16]; a[24] = xr;
  xr = a[20] - xr;    a[20] = xr;
  xr = a[28] - xr;    a[28] = xr;
  
  xr = a[25] - a[17]; a[25] = xr;
  xr = a[21] - xr;    a[21] = xr;
  xr = a[29] - xr;    a[29] = xr;
  
  xr = a[17] - a[1];  a[17] = xr;
  xr = a[ 9] - xr;    a[ 9] = xr;
  xr = a[25] - xr;    a[25] = xr;
  xr = a[ 5] - xr;    a[ 5] = xr;
  xr = a[21] - xr;    a[21] = xr;
  xr = a[13] - xr;    a[13] = xr;
  xr = a[29] - xr;    a[29] = xr;
  
  xr = a[ 1] - a[0];  a[ 1] = xr;
  xr = a[16] - xr;    a[16] = xr;
  xr = a[17] - xr;    a[17] = xr;
  xr = a[ 8] - xr;    a[ 8] = xr;
  xr = a[ 9] - xr;    a[ 9] = xr;
  xr = a[24] - xr;    a[24] = xr;
  xr = a[25] - xr;    a[25] = xr;
  xr = a[ 4] - xr;    a[ 4] = xr;
  xr = a[ 5] - xr;    a[ 5] = xr;
  xr = a[20] - xr;    a[20] = xr;
  xr = a[21] - xr;    a[21] = xr;
  xr = a[12] - xr;    a[12] = xr;
  xr = a[13] - xr;    a[13] = xr;
  xr = a[28] - xr;    a[28] = xr;
  xr = a[29] - xr;    a[29] = xr;
  
  xr = a[ 0];  a[ 0] += a[31];  a[31] -= xr;
  xr = a[ 1];  a[ 1] += a[30];  a[30] -= xr;
  xr = a[16];  a[16] += a[15];  a[15] -= xr;
  xr = a[17];  a[17] += a[14];  a[14] -= xr;
  xr = a[ 8];  a[ 8] += a[23];  a[23] -= xr;
  xr = a[ 9];  a[ 9] += a[22];  a[22] -= xr;
  xr = a[24];  a[24] += a[ 7];  a[ 7] -= xr;
  xr = a[25];  a[25] += a[ 6];  a[ 6] -= xr;
  xr = a[ 4];  a[ 4] += a[27];  a[27] -= xr;
  xr = a[ 5];  a[ 5] += a[26];  a[26] -= xr;
  xr = a[20];  a[20] += a[11];  a[11] -= xr;
  xr = a[21];  a[21] += a[10];  a[10] -= xr;
  xr = a[12];  a[12] += a[19];  a[19] -= xr;
  xr = a[13];  a[13] += a[18];  a[18] -= xr;
  xr = a[28];  a[28] += a[ 3];  a[ 3] -= xr;
  xr = a[29];  a[29] += a[ 2];  a[ 2] -= xr;
}

void mdct_long(int *out, int *in) ICODE_ATTR;
void mdct_long(int *out, int *in)
{
  int ct,st;
  int tc1, tc2, tc3, tc4, ts5, ts6, ts7, ts8;
  int ts1, ts2, ts3, ts4, tc5, tc6, tc7, tc8;

  /* 1,2, 5,6, 9,10, 13,14, 17 */
  tc1 = in[17] - in[ 9];
  tc3 = in[15] - in[11];
  tc4 = in[14] - in[12];
  ts5 = in[ 0] + in[ 8];
  ts6 = in[ 1] + in[ 7];
  ts7 = in[ 2] + in[ 6];
  ts8 = in[ 3] + in[ 5];

  out[17] = (ts5 + ts7 - ts8) * cx[8] - (ts6 - in[4]) * cx[8];
  st      = (ts5 + ts7 - ts8) * cx[7] + (ts6 - in[4]) * cx[8];
  ct      = (tc1 - tc3 - tc4) * cx[6];
  out[5]  = ct + st;
  out[6]  = ct - st;
    
  tc2     = (in[16] - in[10]) * cx[6];
  ts6     =  ts6 * cx[7] + in[4] * cx[8];

  ct      =  tc1 * cx[0] + tc2 + tc3 * cx[1] + tc4 * cx[2];
  st      = -ts5 * cx[4] + ts6 - ts7 * cx[5] + ts8 * cx[3];
  out[1]  = ct + st;
  out[2]  = ct - st;
    
  ct      =  tc1 * cx[1] - tc2 - tc3 * cx[2] + tc4 * cx[0];
  st      = -ts5 * cx[5] + ts6 - ts7 * cx[3] + ts8 * cx[4];
  out[ 9] = ct + st;
  out[10] = ct - st;
    
  ct      = tc1 * cx[2] - tc2 + tc3 * cx[0] - tc4 * cx[1];
  st      = ts5 * cx[3] - ts6 + ts7 * cx[4] - ts8 * cx[5];
  out[13] = ct + st;
  out[14] = ct - st;

  ts1 = in[ 8] - in[ 0];
  ts3 = in[ 6] - in[ 2];
  ts4 = in[ 5] - in[ 3];
  tc5 = in[17] + in[ 9];
  tc6 = in[16] + in[10];
  tc7 = in[15] + in[11];
  tc8 = in[14] + in[12];

  out[0]  = (tc5 + tc7 + tc8) * cx[8] + (tc6 + in[13]) * cx[8];
  ct      = (tc5 + tc7 + tc8) * cx[7] - (tc6 + in[13]) * cx[8];
  st      = (ts1 - ts3 + ts4) * cx[6];
  out[11] = ct + st;
  out[12] = ct - st;

  ts2     = (in[7] - in[1]) * cx[6];
  tc6     = in[13] * cx[8] - tc6 * cx[7];

  ct      = tc5 * cx[3] - tc6 + tc7 * cx[4] + tc8 * cx[5];
  st      = ts1 * cx[2] + ts2 + ts3 * cx[0] + ts4 * cx[1];
  out[3]  = ct + st;
  out[4]  = ct - st;

  ct      =-tc5 * cx[5] + tc6 - tc7 * cx[3] - tc8 * cx[4];
  st      = ts1 * cx[1] + ts2 - ts3 * cx[2] - ts4 * cx[0];
  out[7]  = ct + st;
  out[8]  = ct - st;

  ct      =-tc5 * cx[4] + tc6 - tc7 * cx[5] - tc8 * cx[3];
  st      = ts1 * cx[0] - ts2 + ts3 * cx[1] - ts4 * cx[2];
  out[15] = ct + st;
  out[16] = ct - st;
}

static int find_bitrate_index(int type, int bitrate)
{
  int i;

  for(i=0;i<14;i++)
    if(bitrate == bitr_index[type][i])
      break;

  return i;
}

static int find_samplerate_index(long freq, int *mp3_type)
{                                /* MPEG 2 */           /* MPEG 1 */
  static long mpeg[2][3] = { {22050, 24000, 16000}, {44100, 48000, 32000} };
  int    mpg, rate;

  /* set default values: MPEG1 at 44100/s */
  *mp3_type = 1;

  for(mpg=0; mpg<2; mpg++)
    for(rate=0; rate<3; rate++)
      if(freq == mpeg[mpg][rate])
      { *mp3_type = mpg; return rate; }

  return 0;
}

void init_mp3_encoder_engine(bool stereo, int bitrate, int sample_rate)
{
  uint32  avg_byte_per_frame;

#ifdef ROCKBOX_LITTLE_ENDIAN
  cfg.byte_order = order_littleEndian;
#else
  cfg.byte_order = order_bigEndian;
#endif

  if(bitrate < 96 && stereo && sample_rate >= 32000)
  { /* use MPEG2 format */
    sample_rate >>= 1;
    cfg.resample  = 1;
    cfg.granules  = 1;
  }
  else
  { /* use MPEG1 format */
    cfg.resample  = 0;
    cfg.granules  = 2;
  }

  cfg.samplerate    = sample_rate;
  cfg.channels      = stereo ? 2 : 1;
  cfg.mpg.mode      = stereo ? 0 : 3; /* 0=stereo, 3=mono */
  cfg.mpg.bitrate   = stereo ? bitrate : bitrate > 160 ? 160 : bitrate;
  cfg.mpg.smpl_id   = find_samplerate_index(cfg.samplerate, &cfg.mpg.type);
  cfg.mpg.bitr_id   = find_bitrate_index(cfg.mpg.type, cfg.mpg.bitrate);
  cfg.mpg.num_bands = num_bands[stereo ? cfg.mpg.type : 2][cfg.mpg.bitr_id];

  memcpy(scalefac, sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type], sizeof(scalefac));
  memset(mfbuf     , 0              , sizeof(mfbuf     ));
  memset(mdct_freq , 0              , sizeof(mdct_freq ));
  memset(enc_data  , 0              , sizeof(enc_data  ));
  memset(sb_data   , 0              , sizeof(sb_data   ));
  memset(&CodedData, 0              , sizeof(CodedData ));
  memcpy(ca        , ca_const       , sizeof(ca        ));
  memcpy(cs        , cs_const       , sizeof(cs        ));
  memcpy(cx        , cx_const       , sizeof(cx        ));
  memcpy(win       , win_const      , sizeof(win       ));
  memcpy(enwindow  , enwindow_const , sizeof(enwindow  ));
  memcpy(int2idx   , int2idx_const  , sizeof(int2idx   ));
  memcpy(ht_count  , ht_count_const , sizeof(ht_count  ));
  memcpy( tab01    , tab01_const    , sizeof(tab01     ));
  memcpy( tab23    , tab23_const    , sizeof(tab23     ));
  memcpy( tab56    , tab56_const    , sizeof(tab56     ));
  memcpy( tab1315  , tab1315_const  , sizeof(tab1315   ));
  memcpy( tab1624  , tab1624_const  , sizeof(tab1624   ));
  memcpy( tab789   , tab789_const   , sizeof(tab789    ));
  memcpy( tabABC   , tabABC_const   , sizeof(tabABC    ));
  memcpy( t1HB     , t1HB_const     , sizeof(t1HB      ));
  memcpy( t2HB     , t2HB_const     , sizeof(t2HB      ));
  memcpy( t3HB     , t3HB_const     , sizeof(t3HB      ));
  memcpy( t5HB     , t5HB_const     , sizeof(t5HB      ));
  memcpy( t6HB     , t6HB_const     , sizeof(t6HB      ));
  memcpy( t7HB     , t7HB_const     , sizeof(t7HB      ));
  memcpy( t8HB     , t8HB_const     , sizeof(t8HB      ));
  memcpy( t9HB     , t9HB_const     , sizeof(t9HB      ));
  memcpy(t10HB     , t10HB_const    , sizeof(t10HB     ));
  memcpy(t11HB     , t11HB_const    , sizeof(t11HB     ));
  memcpy(t12HB     , t12HB_const    , sizeof(t12HB     ));
  memcpy(t13HB     , t13HB_const    , sizeof(t13HB     ));
  memcpy(t15HB     , t15HB_const    , sizeof(t15HB     ));
  memcpy(t16HB     , t16HB_const    , sizeof(t16HB     ));
  memcpy(t24HB     , t24HB_const    , sizeof(t24HB     ));
  memcpy( t1l      , t1l_const      , sizeof(t1l       ));
  memcpy( t2l      , t2l_const      , sizeof(t2l       ));
  memcpy( t3l      , t3l_const      , sizeof(t3l       ));
  memcpy( t5l      , t5l_const      , sizeof(t5l       ));
  memcpy( t6l      , t6l_const      , sizeof(t6l       ));
  memcpy( t7l      , t7l_const      , sizeof(t7l       ));
  memcpy( t8l      , t8l_const      , sizeof(t8l       ));
  memcpy( t9l      , t9l_const      , sizeof(t9l       ));
  memcpy(t10l      , t10l_const     , sizeof(t10l      ));
  memcpy(t11l      , t11l_const     , sizeof(t11l      ));
  memcpy(t12l      , t12l_const     , sizeof(t12l      ));
  memcpy(t13l      , t13l_const     , sizeof(t13l      ));
  memcpy(t15l      , t15l_const     , sizeof(t15l      ));
  memcpy(t16l      , t16l_const     , sizeof(t16l      ));
  memcpy(t24l      , t24l_const     , sizeof(t24l      ));
  memcpy(ht        , ht_const       , sizeof(ht        ));

  ht[ 0].table =  NULL;  ht[ 0].hlen = NULL; /* Apparently not used */
  ht[ 1].table =  t1HB;  ht[ 1].hlen =  t1l;
  ht[ 2].table =  t2HB;  ht[ 2].hlen =  t2l;
  ht[ 3].table =  t3HB;  ht[ 3].hlen =  t3l;
  ht[ 4].table =  NULL;  ht[ 4].hlen = NULL; /* Apparently not used */
  ht[ 5].table =  t5HB;  ht[ 5].hlen =  t5l;
  ht[ 6].table =  t6HB;  ht[ 6].hlen =  t6l;
  ht[ 7].table =  t7HB;  ht[ 7].hlen =  t7l;
  ht[ 8].table =  t8HB;  ht[ 8].hlen =  t8l;
  ht[ 9].table =  t9HB;  ht[ 9].hlen =  t9l;
  ht[10].table = t10HB;  ht[10].hlen = t10l;
  ht[11].table = t11HB;  ht[11].hlen = t11l;
  ht[12].table = t12HB;  ht[12].hlen = t12l;
  ht[13].table = t13HB;  ht[13].hlen = t13l;
  ht[14].table =  NULL;  ht[14].hlen = NULL; /* Apparently not used */
  ht[15].table = t15HB;  ht[15].hlen = t15l;

  /* Figure average number of 'bytes' per frame */
  avg_byte_per_frame = SAMPL2 * 16000 * cfg.mpg.bitrate / (2 - cfg.mpg.type);
  avg_byte_per_frame = avg_byte_per_frame / cfg.samplerate;
  cfg.byte_per_frame = avg_byte_per_frame / 64;
  cfg.frac_per_frame = avg_byte_per_frame & 63;
  cfg.slot_lag       = 0;
  cfg.sideinfo_len   = 32 + (cfg.mpg.type ? (cfg.channels == 1 ? 136 : 256)
                                          : (cfg.channels == 1 ?  72 : 136));
}

void compress(void)
{
  int      i, ii, gr, k, ch, shift, gr_cnt;
  int      max, min;
  char     stg[20];

  while(1)
  {
    if((frames & 7) == 0)
    { rb->lcd_clear_display();
      rb->snprintf(stg, 20, "Frame %d / %d", frames, wav_size/SAMPL2/8);
      rb->lcd_putsxy(4, 20, stg);
      rb->lcd_update();
    }
    /* encode one mp3 frame in this loop */
    memset(CodedData.bbuf, 0, sizeof(CodedData.bbuf));
      
    if((cfg.slot_lag += cfg.frac_per_frame) >= 64)
    { /* Padding for this frame */
      cfg.slot_lag   -= 64;
      cfg.mpg.padding = 1;
    }
    else
      cfg.mpg.padding = 0;

    cfg.mean_bits = (8 * cfg.byte_per_frame + 8 * cfg.mpg.padding
                       - cfg.sideinfo_len) / cfg.granules / cfg.channels;

    /* shift out old samples */
    memcpy(mfbuf, mfbuf + 2*cfg.granules*576, 4*512);

    /* read new samples to iram for further processing */
    if(read_samples((uint32*)(mfbuf + 2*512), SAMP_PER_FRAME) == 0)
      break;

    /* swap bytes if neccessary */
    if(cfg.byte_order == order_bigEndian)
      for(i=0; i<SAMP_PER_FRAME; i++)
      {
        uint32 t = ((uint32*)mfbuf)[512 + i];
        t = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
        ((uint32*)mfbuf)[512 + i] = t;
      }

    if(cfg.resample) /* downsample to half of original */
      for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=4)
      {
        mfbuf[i/2+512] = (short)(((int)mfbuf[i+0] + mfbuf[i+2]) >> 1);
        mfbuf[i/2+513] = (short)(((int)mfbuf[i+1] + mfbuf[i+3]) >> 1);
      }

    if(cfg.channels == 1) /* mix left and right channels to mono */
      for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=2)
        mfbuf[i] = mfbuf[i+1] = (short)(((int)mfbuf[i] + mfbuf[i+1]) >> 1);

    cfg.ResvSize = 0;
    gr_cnt = cfg.granules * cfg.channels;
    CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */
    for(gr=0; gr<cfg.granules; gr++)
    {
      short *wk = mfbuf + 2*286 + gr*1152;

      /* 16bit packed wav data can be windowed efficiently on coldfire */
      window_subband1(wk, sb_data[0][1-gr][0], sb_data[1][1-gr][0]);

      for(ch=0; ch<cfg.channels; ch++)
      {
        int   band;
        int   *mdct;

        wk = mfbuf + 2*286 + gr*1152 + ch;

        /* 36864=4*18*16*32 */
        for(k=0; k<18; k++, wk+=64)
        {
          window_subband2(wk, sb_data[ch][1-gr][k]);
          /* Compensate for inversion in the analysis filter */
          if(k & 1)
            for(band=1; band<32; band+=2)
              sb_data[ch][1-gr][k][band] *= -1;
        }

        /* Perform imdct of 18 previous + 18 current subband samples */
        /* for integer precision do this loop twice (if neccessary) */
        shift = k = 14;
        for(ii=0; ii<2 && k; ii++)
        {
          mdct = mdct_freq;
          cfg.cod_info[gr][ch].additStep = 4 * (14 - shift);
          for(band=0; band<cfg.mpg.num_bands; band++, mdct+=18)
          {
            int *band0 = sb_data[ch][  gr][0] + order[band];
            int *band1 = sb_data[ch][1-gr][0] + order[band];
            int work[18];

            /* 9216=4*32*9*8 */
            for(k=-9; k<0; k++)
            {
              int a = shft_n(band1[(k+9)*32], shift);
              int b = shft_n(band1[(8-k)*32], shift);
              int c = shft_n(band0[(k+9)*32], shift);
              int d = shft_n(band0[(8-k)*32], shift);

              work[k+ 9] = shft16(a * win[k+ 9][0] + b * win[k+ 9][1]
                                + c * win[k+ 9][2] + d * win[k+ 9][3]);

              work[k+18] = shft16(c * win[k+18][0] + d * win[k+18][1]
                                + a * win[k+18][2] + b * win[k+18][3]);
            }

            /* 7200=4*18*100 */
            mdct_long(mdct, work);

            /* Perform aliasing reduction butterfly */
            if(band != 0)
              for(k=7; k>=0; --k)
              {
                int bu, bd;
                bu = shft15(mdct[k]) * ca[k] + shft15(mdct[-1-k]) * cs[k];
                bd = shft15(mdct[k]) * cs[k] - shft15(mdct[-1-k]) * ca[k];
                mdct[-1-k] = bu;
                mdct[ k  ] = bd;
              }
          }

          max = min = 0;
          for(k=0; k<576; k++)
          {
            mdct_freq[k] = shft13(mdct_freq[k]);
            if(max < mdct_freq[k])  max = mdct_freq[k];
            if(min > mdct_freq[k])  min = mdct_freq[k];
          }

          max = (max > -min) ? max : -min;
          cfg.cod_info[gr][ch].max_val = (long)max;

          /* calc new shift for higher integer precision */
          for(k=0; max<(0x3c00>>k); k++);
          shift = 12 - k;
        }

        cfg.cod_info[gr][ch].quantStep += cfg.cod_info[gr][ch].additStep;

        /* bit and noise allocation */
        iteration_loop(mdct_freq, &cfg.cod_info[gr][ch], gr_cnt--);
        /* write the frame to the bitstream */
        Huffmancodebits(enc_data, mdct_freq, &cfg.cod_info[gr][ch]);

        cfg.cod_info[gr][ch].quantStep -= cfg.cod_info[gr][ch].additStep;

        if(cfg.granules == 1)
          memcpy(sb_data[ch][0], sb_data[ch][1], sizeof(sb_data[ch][0]));
      }
    }

    enc_size = (CodedData.bitpos + 7) >> 3;
    /* finish this chunk by adding sideinfo header data */
    CodedData.bitpos = 0;
    encodeSideInfo( cfg.cod_info );

    if(cfg.byte_order != order_bigEndian)
      for(i=0; i<(enc_size+3)/4; i++)
        CodedData.bbuf[i] = myswap32(CodedData.bbuf[i]);

    if(enc_chunk + enc_size > 65536)
    {
      /* copy iram mp3 buffer to sdram/file */
      rb->write(mp3file, enc_buffer, enc_chunk & ~3);
      memcpy(enc_buffer, enc_buffer + (enc_chunk >> 2), enc_chunk & 3);
      enc_chunk &= 3;
    }

    memcpy((char*)enc_buffer + enc_chunk, CodedData.bbuf, enc_size);
    enc_chunk += enc_size;
    frames++;
  }
  /* write last chunks to disk */
  rb->write(mp3file, enc_buffer, enc_chunk);
}


int  num_file;
char filename[12][80];
char mp3_name[80];

void read_wav_files(char *dirname)
{
  DIR *dir = rb->opendir(dirname);

  if(!dir)
    return;

  while(true)
  {
    struct dirent *entry;

    entry = rb->readdir(dir);
    if(!entry)
      break;

    if( !(entry->attribute & ATTR_DIRECTORY) )
    {
      int slen = rb->strlen(entry->d_name);
            
      /* add all wav audio files */
      if(!rb->strcasecmp(entry->d_name + slen - 4, ".wav"))
      {
        if(num_file >= 12)
          break;

        rb->strncpy(filename[num_file], dirname, 79);
        slen = rb->strlen(filename[num_file]);
        rb->strncpy(filename[num_file++] + slen, entry->d_name, 79);
      }
    }
  }
  rb->closedir(dir);
}

void get_mp3_filename(char *wav_name)
{
    int slen = rb->strlen(wav_name);
    rb->strncpy(mp3_name, wav_name, 79);
    rb->strncpy(mp3_name + slen - 4, ".mp3", 5);
}

#if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD
#define MP3ENC_PREV BUTTON_UP
#define MP3ENC_NEXT BUTTON_DOWN
#define MP3ENC_DONE BUTTON_OFF
#define MP3ENC_SELECT BUTTON_SELECT
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
      (CONFIG_KEYPAD == IPOD_1G2G_PAD)
#define MP3ENC_PREV BUTTON_SCROLL_BACK
#define MP3ENC_NEXT BUTTON_SCROLL_FWD
#define MP3ENC_DONE BUTTON_MENU
#define MP3ENC_SELECT BUTTON_SELECT
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
#define MP3ENC_PREV BUTTON_UP
#define MP3ENC_NEXT BUTTON_DOWN
#define MP3ENC_DONE BUTTON_POWER
#define MP3ENC_SELECT BUTTON_SELECT
#elif CONFIG_KEYPAD == GIGABEAT_PAD
#define MP3ENC_PREV BUTTON_UP
#define MP3ENC_NEXT BUTTON_DOWN
#define MP3ENC_DONE BUTTON_POWER
#define MP3ENC_SELECT BUTTON_SELECT
#elif CONFIG_KEYPAD == SANSA_E200_PAD
#define MP3ENC_PREV BUTTON_UP
#define MP3ENC_NEXT BUTTON_DOWN
#define MP3ENC_DONE BUTTON_POWER
#define MP3ENC_SELECT BUTTON_SELECT
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
#define MP3ENC_PREV BUTTON_SCROLL_UP
#define MP3ENC_NEXT BUTTON_SCROLL_DOWN
#define MP3ENC_DONE BUTTON_POWER
#define MP3ENC_SELECT BUTTON_PLAY
#endif

enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    int   fil, sfil, nfil; /* for file selection */
    int   rat, srat, nrat; /* for rate selection */
    int   cont = 1, butt;
    long  tim  = 0;
    char  stg[40];
    char* bstrg[] = {"64","80","96","112","128","160","192","224","256","320"};
    int   brate[] = { 64,  80,  96,  112,  128,  160,  192,  224,  256,  320 };

    (void)parameter;

    PLUGIN_IRAM_INIT(api)

#ifdef CPU_COLDFIRE
    asm volatile ("move.l #0, %macsr"); /* integer mode */
#endif

    rb = api;
    rb->lcd_setfont(FONT_SYSFIXED);

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(true);
#endif
    rb->button_clear_queue();

    /* check 'viewer' or 'plugin' call */
    if(parameter == NULL || *(char*)parameter == 0)
    {
        read_wav_files("/");
        read_wav_files(REC_BASE_DIR"/");

        nfil = num_file - 1;
        sfil = 0; /* set first file as default */

        while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != MP3ENC_SELECT)
        {
            switch(butt)
            {
                case MP3ENC_DONE:   cont = 0;               break;
                case MP3ENC_PREV:   if(sfil >  0  ) sfil--; break;
                case MP3ENC_NEXT:   if(sfil < nfil) sfil++; break;
            }

            rb->lcd_clear_display();
            rb->lcd_putsxy(2, 2, "-- Select WAV-File --");

            for(fil=0; fil<=nfil; fil++)
                rb->lcd_putsxy(2, 12 + fil*8, filename[fil]);

            rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
            rb->lcd_fillrect(0, 12 + sfil*8, 127, 8);
            rb->lcd_set_drawmode(DRMODE_SOLID);
            rb->lcd_update();
        }
    }
    else
    {
        sfil = 0;
        rb->strncpy(filename[0], (char*)parameter, 79);
    }

    nrat = 9;
    srat = 4; /* set 128kBit as default */

    while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != MP3ENC_SELECT)
    {
        switch(butt)
        {
            case MP3ENC_DONE:   cont = 0;               break;
            case MP3ENC_PREV:   if(srat >  0  ) srat--; break;
            case MP3ENC_NEXT:   if(srat < nrat) srat++; break;
        }

        rb->lcd_clear_display();
        rb->lcd_putsxy(2, 2, "-- Select Bitrate --");

        for(rat=0; rat<=nrat; rat++)
            rb->lcd_putsxy(2, 12 + rat*8, bstrg[rat]);
        rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
        rb->lcd_fillrect(0, 12 + srat*8, 127, 8);
        rb->lcd_set_drawmode(DRMODE_SOLID);
        rb->lcd_update();
    }

    wav_filename = filename[sfil];

    if(cont)
    {
        if(wave_open() == 0)
        {
            init_mp3_encoder_engine(true, brate[srat], cfg.samplerate);
            get_mp3_filename(wav_filename);
            mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC);
            frames  = 0;

            tim = *rb->current_tick;
            compress();
            tim = *rb->current_tick - tim;

            rb->close(wavfile);
            rb->close(mp3file);
        }
        else
        {
            rb->close(wavfile);
            rb->snprintf(stg, 20, "WaveOpen failed %d", wave_open());
            rb->lcd_putsxy(0, 20, stg);
            rb->lcd_update();
            rb->sleep(5*HZ);
        }

        rb->lcd_clear_display();
        rb->snprintf(stg, 30, "  Conversion: %ld.%02lds    ", tim/100, tim%100);
        rb->lcd_putsxy(0, 30, stg);
        tim = frames * SAMP_PER_FRAME * 100 / 44100; /* unit=.01s */
        rb->snprintf(stg, 30, "  WAV-Length: %ld.%02lds    ", tim/100, tim%100);
        rb->lcd_putsxy(0, 20, stg);
        rb->lcd_update();
        rb->sleep(5*HZ);
    }

    rb->lcd_setfont(FONT_UI);
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    rb->cpu_boost(false);
#endif
    return PLUGIN_OK;
}