1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
Index: libavcodec/fixp_mdct.h
===================================================================
--- libavcodec/fixp_mdct.h	(revision 0)
+++ libavcodec/fixp_mdct.h	(revision 0)
@@ -0,0 +1,560 @@
+/*
+ * The following (normalized modified discrete cosine transform)
+ * is taken from the OggVorbis 'TREMOR' source code.
+ *
+ * It has been modified for the ffmpeg cook fixed point decoder.
+ */
+
+/********************************************************************
+ *                                                                  *
+ * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002    *
+ * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Xiph.org Foundation nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ *********************************************************************
+
+ function: normalized modified discrete cosine transform
+           power of two length transform only [64 <= n ]
+ last mod: $Id: mdct.c 14281 2004-12-30 12:11:32Z henry $
+
+ Original algorithm adapted long ago from _The use of multirate filter
+ banks for coding of high quality digital audio_, by T. Sporer,
+ K. Brandenburg and B. Edler, collection of the European Signal
+ Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp
+ 211-214
+
+ The below code implements an algorithm that no longer looks much like
+ that presented in the paper, but the basic structure remains if you
+ dig deep enough to see it.
+
+ This module DOES NOT INCLUDE code to generate/apply the window
+ function.  Everybody has their own weird favorite including me... I
+ happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
+ vehemently disagree.
+
+ ********************************************************************/
+#include "fixp_mdct_data.h"
+
+/**
+ * Fixed point multiply by fraction.
+ *
+ * @param a                     fix point value
+ * @param b                     fix point fraction, 0 <= b < 1
+ */
+static inline FIXP fixp_mult_su(FIXP a, FIXPU b)
+{
+    int32_t hb = (a >> 16) * b;
+    uint32_t lb = (a & 0xffff) * b;
+
+    return hb + (lb >> 16) + ((lb & 0x8000) >> 15);
+}
+
+#define STIN static inline
+
+typedef int32_t ogg_int32_t;
+
+#define DATA_TYPE ogg_int32_t
+#define REG_TYPE  register ogg_int32_t
+#define LOOKUP_T const uint16_t
+
+static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
+  return fixp_mult_su(x, y) >> 1;
+}
+
+static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
+  return fixp_mult_su(x, y);
+}
+
+/*
+ * This should be used as a memory barrier, forcing all cached values in
+ * registers to wr writen back to memory.  Might or might not be beneficial
+ * depending on the architecture and compiler.
+ */
+#define MB()
+
+/*
+ * The XPROD functions are meant to optimize the cross products found all
+ * over the place in mdct.c by forcing memory operation ordering to avoid
+ * unnecessary register reloads as soon as memory is being written to.
+ * However this is only beneficial on CPUs with a sane number of general
+ * purpose registers which exclude the Intel x86.  On Intel, better let the
+ * compiler actually reload registers directly from original memory by using
+ * macros.
+ */
+
+#ifdef __i386__
+
+#define XPROD32(_a, _b, _t, _v, _x, _y)		\
+  { *(_x)=MULT32(_a,_t)+MULT32(_b,_v);		\
+    *(_y)=MULT32(_b,_t)-MULT32(_a,_v); }
+#define XPROD31(_a, _b, _t, _v, _x, _y)		\
+  { *(_x)=MULT31(_a,_t)+MULT31(_b,_v);		\
+    *(_y)=MULT31(_b,_t)-MULT31(_a,_v); }
+#define XNPROD31(_a, _b, _t, _v, _x, _y)	\
+  { *(_x)=MULT31(_a,_t)-MULT31(_b,_v);		\
+    *(_y)=MULT31(_b,_t)+MULT31(_a,_v); }
+
+#else
+
+static inline void XPROD32(ogg_int32_t  a, ogg_int32_t  b,
+			   ogg_int32_t  t, ogg_int32_t  v,
+			   ogg_int32_t *x, ogg_int32_t *y)
+{
+  *x = MULT32(a, t) + MULT32(b, v);
+  *y = MULT32(b, t) - MULT32(a, v);
+}
+
+static inline void XPROD31(ogg_int32_t  a, ogg_int32_t  b,
+			   ogg_int32_t  t, ogg_int32_t  v,
+			   ogg_int32_t *x, ogg_int32_t *y)
+{
+  *x = MULT31(a, t) + MULT31(b, v);
+  *y = MULT31(b, t) - MULT31(a, v);
+}
+
+static inline void XNPROD31(ogg_int32_t  a, ogg_int32_t  b,
+			    ogg_int32_t  t, ogg_int32_t  v,
+			    ogg_int32_t *x, ogg_int32_t *y)
+{
+  *x = MULT31(a, t) - MULT31(b, v);
+  *y = MULT31(b, t) + MULT31(a, v);
+}
+
+#endif
+
+
+/* 8 point butterfly (in place) */
+STIN void mdct_butterfly_8(DATA_TYPE *x){
+
+  REG_TYPE r0   = x[4] + x[0];
+  REG_TYPE r1   = x[4] - x[0];
+  REG_TYPE r2   = x[5] + x[1];
+  REG_TYPE r3   = x[5] - x[1];
+  REG_TYPE r4   = x[6] + x[2];
+  REG_TYPE r5   = x[6] - x[2];
+  REG_TYPE r6   = x[7] + x[3];
+  REG_TYPE r7   = x[7] - x[3];
+
+	   x[0] = r5   + r3;
+	   x[1] = r7   - r1;
+	   x[2] = r5   - r3;
+	   x[3] = r7   + r1;
+           x[4] = r4   - r0;
+	   x[5] = r6   - r2;
+           x[6] = r4   + r0;
+	   x[7] = r6   + r2;
+	   MB();
+}
+
+/* 16 point butterfly (in place, 4 register) */
+STIN void mdct_butterfly_16(DATA_TYPE *x){
+
+  REG_TYPE r0, r1;
+
+	   r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0];
+	   r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1];
+	   x[ 0] = MULT31((r0 + r1) , cPI2_8);
+	   x[ 1] = MULT31((r1 - r0) , cPI2_8);
+	   MB();
+
+	   r0 = x[10] - x[ 2]; x[10] += x[ 2];
+	   r1 = x[ 3] - x[11]; x[11] += x[ 3];
+	   x[ 2] = r1; x[ 3] = r0;
+	   MB();
+
+	   r0 = x[12] - x[ 4]; x[12] += x[ 4];
+	   r1 = x[13] - x[ 5]; x[13] += x[ 5];
+	   x[ 4] = MULT31((r0 - r1) , cPI2_8);
+	   x[ 5] = MULT31((r0 + r1) , cPI2_8);
+	   MB();
+
+	   r0 = x[14] - x[ 6]; x[14] += x[ 6];
+	   r1 = x[15] - x[ 7]; x[15] += x[ 7];
+	   x[ 6] = r0; x[ 7] = r1;
+	   MB();
+
+	   mdct_butterfly_8(x);
+	   mdct_butterfly_8(x+8);
+}
+
+/* 32 point butterfly (in place, 4 register) */
+STIN void mdct_butterfly_32(DATA_TYPE *x){
+
+  REG_TYPE r0, r1;
+
+	   r0 = x[30] - x[14]; x[30] += x[14];           
+	   r1 = x[31] - x[15]; x[31] += x[15];
+	   x[14] = r0; x[15] = r1;
+	   MB();
+
+	   r0 = x[28] - x[12]; x[28] += x[12];           
+	   r1 = x[29] - x[13]; x[29] += x[13];
+	   XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] );
+	   MB();
+
+	   r0 = x[26] - x[10]; x[26] += x[10];
+	   r1 = x[27] - x[11]; x[27] += x[11];
+	   x[10] = MULT31((r0 - r1) , cPI2_8);
+	   x[11] = MULT31((r0 + r1) , cPI2_8);
+	   MB();
+
+	   r0 = x[24] - x[ 8]; x[24] += x[ 8];
+	   r1 = x[25] - x[ 9]; x[25] += x[ 9];
+	   XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] );
+	   MB();
+
+	   r0 = x[22] - x[ 6]; x[22] += x[ 6];
+	   r1 = x[ 7] - x[23]; x[23] += x[ 7];
+	   x[ 6] = r1; x[ 7] = r0;
+	   MB();
+
+	   r0 = x[ 4] - x[20]; x[20] += x[ 4];
+	   r1 = x[ 5] - x[21]; x[21] += x[ 5];
+	   XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] );
+	   MB();
+
+	   r0 = x[ 2] - x[18]; x[18] += x[ 2];
+	   r1 = x[ 3] - x[19]; x[19] += x[ 3];
+	   x[ 2] = MULT31((r1 + r0) , cPI2_8);
+	   x[ 3] = MULT31((r1 - r0) , cPI2_8);
+	   MB();
+
+	   r0 = x[ 0] - x[16]; x[16] += x[ 0];
+	   r1 = x[ 1] - x[17]; x[17] += x[ 1];
+	   XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] );
+	   MB();
+
+	   mdct_butterfly_16(x);
+	   mdct_butterfly_16(x+16);
+}
+
+/* N/stage point generic N stage butterfly (in place, 2 register) */
+STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){
+
+  LOOKUP_T *T   = sincos_lookup;
+  DATA_TYPE *x1        = x + points      - 8;
+  DATA_TYPE *x2        = x + (points>>1) - 8;
+  REG_TYPE   r0;
+  REG_TYPE   r1;
+
+  //av_log(0, 0, "bfly: points=%d, step=%d\n", points, step);
+
+  do{
+    r0 = x1[6] - x2[6]; x1[6] += x2[6];
+    r1 = x2[7] - x1[7]; x1[7] += x2[7];
+    XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step;
+
+    r0 = x1[4] - x2[4]; x1[4] += x2[4];
+    r1 = x2[5] - x1[5]; x1[5] += x2[5];
+    XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step;
+
+    r0 = x1[2] - x2[2]; x1[2] += x2[2];
+    r1 = x2[3] - x1[3]; x1[3] += x2[3];
+    XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step;
+
+    r0 = x1[0] - x2[0]; x1[0] += x2[0];
+    r1 = x2[1] - x1[1]; x1[1] += x2[1];
+    XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step;
+
+    x1-=8; x2-=8;
+  }while(T<sincos_lookup+2048);
+  do{
+    r0 = x1[6] - x2[6]; x1[6] += x2[6];
+    r1 = x1[7] - x2[7]; x1[7] += x2[7];
+    XNPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T-=step;
+
+    r0 = x1[4] - x2[4]; x1[4] += x2[4];
+    r1 = x1[5] - x2[5]; x1[5] += x2[5];
+    XNPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T-=step;
+
+    r0 = x1[2] - x2[2]; x1[2] += x2[2];
+    r1 = x1[3] - x2[3]; x1[3] += x2[3];
+    XNPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T-=step;
+
+    r0 = x1[0] - x2[0]; x1[0] += x2[0];
+    r1 = x1[1] - x2[1]; x1[1] += x2[1];
+    XNPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T-=step;
+
+    x1-=8; x2-=8;
+  }while(T>sincos_lookup);
+  do{
+    r0 = x2[6] - x1[6]; x1[6] += x2[6];
+    r1 = x2[7] - x1[7]; x1[7] += x2[7];
+    XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step;
+
+    r0 = x2[4] - x1[4]; x1[4] += x2[4];
+    r1 = x2[5] - x1[5]; x1[5] += x2[5];
+    XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step;
+
+    r0 = x2[2] - x1[2]; x1[2] += x2[2];
+    r1 = x2[3] - x1[3]; x1[3] += x2[3];
+    XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step;
+
+    r0 = x2[0] - x1[0]; x1[0] += x2[0];
+    r1 = x2[1] - x1[1]; x1[1] += x2[1];
+    XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step;
+
+    x1-=8; x2-=8;
+  }while(T<sincos_lookup+2048);
+  do{
+    r0 = x1[6] - x2[6]; x1[6] += x2[6];
+    r1 = x2[7] - x1[7]; x1[7] += x2[7];
+    XNPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T-=step;
+
+    r0 = x1[4] - x2[4]; x1[4] += x2[4];
+    r1 = x2[5] - x1[5]; x1[5] += x2[5];
+    XNPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T-=step;
+
+    r0 = x1[2] - x2[2]; x1[2] += x2[2];
+    r1 = x2[3] - x1[3]; x1[3] += x2[3];
+    XNPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T-=step;
+
+    r0 = x1[0] - x2[0]; x1[0] += x2[0];
+    r1 = x2[1] - x1[1]; x1[1] += x2[1];
+    XNPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T-=step;
+
+    x1-=8; x2-=8;
+  }while(T>sincos_lookup);
+}
+
+STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){
+
+  int stages=8-shift;
+  int i,j;
+  
+  for(i=0;--stages>0;i++){
+    for(j=0;j<(1<<i);j++)
+      mdct_butterfly_generic(x+(points>>i)*j,points>>i,8<<(i+shift));
+  }
+
+  for(j=0;j<points;j+=32)
+    mdct_butterfly_32(x+j);
+
+}
+
+static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
+
+STIN int bitrev12(int x){
+  return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8);
+}
+
+STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){
+
+  int          bit   = 0;
+  DATA_TYPE   *w0    = x;
+  DATA_TYPE   *w1    = x = w0+(n>>1);
+  LOOKUP_T    *T = sincos_lookup+(step>>1);
+  LOOKUP_T    *Ttop  = T+2048;
+  DATA_TYPE    r2;
+
+  //av_log(0, 0, "brev: shift=%d, step=%d\n", shift, step);
+
+  do{
+    DATA_TYPE r3     = bitrev12(bit++);
+    DATA_TYPE *x0    = x + ((r3 ^ 0xfff)>>shift) -1;
+    DATA_TYPE *x1    = x + (r3>>shift);
+
+    REG_TYPE  r0     = x0[0]  + x1[0];
+    REG_TYPE  r1     = x1[1]  - x0[1];
+
+	      XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
+
+	      w1    -= 4;
+
+	      r0     = (x0[1] + x1[1])>>1;
+              r1     = (x0[0] - x1[0])>>1;
+	      w0[0]  = r0     + r2;
+	      w0[1]  = r1     + r3;
+	      w1[2]  = r0     - r2;
+	      w1[3]  = r3     - r1;
+
+	      r3     = bitrev12(bit++);
+              x0     = x + ((r3 ^ 0xfff)>>shift) -1;
+              x1     = x + (r3>>shift);
+
+              r0     = x0[0]  + x1[0];
+              r1     = x1[1]  - x0[1];
+
+	      XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
+
+              r0     = (x0[1] + x1[1])>>1;
+              r1     = (x0[0] - x1[0])>>1;
+	      w0[2]  = r0     + r2;
+	      w0[3]  = r1     + r3;
+	      w1[0]  = r0     - r2;
+	      w1[1]  = r3     - r1;
+
+	      w0    += 4;
+  }while(T<Ttop);
+  do{
+    DATA_TYPE r3     = bitrev12(bit++);
+    DATA_TYPE *x0    = x + ((r3 ^ 0xfff)>>shift) -1;
+    DATA_TYPE *x1    = x + (r3>>shift);
+
+    REG_TYPE  r0     = x0[0]  + x1[0];
+    REG_TYPE  r1     = x1[1]  - x0[1];
+
+	      T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
+
+	      w1    -= 4;
+
+	      r0     = (x0[1] + x1[1])>>1;
+              r1     = (x0[0] - x1[0])>>1;
+	      w0[0]  = r0     + r2;
+	      w0[1]  = r1     + r3;
+	      w1[2]  = r0     - r2;
+	      w1[3]  = r3     - r1;
+
+	      r3     = bitrev12(bit++);
+              x0     = x + ((r3 ^ 0xfff)>>shift) -1;
+              x1     = x + (r3>>shift);
+
+              r0     = x0[0]  + x1[0];
+              r1     = x1[1]  - x0[1];
+
+	      T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
+
+              r0     = (x0[1] + x1[1])>>1;
+              r1     = (x0[0] - x1[0])>>1;
+	      w0[2]  = r0     + r2;
+	      w0[3]  = r1     + r3;
+	      w1[0]  = r0     - r2;
+	      w1[1]  = r3     - r1;
+
+	      w0    += 4;
+  }while(w0<w1);
+}
+
+STIN void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out){
+  int n2=n>>1;
+  int n4=n>>2;
+  DATA_TYPE *iX;
+  DATA_TYPE *oX;
+  LOOKUP_T *T;
+  int shift;
+  int step;
+
+  for (shift=6;!(n&(1<<shift));shift++);
+
+  shift=13-shift;
+  step=4<<shift;
+  //step=16;
+  //av_log(0, 0, "mdct: shift=%d, step=%d\n", shift, step);
+   
+  /* rotate */
+
+  iX            = in+n2-7;
+  oX            = out+n2+n4;
+  T             = sincos_lookup;
+
+  do{
+    oX-=4;
+    XPROD31( iX[4], iX[6], T[0], T[1], &oX[2], &oX[3] ); T+=step;
+    XPROD31( iX[0], iX[2], T[0], T[1], &oX[0], &oX[1] ); T+=step;
+    iX-=8;
+  }while(iX>=in+n4);
+  do{
+    oX-=4;
+    XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step;
+    XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step;
+    iX-=8;
+  }while(iX>=in);
+
+  iX            = in+n2-8;
+  oX            = out+n2+n4;
+  T             = sincos_lookup;
+
+  do{
+    T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] );
+    T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] );
+    iX-=8;
+    oX+=4;
+  }while(iX>=in+n4);
+  do{
+    T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] );
+    T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] );
+    iX-=8;
+    oX+=4;
+  }while(iX>=in);
+
+  mdct_butterflies(out+n2,n2,shift);
+  mdct_bitreverse(out,n,step,shift);
+
+  /* rotate */
+
+  step>>=2;
+  //step=4;
+  {
+    DATA_TYPE *oX1=out+n2+n4;
+    DATA_TYPE *oX2=out+n2+n4;
+    DATA_TYPE *iX =out;
+
+    T=sincos_lookup+(step>>1);
+    do{
+      oX1-=4;
+      XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step;
+      XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step;
+      XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step;
+      XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step;
+      oX2+=4;
+      iX+=8;
+    }while(iX<oX1);
+
+    iX=out+n2+n4;
+    oX1=out+n4;
+    oX2=oX1;
+
+    do{
+      oX1-=4;
+      iX-=4;
+
+      oX2[0] = -(oX1[3] = iX[3]);
+      oX2[1] = -(oX1[2] = iX[2]);
+      oX2[2] = -(oX1[1] = iX[1]);
+      oX2[3] = -(oX1[0] = iX[0]);
+
+      oX2+=4;
+    }while(oX2<iX);
+
+    iX=out+n2+n4;
+    oX1=out+n2+n4;
+    oX2=out+n2;
+
+    do{
+      oX1-=4;
+      oX1[0]= iX[3];
+      oX1[1]= iX[2];
+      oX1[2]= iX[1];
+      oX1[3]= iX[0];
+      iX+=4;
+    }while(oX1>oX2);
+  }
+}
Index: libavcodec/atrac3data_fixed.h
===================================================================
--- libavcodec/atrac3data_fixed.h	(revision 0)
+++ libavcodec/atrac3data_fixed.h	(revision 0)
@@ -0,0 +1,145 @@
+
+/* tables for the scalefactor decoding */
+/* scaled by 2^31*/
+static const int32_t iMaxQuant_fix[8] = {
+    0x0, 0x55555580, 0x33333340, 0x24924940, 0x1c71c720, 0x11111120, 0x8421080, 
+    0x4104108
+};
+
+/* scaled by 2^16 */
+static const int32_t SFTable_fixed[64] = {
+    0x00000800, 0x00000a14, 0x00000cb3, 0x00001000, 0x00001429, 0x00001966, 
+    0x00002000, 0x00002851, 0x000032cc, 0x00004000, 0x000050a3, 0x00006598, 
+    0x00008000, 0x0000a145, 0x0000cb30, 0x00010000, 0x0001428a, 0x00019660, 
+    0x00020000, 0x00028514, 0x00032cc0, 0x00040000, 0x00050a29, 0x00065980, 
+    0x00080000, 0x000a1452, 0x000cb2ff, 0x00100000, 0x001428a3, 0x001965ff, 
+    0x00200000, 0x00285146, 0x0032cbfd, 0x00400000, 0x0050a28c, 0x006597fb, 
+    0x00800000, 0x00a14518, 0x00cb2ff5, 0x01000000, 0x01428a30, 0x01965fea, 
+    0x02000000, 0x02851460, 0x032cbfd4, 0x04000000, 0x050a28c0, 0x06597fa8, 
+    0x08000000, 0x0a145180, 0x0cb2ff50, 0x10000000, 0x1428a300, 0x1965fea0, 
+    0x20000000, 0x28514600, 0x32cbfd40, 0x40000000, 0x50a28c00, 0x6597fa80, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000,
+};
+
+/* transform data */
+/* floating point values scaled by 2^31  */
+static const int32_t qmf_48tap_half_fix[24] = {
+    0xffff855e, 0xfffcfbca, 0xfffe28eb, 0x9de6b,    0x7f028,    0xffe40d08, 
+    0xffeef140, 0x42a692,   0x19ab1f,   0xff75dec7, 0xffe738f5, 0x100e928, 
+    0xfffdfedf, 0xfe478b84, 0x50b279,   0x2c83f88,  0xff005ad7, 0xfba2ee80, 
+    0x2685970,  0x6f42798,  0xfa6b6f10, 0xf3475f80, 0x10e7f7c0, 0x3b6c44c0 
+};
+
+/* mdct window scaled by 2^31 */
+static const int32_t window_lookup[512]  = {
+    0xffffb10c, 0xfffd394b, 0xfff8494f, 0xfff0e025, 0xffe6fc5f, 0xffda9c15, 
+    0xffcbbce6, 0xffba5bf4, 0xffa675e8, 0xff9006f0, 0xff770aba, 0xff5b7c7e, 
+    0xff3d56f2, 0xff1c9452, 0xfef92e59, 0xfed31e45, 0xfeaa5cd5, 0xfe7ee247, 
+    0xfe50a657, 0xfe1fa041, 0xfdebc6c1, 0xfdb5100d, 0xfd7b71d5, 0xfd3ee149, 
+    0xfcff5311, 0xfcbcbb49, 0xfc770d99, 0xfc2e3d15, 0xfbe23c39, 0xfb92fd29, 
+    0xfb407141, 0xfaea8989, 0xfa913661, 0xfa3467b1, 0xf9d40cd9, 0xf9701499, 
+    0xf9086d41, 0xf89d04a9, 0xf82dc7f1, 0xf7baa3e1, 0xf74384b1, 0xf6c85611, 
+    0xf6490321, 0xf5c576b1, 0xf53d9b21, 0xf4b15a01, 0xf4209ce1, 0xf38b4c71, 
+    0xf2f15171, 0xf2529411, 0xf1aefbf1, 0xf10670a1, 0xf058d941, 0xefa61cc1, 
+    0xeeee21c1, 0xee30cec1, 0xed6e0a41, 0xeca5ba61, 0xebd7c5c1, 0xeb041241, 
+    0xea2a8601, 0xe94b0861, 0xe8657f61, 0xe779d241, 0xe687e861, 0xe58fa9e1, 
+    0xe490fec1, 0xe38bd101, 0xe28009c1, 0xe16d93e1, 0xe0545ba1, 0xdf344dc1, 
+    0xde0d5881, 0xdcdf6bc1, 0xdbaa7801, 0xda6e70c1, 0xd92b4ac1, 0xd7e0fc81, 
+    0xd68f7ec1, 0xd536cd41, 0xd3d6e5c1, 0xd26fc901, 0xd10179c1, 0xcf8bff41, 
+    0xce0f6301, 0xcc8bb241, 0xcb00fdc1, 0xc96f5b01, 0xc7d6e141, 0xc637af41, 
+    0xc491e4c1, 0xc2e5a801, 0xc1332401, 0xbf7a8701, 0xbdbc0681, 0xbbf7da01, 
+    0xba2e4181, 0xb85f7f81, 0xb68bde01, 0xb4b3a981, 0xb2d73781, 0xb0f6df01, 
+    0xaf12ff01, 0xad2bfa81, 0xab423981, 0xa9562981, 0xa7683c01, 0xa578e701, 
+    0xa388a681, 0xa197f801, 0x9fa75e81, 0x9db75f01, 0x9bc88201, 0x99db5301, 
+    0x97f06001, 0x96083601, 0x94236601, 0x92427f81, 0x90661481, 0x8e8eb481, 
+    0x8cbced01, 0x8af14d81, 0x892c5f81, 0x876eab01, 0x85b8b681, 0x840b0301, 
+    0x82660c01, 0x80ca4a01, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 0x80000000, 
+    0x80ca4a01, 0x82660c01, 0x840b0301, 0x85b8b681, 0x876eab01, 0x892c5f81, 
+    0x8af14d81, 0x8cbced01, 0x8e8eb481, 0x90661481, 0x92427f81, 0x94236601, 
+    0x96083601, 0x97f06001, 0x99db5301, 0x9bc88201, 0x9db75f01, 0x9fa75e81, 
+    0xa197f801, 0xa388a681, 0xa578e701, 0xa7683c01, 0xa9562981, 0xab423981, 
+    0xad2bfa81, 0xaf12ff01, 0xb0f6df01, 0xb2d73781, 0xb4b3a981, 0xb68bde01, 
+    0xb85f7f81, 0xba2e4181, 0xbbf7da01, 0xbdbc0681, 0xbf7a8701, 0xc1332401, 
+    0xc2e5a801, 0xc491e4c1, 0xc637af41, 0xc7d6e141, 0xc96f5b01, 0xcb00fdc1, 
+    0xcc8bb241, 0xce0f6301, 0xcf8bff41, 0xd10179c1, 0xd26fc901, 0xd3d6e5c1, 
+    0xd536cd41, 0xd68f7ec1, 0xd7e0fc81, 0xd92b4ac1, 0xda6e70c1, 0xdbaa7801, 
+    0xdcdf6bc1, 0xde0d5881, 0xdf344dc1, 0xe0545ba1, 0xe16d93e1, 0xe28009c1, 
+    0xe38bd101, 0xe490fec1, 0xe58fa9e1, 0xe687e861, 0xe779d241, 0xe8657f61, 
+    0xe94b0861, 0xea2a8601, 0xeb041241, 0xebd7c5c1, 0xeca5ba61, 0xed6e0a41, 
+    0xee30cec1, 0xeeee21c1, 0xefa61cc1, 0xf058d941, 0xf10670a1, 0xf1aefbf1, 
+    0xf2529411, 0xf2f15171, 0xf38b4c71, 0xf4209ce1, 0xf4b15a01, 0xf53d9b21, 
+    0xf5c576b1, 0xf6490321, 0xf6c85611, 0xf74384b1, 0xf7baa3e1, 0xf82dc7f1, 
+    0xf89d04a9, 0xf9086d41, 0xf9701499, 0xf9d40cd9, 0xfa3467b1, 0xfa913661, 
+    0xfaea8989, 0xfb407141, 0xfb92fd29, 0xfbe23c39, 0xfc2e3d15, 0xfc770d99, 
+    0xfcbcbb49, 0xfcff5311, 0xfd3ee149, 0xfd7b71d5, 0xfdb5100d, 0xfdebc6c1, 
+    0xfe1fa041, 0xfe50a657, 0xfe7ee247, 0xfeaa5cd5, 0xfed31e45, 0xfef92e59, 
+    0xff1c9452, 0xff3d56f2, 0xff5b7c7e, 0xff770aba, 0xff9006f0, 0xffa675e8, 
+    0xffba5bf4, 0xffcbbce6, 0xffda9c15, 0xffe6fc5f, 0xfff0e025, 0xfff8494f, 
+    0xfffd394b, 0xffffb10c, 
+};
+
+/* Gain tables scaled by 2^16 */
+static const int32_t gain_tab1[16] = {
+    0x00100000, 0x00080000, 0x00040000, 0x00020000, 0x00010000, 0x00008000, 
+    0x00004000, 0x00002000, 0x00001000, 0x00000800, 0x00000400, 0x00000200, 
+    0x00000100, 0x00000080, 0x00000040, 0x00000020, 
+};
+
+static const int32_t gain_tab2[31] = {
+    0x0003ab03, 0x00035d14, 0x0003159d, 0x0002d414, 0x000297fb, 0x000260e0, 
+    0x00022e57, 0x00020000, 0x0001d582, 0x0001ae8a, 0x00018ace, 0x00016a0a, 
+    0x00014bfe, 0x00013070, 0x0001172c, 0x00010000, 0x0000eac1, 0x0000d745, 
+    0x0000c567, 0x0000b505, 0x0000a5ff, 0x00009838, 0x00008b96, 0x00008000, 
+    0x00007560, 0x00006ba2, 0x000062b4, 0x00005a82, 0x000052ff, 0x00004c1c, 
+    0x000045cb, 
+ 
+};
+
+/* Joint-Stereo related tables, scaled by 2^16 */
+static const int32_t matrixCoeffs_fix[8] = {
+    0x00000000, 0x00020000, 0x00020000, 0x00020000, 
+    0x00000000, 0x00000000, 0x00010000, 0x00010000, 
+};
+
Index: libavcodec/atrac3.c
===================================================================
--- libavcodec/atrac3.c	(revision 19667)
+++ libavcodec/atrac3.c	(working copy)
@@ -42,6 +42,9 @@
 #include "bytestream.h"

 #include "atrac3data.h"
+#include "atrac3data_fixed.h"
+#include "fixp_math.h"
+#include "fixp_mdct.h"

 #define JOINT_STEREO    0x12
 #define STEREO          0x2
@@ -61,23 +64,23 @@
 typedef struct {
     int     pos;
     int     numCoefs;
-    float   coef[8];
+    int32_t   coef[8];
 } tonal_component;

 typedef struct {
     int               bandsCoded;
     int               numComponents;
     tonal_component   components[64];
-    float             prevFrame[1024];
+    int32_t           prevFrame[1024];
     int               gcBlkSwitch;
     gain_block        gainBlock[2];

-    DECLARE_ALIGNED_16(float, spectrum[1024]);
-    DECLARE_ALIGNED_16(float, IMDCT_buf[1024]);
+    DECLARE_ALIGNED_16(int32_t, spectrum[1024]);
+    DECLARE_ALIGNED_16(int32_t, IMDCT_buf[1024]);

-    float             delayBuf1[46]; ///<qmf delay buffers
-    float             delayBuf2[46];
-    float             delayBuf3[46];
+    int32_t           delayBuf1[46]; ///<qmf delay buffers
+    int32_t           delayBuf2[46];
+    int32_t           delayBuf3[46];
 } channel_unit;

 typedef struct {
@@ -105,9 +108,9 @@
     //@}
     //@{
     /** data buffers */
-    float               outSamples[2048];
+    int32_t             outSamples[2048];
     uint8_t*            decoded_bytes_buffer;
-    float               tempBuf[1070];
+    int32_t             tempBuf[1070];
     //@}
     //@{
     /** extradata */
@@ -118,14 +121,8 @@
     //@}
 } ATRAC3Context;

-static DECLARE_ALIGNED_16(float,mdct_window[512]);
-static float            qmf_window[48];
+static int32_t          qmf_window[48];
 static VLC              spectral_coeff_tab[7];
-static float            SFTable[64];
-static float            gain_tab1[16];
-static float            gain_tab2[31];
-static MDCTContext      mdct_ctx;
-static DSPContext       dsp;


 /* quadrature mirror synthesis filter */
@@ -142,12 +139,12 @@
  */


-static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
+static void iqmf (int32_t *inlo, int32_t *inhi, unsigned int nIn, int32_t *pOut, int32_t *delayBuf, int32_t *temp)
 {
-    int   i, j;
-    float   *p1, *p3;
+    unsigned int   i, j;
+    int32_t   *p1, *p3;

-    memcpy(temp, delayBuf, 46*sizeof(float));
+    memcpy(temp, delayBuf, 46*sizeof(int32_t));

     p3 = temp + 46;

@@ -162,12 +159,12 @@
     /* loop2 */
     p1 = temp;
     for (j = nIn; j != 0; j--) {
-        float s1 = 0.0;
-        float s2 = 0.0;
+        int32_t s1 = 0;
+        int32_t s2 = 0;

         for (i = 0; i < 48; i += 2) {
-            s1 += p1[i] * qmf_window[i];
-            s2 += p1[i+1] * qmf_window[i+1];
+            s1 += fixmul31(p1[i], qmf_window[i]);
+            s2 += fixmul31(p1[i+1], qmf_window[i+1]);
         }

         pOut[0] = s2;
@@ -178,7 +175,7 @@
     }

     /* Update the delay buffer. */
-    memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
+    memcpy(delayBuf, temp + (nIn << 1), 46*sizeof(int32_t));
 }

 /**
@@ -190,10 +187,9 @@
  * @param odd_band  1 if the band is an odd band
  */

-static void IMLT(float *pInput, float *pOutput, int odd_band)
+static void IMLT(int32_t *pInput, int32_t *pOutput, int odd_band)
 {
     int     i;
-
     if (odd_band) {
         /**
         * Reverse the odd bands before IMDCT, this is an effect of the QMF transform
@@ -205,14 +201,16 @@
         */

         for (i=0; i<128; i++)
-            FFSWAP(float, pInput[i], pInput[255-i]);
+            FFSWAP(int32_t, pInput[i], pInput[255-i]);
     }
+ 
+    /* Apply the imdct. */
+    mdct_backward(512, pInput, pOutput);

-    ff_imdct_calc(&mdct_ctx,pOutput,pInput);
+    /* Windowing. */
+    for(i = 0; i<512; i++)
+        pOutput[i] = fixmul31(pOutput[i], window_lookup[i]);

-    /* Perform windowing on the output. */
-    dsp.vector_fmul(pOutput,mdct_window,512);
-
 }


@@ -244,31 +242,21 @@
 }


-static av_cold void init_atrac3_transforms(ATRAC3Context *q) {
-    float enc_window[256];
-    float s;
+static av_cold void init_atrac3_transforms(void) {
+    int32_t s;
     int i;

     /* Generate the mdct window, for details see
      * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */
-    for (i=0 ; i<256; i++)
-        enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5;

-    if (!mdct_window[0])
-        for (i=0 ; i<256; i++) {
-            mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]);
-            mdct_window[511-i] = mdct_window[i];
-        }
+    /* mdct window had been generated and saved as a lookup table in atrac3data_fixed.h */

     /* Generate the QMF window. */
     for (i=0 ; i<24; i++) {
-        s = qmf_48tap_half[i] * 2.0;
+        s = qmf_48tap_half_fix[i] << 1;
         qmf_window[i] = s;
         qmf_window[47 - i] = s;
     }
-
-    /* Initialize the MDCT transform. */
-    ff_mdct_init(&mdct_ctx, 9, 1, 1.0);
 }

 /**
@@ -353,12 +341,12 @@
  * @return outSubbands   subband counter, fix for broken specification/files
  */

-static int decodeSpectrum (GetBitContext *gb, float *pOut)
+static int decodeSpectrum (GetBitContext *gb, int32_t *pOut)
 {
     int   numSubbands, codingMode, cnt, first, last, subbWidth, *pIn;
     int   subband_vlc_index[32], SF_idxs[32];
     int   mantissas[128];
-    float SF;
+    int32_t SF;

     numSubbands = get_bits(gb, 5); // number of coded subbands
     codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
@@ -386,20 +374,20 @@
             readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth);

             /* Decode the scale factor for this subband. */
-            SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]];
+            SF = fixmul31(SFTable_fixed[SF_idxs[cnt]], iMaxQuant_fix[subband_vlc_index[cnt]]);

             /* Inverse quantize the coefficients. */
             for (pIn=mantissas ; first<last; first++, pIn++)
-                pOut[first] = *pIn * SF;
+                pOut[first] = fixmul16(*pIn, SF);
         } else {
             /* This subband was not coded, so zero the entire subband. */
-            memset(pOut+first, 0, subbWidth*sizeof(float));
+            memset(pOut+first, 0, subbWidth*sizeof(int32_t));
         }
     }

     /* Clear the subbands that were not coded. */
     first = subbandTab[cnt];
-    memset(pOut+first, 0, (1024 - first) * sizeof(float));
+    memset(pOut+first, 0, (1024 - first) * sizeof(int32_t));
     return numSubbands;
 }

@@ -417,8 +405,8 @@
     int   components, coding_mode_selector, coding_mode, coded_values_per_component;
     int   sfIndx, coded_values, max_coded_values, quant_step_index, coded_components;
     int   band_flags[4], mantissa[8];
-    float  *pCoef;
-    float  scalefactor;
+    int32_t  *pCoef;
+    int32_t  scalefactor;
     int   component_count = 0;

     components = get_bits(gb,5);
@@ -459,7 +447,7 @@
                 coded_values = coded_values_per_component + 1;
                 coded_values = FFMIN(max_coded_values,coded_values);

-                scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index];
+                scalefactor = fixmul31(SFTable_fixed[sfIndx], iMaxQuant_fix[quant_step_index]);

                 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values);

@@ -468,7 +456,7 @@
                 /* inverse quant */
                 pCoef = pComponent[component_count].coef;
                 for (cnt = 0; cnt < coded_values; cnt++)
-                    pCoef[cnt] = mantissa[cnt] * scalefactor;
+                    pCoef[cnt] = fixmul16(mantissa[cnt], scalefactor);

                 component_count++;
             }
@@ -477,7 +465,6 @@

     return component_count;
 }
-
 /**
  * Decode gain parameters for the coded bands
  *
@@ -525,21 +512,21 @@
  * @param pGain2        next band gain info
  */

-static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2)
+static void gainCompensateAndOverlap (int32_t *pIn, int32_t *pPrev, int32_t *pOut, gain_info *pGain1, gain_info *pGain2)
 {
     /* gain compensation function */
-    float  gain1, gain2, gain_inc;
+    int32_t  gain1, gain2, gain_inc;
     int   cnt, numdata, nsample, startLoc, endLoc;


     if (pGain2->num_gain_data == 0)
-        gain1 = 1.0;
+        gain1 = ONE_16;
     else
         gain1 = gain_tab1[pGain2->levcode[0]];

     if (pGain1->num_gain_data == 0) {
         for (cnt = 0; cnt < 256; cnt++)
-            pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt];
+            pOut[cnt] = fixmul16(pIn[cnt], gain1) + pPrev[cnt];
     } else {
         numdata = pGain1->num_gain_data;
         pGain1->loccode[numdata] = 32;
@@ -556,21 +543,21 @@

             /* interpolate */
             for (; nsample < startLoc; nsample++)
-                pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
+                pOut[nsample] = fixmul16((fixmul16(pIn[nsample], gain1) + pPrev[nsample]), gain2);

             /* interpolation is done over eight samples */
             for (; nsample < endLoc; nsample++) {
-                pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
-                gain2 *= gain_inc;
+                pOut[nsample] = fixmul16((fixmul16(pIn[nsample], gain1) + pPrev[nsample]),gain2);
+                gain2 = fixmul16(gain2, gain_inc);
             }
         }

         for (; nsample < 256; nsample++)
-            pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample];
+            pOut[nsample] = fixmul16(pIn[nsample], gain1) + pPrev[nsample];
     }

     /* Delay for the overlapping part. */
-    memcpy(pPrev, &pIn[256], 256*sizeof(float));
+    memcpy(pPrev, &pIn[256], 256*sizeof(int32_t));
 }

 /**
@@ -582,10 +569,11 @@
  * @param pComponent    tonal components for this band
  */

-static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
+static int addTonalComponents (int32_t *pSpectrum, int numComponents, tonal_component *pComponent)
 {
     int   cnt, i, lastPos = -1;
-    float   *pIn, *pOut;
+    int32_t *pOut;
+    int32_t *pIn;

     for (cnt = 0; cnt < numComponents; cnt++){
         lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
@@ -599,14 +587,13 @@
     return lastPos;
 }

+#define INTERPOLATE(old,new,nsample)  ((old*ONE_16) + fixmul16(((nsample*ONE_16)>>3), (((new) - (old))*ONE_16)))

-#define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
-
-static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrCode)
+static void reverseMatrixing(int32_t *su1, int32_t *su2, int *pPrevCode, int *pCurrCode)
 {
     int    i, band, nsample, s1, s2;
-    float    c1, c2;
-    float    mc1_l, mc1_r, mc2_l, mc2_r;
+    int32_t    c1, c2;
+    int32_t    mc1_l, mc1_r, mc2_l, mc2_r;

     for (i=0,band = 0; band < 4*256; band+=256,i++) {
         s1 = pPrevCode[i];
@@ -615,18 +602,18 @@

         if (s1 != s2) {
             /* Selector value changed, interpolation needed. */
-            mc1_l = matrixCoeffs[s1*2];
-            mc1_r = matrixCoeffs[s1*2+1];
-            mc2_l = matrixCoeffs[s2*2];
-            mc2_r = matrixCoeffs[s2*2+1];
+            mc1_l = matrixCoeffs_fix[s1<<1];
+            mc1_r = matrixCoeffs_fix[(s1<<1)+1];
+            mc2_l = matrixCoeffs_fix[s2<<1];
+            mc2_r = matrixCoeffs_fix[(s2<<1)+1];

             /* Interpolation is done over the first eight samples. */
             for(; nsample < 8; nsample++) {
                 c1 = su1[band+nsample];
                 c2 = su2[band+nsample];
-                c2 = c1 * INTERPOLATE(mc1_l,mc2_l,nsample) + c2 * INTERPOLATE(mc1_r,mc2_r,nsample);
+                c2 = fixmul16(c1, INTERPOLATE(mc1_l, mc2_l, nsample)) + fixmul16(c2, INTERPOLATE(mc1_r, mc2_r, nsample));
                 su1[band+nsample] = c2;
-                su2[band+nsample] = c1 * 2.0 - c2;
+                su2[band+nsample] = (c1 << 1) - c2;
             }
         }

@@ -636,8 +623,8 @@
                 for (; nsample < 256; nsample++) {
                     c1 = su1[band+nsample];
                     c2 = su2[band+nsample];
-                    su1[band+nsample] = c2 * 2.0;
-                    su2[band+nsample] = (c1 - c2) * 2.0;
+                    su1[band+nsample] = c2 << 1;
+                    su2[band+nsample] = (c1 - c2) << 1;
                 }
                 break;

@@ -645,8 +632,8 @@
                 for (; nsample < 256; nsample++) {
                     c1 = su1[band+nsample];
                     c2 = su2[band+nsample];
-                    su1[band+nsample] = (c1 + c2) * 2.0;
-                    su2[band+nsample] = c2 * -2.0;
+                    su1[band+nsample] = (c1 + c2) << 1;
+                    su2[band+nsample] = -1*(c2 << 1);
                 }
                 break;
             case 2:
@@ -664,24 +651,23 @@
     }
 }

-static void getChannelWeights (int indx, int flag, float ch[2]){
-
+static void getChannelWeights (int indx, int flag, int32_t ch[2]){
     if (indx == 7) {
-        ch[0] = 1.0;
-        ch[1] = 1.0;
+        ch[0] = ONE_16;
+        ch[1] = ONE_16;
     } else {
-        ch[0] = (float)(indx & 7) / 7.0;
-        ch[1] = sqrt(2 - ch[0]*ch[0]);
+        ch[0] = fixdiv16(((indx & 7)*ONE_16), 7*ONE_16);
+        ch[1] = fastSqrt((ONE_16 << 1) - fixmul16(ch[0], ch[0]));
         if(flag)
-            FFSWAP(float, ch[0], ch[1]);
+            FFSWAP(int32_t, ch[0], ch[1]);
     }
 }

-static void channelWeighting (float *su1, float *su2, int *p3)
+static void channelWeighting (int32_t *su1, int32_t *su2, int *p3)
 {
     int   band, nsample;
     /* w[x][y] y=0 is left y=1 is right */
-    float w[2][2];
+    int32_t w[2][2];

     if (p3[1] != 7 || p3[3] != 7){
         getChannelWeights(p3[1], p3[0], w[0]);
@@ -690,13 +676,13 @@
         for(band = 1; band < 4; band++) {
             /* scale the channels by the weights */
             for(nsample = 0; nsample < 8; nsample++) {
-                su1[band*256+nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample);
-                su2[band*256+nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample);
+                su1[band*256+nsample] = fixmul16(su1[band*256+nsample], INTERPOLATE(w[0][0], w[0][1], nsample));
+                su2[band*256+nsample] = fixmul16(su2[band*256+nsample], INTERPOLATE(w[1][0], w[1][1], nsample));
             }

             for(; nsample < 256; nsample++) {
-                su1[band*256+nsample] *= w[1][0];
-                su2[band*256+nsample] *= w[1][1];
+                su1[band*256+nsample] = fixmul16(su1[band*256+nsample], w[1][0]);
+                su2[band*256+nsample] = fixmul16(su2[band*256+nsample], w[1][1]);
             }
         }
     }
@@ -714,18 +700,17 @@
  */


-static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode)
+static int decodeChannelSoundUnit (GetBitContext *gb, channel_unit *pSnd, int32_t *pOut, int channelNum, int codingMode)
 {
     int   band, result=0, numSubbands, lastTonal, numBands;
-
     if (codingMode == JOINT_STEREO && channelNum == 1) {
         if (get_bits(gb,2) != 3) {
-            av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
+            av_log(NULL, AV_LOG_ERROR, "JS mono Sound Unit id != 3.\n");
             return -1;
         }
     } else {
         if (get_bits(gb,6) != 0x28) {
-            av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n");
+            av_log(NULL, AV_LOG_ERROR, "Sound Unit id != 0x28.\n");
             return -1;
         }
     }
@@ -757,7 +742,7 @@
         if (band <= numBands) {
             IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1);
         } else
-            memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float));
+            memset(pSnd->IMDCT_buf, 0, 512 * sizeof(int32_t));

         /* gain compensation and overlapping */
         gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]),
@@ -781,7 +766,7 @@
 static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
 {
     int   result, i;
-    float   *p1, *p2, *p3, *p4;
+    int32_t   *p1, *p2, *p3, *p4;
     uint8_t *ptr1;

     if (q->codingMode == JOINT_STEREO) {
@@ -790,7 +775,7 @@
         /* decode Sound Unit 1 */
         init_get_bits(&q->gb,databuf,q->bits_per_frame);

-        result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO);
+        result = decodeChannelSoundUnit(&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO);
         if (result != 0)
             return (result);

@@ -831,7 +816,7 @@
         }

         /* Decode Sound Unit 2. */
-        result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO);
+        result = decodeChannelSoundUnit(&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO);
         if (result != 0)
             return (result);

@@ -848,7 +833,7 @@
             /* Set the bitstream reader at the start of a channel sound unit. */
             init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels);

-            result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode);
+            result = decodeChannelSoundUnit(&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode);
             if (result != 0)
                 return (result);
         }
@@ -869,7 +854,6 @@
     return 0;
 }

-
 /**
  * Atrac frame decoding
  *
@@ -907,13 +891,13 @@
     if (q->channels == 1) {
         /* mono */
         for (i = 0; i<1024; i++)
-            samples[i] = av_clip_int16(round(q->outSamples[i]));
+            samples[i] = av_clip_int16(q->outSamples[i]);
         *data_size = 1024 * sizeof(int16_t);
     } else {
         /* stereo */
         for (i = 0; i < 1024; i++) {
-            samples[i*2] = av_clip_int16(round(q->outSamples[i]));
-            samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i]));
+            samples[i*2] = av_clip_int16(q->outSamples[i]);
+            samples[i*2+1] = av_clip_int16(q->outSamples[1024+i]);
         }
         *data_size = 2048 * sizeof(int16_t);
     }
@@ -1036,19 +1020,8 @@
         vlcs_initialized = 1;
     }

-    init_atrac3_transforms(q);
+    init_atrac3_transforms();

-    /* Generate the scale factors. */
-    for (i=0 ; i<64 ; i++)
-        SFTable[i] = pow(2.0, (i - 15) / 3.0);
-
-    /* Generate gain tables. */
-    for (i=0 ; i<16 ; i++)
-        gain_tab1[i] = powf (2.0, (4 - i));
-
-    for (i=-15 ; i<16 ; i++)
-        gain_tab2[i+15] = powf (2.0, i * -0.125);
-
     /* init the joint-stereo decoding data */
     q->weighting_delay[0] = 0;
     q->weighting_delay[1] = 7;
@@ -1063,8 +1036,6 @@
         q->matrix_coeff_index_next[i] = 3;
     }

-    dsputil_init(&dsp, avctx);
-
     q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels);
     if (!q->pUnits) {
         av_free(q->decoded_bytes_buffer);
Index: libavcodec/fixp_math.h
===================================================================
--- libavcodec/fixp_math.h	(revision 0)
+++ libavcodec/fixp_math.h	(revision 0)
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <inttypes.h>
+
+/* Macros for converting between various fixed-point representations and floating point. */
+#define ONE_16 (1L << 16)
+#define fixtof64(x)       (float)((float)(x) / (float)(1 << 16))        //does not work on int64_t!
+#define ftofix32(x)       ((int32_t)((x) * (float)(1 << 16) + ((x) < 0 ? -0.5 : 0.5)))
+#define ftofix31(x)       ((int32_t)((x) * (float)(1 << 31) + ((x) < 0 ? -0.5 : 0.5)))
+#define fix31tof64(x)     (float)((float)(x) / (float)(1 << 31))
+
+/* Fixed point math routines for use in atrac3.c */
+static inline int32_t fixmul16(int32_t x, int32_t y)
+{
+    int64_t temp;
+    temp = x;
+    temp *= y;
+
+    temp >>= 16;
+
+    return (int32_t)temp;
+}
+
+static inline int32_t fixmul31(int32_t x, int32_t y)
+{
+    int64_t temp;
+    temp = x;
+    temp *= y;
+
+    temp >>= 31;        //16+31-16 = 31 bits
+
+    return (int32_t)temp;
+}
+
+/*
+ * Fast integer square root adapted from algorithm, 
+ * Martin Guy @ UKC, June 1985.
+ * Originally from a book on programming abaci by Mr C. Woo.
+ * This is taken from :
+ * http://wiki.forum.nokia.com/index.php/How_to_use_fixed_point_maths#How_to_get_square_root_for_integers
+ * with a added shift up of the result by 8 bits to return result in 16.16 fixed-point representation.
+ */
+static inline int32_t fastSqrt(int32_t n)
+{
+   /*
+    * Logically, these are unsigned. 
+    * We need the sign bit to test
+    *	whether (op - res - one) underflowed.
+    */
+    int32_t op, res, one;
+    op = n;
+    res = 0;
+    /* "one" starts at the highest power of four <= than the argument. */
+    one = 1 << 30;	/* second-to-top bit set */
+    while (one > op) one >>= 2;
+    while (one != 0) 
+    {
+        if (op >= res + one) 
+        {
+            op = op - (res + one);
+            res = res +  (one<<1);
+        }
+        res >>= 1;
+        one >>= 2;
+    }
+    return(res << 8);
+}
+
+static inline int32_t fixdiv16(int32_t x, int32_t y)
+{
+    int64_t temp;
+    temp = x << 16;
+    temp /= y;
+
+    return (int32_t)temp;
+}