-
Notifications
You must be signed in to change notification settings - Fork 3
/
mp3frameutils.ml
1807 lines (1603 loc) · 68.6 KB
/
mp3frameutils.ml
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
(*******************************************************************************
This file is a part of mp3packer.
mp3packer is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
mp3packer 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with mp3packer; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************************)
(*
mp3packer -f -z test\aps.mp3 NUL
Before: 15.328 / 15.343
*)
open Types;;
open Mp3framehuffman;;
let get_seq = if true then Ptr.Ref.get_seq_fast else Ptr.Ref.get_seq;;
let get_huffman_c = false;;
(***********)
(* C STUBS *)
(***********)
external find_best_config_base : Ptr.t -> Ptr.t -> Ptr.t -> Ptr.t -> bool -> (int * int * int * int * int * int * int * bool) = "mfu_find_best_config_base";;
external find_best_config_sse41 : Ptr.t -> Ptr.t -> Ptr.t -> Ptr.t -> bool -> (int * int * int * int * int * int * int * bool) = "mfu_find_best_config_sse41";;
let debug_more = true;;
let tab = " ";;
(****************)
(* GLOBAL STUFF *)
(****************)
let num_quants = 576;;
(*
The lowest frequency sample of each scalefactor band is given in this table
*)
(*
let global_scalefactors sfreq is_short = match (sfreq, is_short) with
| (S48000, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 42; 50; 60; 72; 88;106;128;156;190;230;276;330;384;576 |]
| (S44100, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 44; 52; 62; 74; 90;110;134;162;196;238;288;342;418;576 |]
| (S32000, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 44; 54; 66; 82;102;126;156;194;240;296;364;448;550;576 |]
| (S24000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;114;136;162;194;232;278;332;394;464;540;576 |]
| (S22050, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S16000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S12000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S11025, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| ( S8000, false) -> [| 0;12;24;36;48;60;72;88;108;132;160;192;232;280;336;400;476;566;568;570;572;574;576 |]
| (S48000, true ) -> [| 0;4; 8;12;16;22;28;38; 50; 64; 80;100;126;192 |]
| (S44100, true ) -> [| 0;4; 8;12;16;22;30;40; 52; 66; 84;106;136;192 |]
| (S32000, true ) -> [| 0;4; 8;12;16;22;30;42; 58; 78;104;138;180;192 |]
| (S24000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;136;180;192 |]
| (S22050, true ) -> [| 0;4; 8;12;18;24;32;42; 56; 74;100;132;174;192 |]
| (S16000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| (S12000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| (S11025, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| ( S8000, true ) -> [| 0;8;16;24;36;52;72;96;124;160;162;164;166;192 |]
;;
let global_scalefactors_ptr =
let get_this a b =
let copy_array = global_scalefactors a b in
let ptr = Ptr.make (2 * Array.length copy_array) 0 in
Array.iteri (fun i q -> Ptr.put_16_of_int ptr (2 * i) q) copy_array;
ptr
in
let long48000 = get_this S48000 false in
let long44100 = get_this S44100 false in
let long32000 = get_this S32000 false in
let long24000 = get_this S24000 false in
let long22050 = get_this S22050 false in
let long16000 = get_this S16000 false in
let long12000 = get_this S12000 false in
let long11025 = get_this S11025 false in
let long8000 = get_this S8000 false in
let short48000 = get_this S48000 true in
let short44100 = get_this S44100 true in
let short32000 = get_this S32000 true in
let short24000 = get_this S24000 true in
let short22050 = get_this S22050 true in
let short16000 = get_this S16000 true in
let short12000 = get_this S12000 true in
let short11025 = get_this S11025 true in
let short8000 = get_this S8000 true in
fun sfreq is_short -> match (sfreq, is_short) with
| (S48000, false) -> long48000
| (S44100, false) -> long44100
| (S32000, false) -> long32000
| (S24000, false) -> long24000
| (S22050, false) -> long22050
| (S16000, false) -> long16000
| (S12000, false) -> long12000
| (S11025, false) -> long11025
| ( S8000, false) -> long8000
| (S48000, true ) -> short48000
| (S44100, true ) -> short44100
| (S32000, true ) -> short32000
| (S24000, true ) -> short24000
| (S22050, true ) -> short22050
| (S16000, true ) -> short16000
| (S12000, true ) -> short12000
| (S11025, true ) -> short11025
| ( S8000, true ) -> short8000
;;
*)
let global_scalefactors : type id. id samplerate_t -> bool -> int array = fun s_freq is_short -> match (s_freq, is_short) with
| (S48000, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 42; 50; 60; 72; 88;106;128;156;190;230;276;330;384;576 |]
| (S44100, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 44; 52; 62; 74; 90;110;134;162;196;238;288;342;418;576 |]
| (S32000, false) -> [| 0; 4; 8;12;16;20;24;30; 36; 44; 54; 66; 82;102;126;156;194;240;296;364;448;550;576 |]
| (S24000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;114;136;162;194;232;278;332;394;464;540;576 |]
| (S22050, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S16000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S12000, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| (S11025, false) -> [| 0; 6;12;18;24;30;36;44; 54; 66; 80; 96;116;140;168;200;238;284;336;396;464;522;576 |]
| ( S8000, false) -> [| 0;12;24;36;48;60;72;88;108;132;160;192;232;280;336;400;476;566;568;570;572;574;576 |]
| (S48000, true ) -> [| 0;4; 8;12;16;22;28;38; 50; 64; 80;100;126;192 |]
| (S44100, true ) -> [| 0;4; 8;12;16;22;30;40; 52; 66; 84;106;136;192 |]
| (S32000, true ) -> [| 0;4; 8;12;16;22;30;42; 58; 78;104;138;180;192 |]
| (S24000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;136;180;192 |]
| (S22050, true ) -> [| 0;4; 8;12;18;24;32;42; 56; 74;100;132;174;192 |]
| (S16000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| (S12000, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| (S11025, true ) -> [| 0;4; 8;12;18;26;36;48; 62; 80;104;134;174;192 |]
| ( S8000, true ) -> [| 0;8;16;24;36;52;72;96;124;160;162;164;166;192 |]
;;
(* NOTE: for some reason I can't add these before a closure in the function, so I have to pollute the module's namespace *)
let gsf_get_this : type id. id samplerate_t -> _ = fun a b ->
let copy_array = global_scalefactors a b in
let ptr = Ptr.make (2 * Array.length copy_array) 0 in
Array.iteri (fun i q -> Ptr.put_16_of_int ptr (2 * i) q) copy_array;
ptr
;;
let gsf_long48000 = gsf_get_this S48000 false;;
let gsf_long44100 = gsf_get_this S44100 false;;
let gsf_long32000 = gsf_get_this S32000 false;;
let gsf_long24000 = gsf_get_this S24000 false;;
let gsf_long22050 = gsf_get_this S22050 false;;
let gsf_long16000 = gsf_get_this S16000 false;;
let gsf_long12000 = gsf_get_this S12000 false;;
let gsf_long11025 = gsf_get_this S11025 false;;
let gsf_long8000 = gsf_get_this S8000 false;;
let gsf_short48000 = gsf_get_this S48000 true;;
let gsf_short44100 = gsf_get_this S44100 true;;
let gsf_short32000 = gsf_get_this S32000 true;;
let gsf_short24000 = gsf_get_this S24000 true;;
let gsf_short22050 = gsf_get_this S22050 true;;
let gsf_short16000 = gsf_get_this S16000 true;;
let gsf_short12000 = gsf_get_this S12000 true;;
let gsf_short11025 = gsf_get_this S11025 true;;
let gsf_short8000 = gsf_get_this S8000 true;;
let global_scalefactors_ptr : type id. id samplerate_t -> bool -> Ptr.t = fun a b ->
match (a,b) with
| (S48000, false) -> gsf_long48000
| (S44100, false) -> gsf_long44100
| (S32000, false) -> gsf_long32000
| (S24000, false) -> gsf_long24000
| (S22050, false) -> gsf_long22050
| (S16000, false) -> gsf_long16000
| (S12000, false) -> gsf_long12000
| (S11025, false) -> gsf_long11025
| (S8000 , false) -> gsf_long8000
| (S48000, true ) -> gsf_short48000
| (S44100, true ) -> gsf_short44100
| (S32000, true ) -> gsf_short32000
| (S24000, true ) -> gsf_short24000
| (S22050, true ) -> gsf_short22050
| (S16000, true ) -> gsf_short16000
| (S12000, true ) -> gsf_short12000
| (S11025, true ) -> gsf_short11025
| (S8000 , true ) -> gsf_short8000
;;
type block_type_t = Block_type_long | Block_type_short | Block_type_start | Block_type_stop;;
type window_normal_t = {
normal_table_select1 : int; (* Which Huffman table to use for each region *)
normal_table_select2 : int; (* etc *)
normal_table_select3 : int; (* etc *)
normal_region_0_count : int; (* How many values are in the first region (starting from lowest freq) *)
normal_region_1_count : int; (* Ditto for the next higher region (region_2_count is implicit because big_values is known beforehand) *)
};;
type window_other_t = {
other_block_type : block_type_t; (* 01 = 1 long block start window. 10 = 3 short blocks. 11 = 1 long block stop window. 00 = invalid *)
other_mixed_block : bool; (* 0 = normal. 1 = lower 2 subbands are long, upper 30 subbands are short (for block_type = 10) *)
other_table_select1 : int; (* Which Huffman table to use for the particular region (regions are implicit) *)
other_table_select2 : int; (* Ditto (note that there is no region3) *)
other_sub_block_gain1 : int; (* Offset from the global gain of each short block, if Block_type = 10. Otherwise not used *)
other_sub_block_gain2 : int; (* Same for next short block *)
other_sub_block_gain3 : int; (* etc *)
};;
(* gc = granule-channel *)
type gc_window_t = Window_normal of window_normal_t | Window_other of window_other_t;;
type side_gc_t = {
gc_part2_3_length : int; (* Length in bits of parts 2 (scalefactors) and 3 (Huffman encoded data) *)
gc_part2_3_offset : int; (* The integral of the previous part2_3_lengths *)
gc_big_values : int; (* Half the number of frequency bands (starting from lowest freq) whose absolute values are greater than 1 *)
gc_global_gain : int; (* Logarithmic encoding of the global gain value *)
(* xxxxxxxx11111111111111110000000000000000000000 *)
(* | | | *)
(* bigvalues*2 bv*2+count1*4 576 *)
(* Everything in "0" region is 0 *)
(* Everything in "1" region is -1, 0, or +1 *)
(* "x" can be anything *)
gc_scf_compress_index : int; (* An index determining the number of bits to use for the scale factors (For MPEG1) *)
gc_window : gc_window_t; (* 0 = granule / channel has only 1 block and a normal window. 1 = something else *)
gc_pre_flag : bool; (* High-frequency amplification shortcut; not used for MPEG2/2.5 *)
gc_sf_scale : int; (* Which Huffman table to use for scalefactor scaling *)
gc_count1_table_1 : bool; (* true if table 1 is used for the Count1 region, false if 0 *)
}
type (_,_) side_gc_selector_t =
| GC_1_mono : side_gc_t * side_gc_t -> (mpeg1_t, channel_mono_t) side_gc_selector_t
| GC_1_stereo : side_gc_t * side_gc_t * side_gc_t * side_gc_t -> (mpeg1_t, channel_stereo_t) side_gc_selector_t
| GC_2_mono : side_gc_t -> (_ mpeg2_t, channel_mono_t) side_gc_selector_t
| GC_2_stereo : side_gc_t * side_gc_t -> (_ mpeg2_t, channel_stereo_t) side_gc_selector_t
;;
type (_,_) side_scfi_t =
| SCFI_none : (_ mpeg2_t, _) side_scfi_t
| SCFI_mono : (bool * bool * bool * bool) -> (mpeg1_t, channel_mono_t) side_scfi_t
| SCFI_stereo : (bool * bool * bool * bool) * (bool * bool * bool * bool) -> (mpeg1_t, channel_stereo_t) side_scfi_t
;;
let no_scfi = (false,false,false,false);;
let print_scfi (a,b,c,d) p =
p (Char '(');
p (Char (if a then '#' else '.'));
p (Char (if b then '#' else '.'));
p (Char (if c then '#' else '.'));
p (Char (if d then '#' else '.'));
p (Char ')');
;;
type ('id,'chan) side_internal_t = {
side_main_data_begin : int;
side_scfi : ('id,'chan) side_scfi_t; (* side_scfi.(channel).(scfi band) 0 = Scale factors are transmitted for each granule. 1 = One scalefactor is for both granules. Note that there are 4 scale factor bands. *)
side_gc : ('id,'chan) side_gc_selector_t; (* (gr0ch0, gr0ch1, gr1ch0, gr1ch1) *)
};;
type side_internal_ext_t = Side_int_ext : ('id,'chan) side_internal_t -> side_internal_ext_t;;
(*
The number of bits to use in the (low,high) frequencies of the scalefactors.
Most of the time, the first number corresponds to the first 11 scalefactors and the last number is for the last 10 scalefactors
Note that the last scalefactor band (#22) does not have its own scalefactor
*)
let scalefactor_compress_m1 = [|
(0,0);
(0,1);
(0,2);
(0,3);
(3,0);
(1,1);
(1,2);
(1,3);
(2,1);
(2,2);
(2,3);
(3,1);
(3,2);
(3,3);
(4,2);
(4,3);
|];;
(* This is used with MPEG2, for everything except the right channel in IS frames *)
let scalefactor_compress_m2 = Array.init 512 (fun i ->
if i < 400 then (
((i lsr 4 / 5), (i lsr 4 mod 5), ((i land 15) lsr 2), (i land 3))
) else if i < 500 then (
let j = i - 400 in
((j lsr 2 / 5), (j lsr 2 mod 5), (j land 3), (0))
) else (
let j = i - 500 in
((j / 3), (j mod 3), (0), (0))
)
);;
(* Only for the right channel in IS frames *)
let scalefactor_compress_m2_is = Array.init 512 (fun q ->
let i = q lsr 1 in
if i < 180 then (
((i / 36), (i mod 36 / 6), (i mod 6), 0)
) else if i < 244 then (
let j = i - 180 in
((j land 63) lsr 4, (j land 15) lsr 2, j land 3, 0)
) else (
let j = i - 244 in
(j / 3, j mod 3, 0, 0)
)
);;
let scalefactor_bands_m2 is gc =
if is then (
if gc.gc_scf_compress_index < 360 then (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (6,15,12,0)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (12,12,12,0)
| _ -> (7,7,7,0)
) else if gc.gc_scf_compress_index < 488 then (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (6,12,9,6)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (12,9,9,6)
| _ -> (6,6,6,3)
) else (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (6,18,9,0)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (15,12,9,0)
| _ -> (8,8,5,0)
)
) else (
if gc.gc_scf_compress_index < 400 then (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (6,9,9,9)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (9,9,9,9)
| _ -> (6,5,5,5)
) else if gc.gc_scf_compress_index < 500 then (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (6,9,12,6)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (9,9,12,6)
| _ -> (6,5,7,3)
) else (
match gc with
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = true}} -> (15,18,0,0)
| {gc_window = Window_other {other_block_type = Block_type_short; other_mixed_block = false}} -> (18,18,0,0)
| _ -> (11,10,0,0)
)
)
;;
(************************)
(* Frame internal types *)
(************************)
type _ m1_scalefactors_t =
| M1_scalefactors_mono : int array * int array -> channel_mono_t m1_scalefactors_t
| M1_scalefactors_stereo : int array * int array * int array * int array -> channel_stereo_t m1_scalefactors_t
;;
type _ m1_quantizers_t =
| M1_quantizers_mono : Ptr.t * Ptr.t -> channel_mono_t m1_quantizers_t
| M1_quantizers_stereo : Ptr.t * Ptr.t * Ptr.t * Ptr.t -> channel_stereo_t m1_quantizers_t
;;
type 'chan m1_frame_data_t = {
m1_header : (mpeg1_t, 'chan) header_t; (* Do I need this? *)
m1_side_info : (mpeg1_t, 'chan) side_internal_t;
m1_scalefactors : 'chan m1_scalefactors_t; (* m1_scalefactors.(granule).(channel).(scalefactor) *)
(* m1_quantizers : int array array array; (* m1_quantizers.(granule).(channel).(quantizer) *)*)
m1_quantizer_ptrs : 'chan m1_quantizers_t; (* Ptr.t = int16 array *)
m1_starting_f1 : (mpeg1_t, 'chan) f1_t;
};;
type _ m2_scalefactors_t =
| M2_scalefactors_mono : int array -> channel_mono_t m2_scalefactors_t
| M2_scalefactors_stereo : int array * int array -> channel_stereo_t m2_scalefactors_t
;;
type _ m2_quantizers_t =
| M2_quantizers_mono : Ptr.t -> channel_mono_t m2_quantizers_t
| M2_quantizers_stereo : Ptr.t * Ptr.t -> channel_stereo_t m2_quantizers_t
;;
type ('id2,'chan) m2_frame_data_t = {
m2_header : ('id2 mpeg2_t, 'chan) header_t;
m2_side_info : ('id2 mpeg2_t, 'chan) side_internal_t;
m2_scalefactors : 'chan m2_scalefactors_t; (* m2_scalefactors.(channel).(scalefactor) *)
(* m2_quantizers : int array array; (* m2_quantizers.(channel).(quantizer) *)*)
m2_quantizer_ptrs : 'chan m2_quantizers_t;
m2_starting_f1 : ('id2 mpeg2_t, 'chan) f1_t;
};;
type (_,_) frame_data_t =
| M1_frame_data : 'chan m1_frame_data_t -> (mpeg1_t, 'chan) frame_data_t
| M2_frame_data : ('id2,'chan) m2_frame_data_t -> ('id2 mpeg2_t, 'chan) frame_data_t
;;
(*let print_side pin spaces s = ();;*)
let print_side : type id chan. (Types.p_type list -> unit) -> int -> (id,chan) side_internal_t -> unit = fun pin spaces s ->
let p x = pin (Spaces spaces :: x) in
p [Str "Main data begin: "; Int s.side_main_data_begin];
p [Fun (fun print ->
print (Str "SCFI each granule:");
(* print (Str "(later)");*)
match s.side_scfi with
| SCFI_none -> print (Str " none (MPEG2)")
| SCFI_mono scfi -> (print (Char ' '); print_scfi scfi print)
| SCFI_stereo (scfi_ch0, scfi_ch1) -> (print (Char ' '); print_scfi scfi_ch0 print; print (Char ' '); print_scfi scfi_ch1 print)
(*
Array.iter (fun gr ->
print (Str " (");
Array.iter (function
| true -> print (Char '#')
| false -> print (Char '.')
) gr;
print (Str ")");
) s.side_scfi;
*)
)];
p [Str "Granule / channel info:"];
let pgrch gr ch gc =
p [Str " Granule "; Int gr; Str ":"];
p [Str " Channel "; Int ch; Str ":"];
p [Str " Part2_3: "; Int gc.gc_part2_3_length; Str " (offset "; Int gc.gc_part2_3_offset; Str ")"];
p [Str " big_values: "; Int gc.gc_big_values];
p [Str " global_gain: "; Int gc.gc_global_gain];
p [Str " scf_comp_i: "; Int gc.gc_scf_compress_index];
(match gc.gc_window with
| Window_normal w -> (
p [Str " Normal window"];
p [Str " Tables: "; Int w.normal_table_select1; Str ","; Int w.normal_table_select2; Str ","; Int w.normal_table_select3];
p [Str " Region 0,1: "; Int w.normal_region_0_count; Str ","; Int w.normal_region_1_count];
)
| Window_other w -> (
p [Str " Other window"];
p [Str " Block type: "; Str (match w.other_block_type with
| Block_type_long -> "INVALID!"
| Block_type_short -> "Short"
| Block_type_start -> "Start"
| Block_type_stop -> "Stop"
)];
p [Str " Mixed block? "; Bool w.other_mixed_block];
p [Str " Tables: "; Int w.other_table_select1; Str ","; Int w.other_table_select2];
p [Str " Sub block gain: "; Int w.other_sub_block_gain1; Str ","; Int w.other_sub_block_gain2; Str ","; Int w.other_sub_block_gain3];
)
);
p [Str " HF amp: "; Bool gc.gc_pre_flag];
p [Str " SF scale: "; Int gc.gc_sf_scale];
p [Str " Count1 table "; Int (if gc.gc_count1_table_1 then 1 else 0)];
in
match s.side_gc with
| GC_1_mono (a,b) -> (pgrch 0 0 a; pgrch 1 0 b)
| GC_1_stereo (a,b,c,d) -> (pgrch 0 0 a; pgrch 0 1 b; pgrch 1 0 c; pgrch 1 1 d)
| GC_2_mono (a) -> (pgrch 0 0 a)
| GC_2_stereo (a,b) -> (pgrch 0 0 a; pgrch 0 1 b)
;;
(*
(* Frame printing functions *)
let print_side pin spaces s =
(* let p = Printf.printf in*)
(*
let p = (
let h f = Printf.printf "%s%s" tabs f in
fun a -> Printf.kprintf h a
) in
*)
let p x = pin (Spaces spaces :: x) in
()
(** TODO: later
p "Main data begin: %d\n" s.side_main_data_begin;
p "SCFI each granule:";
Array.iter (fun n -> Printf.printf " ("; Array.iter (fun q -> Printf.printf "%s" (if q then "#" else ".")) n; Printf.printf ")") s.side_scfi;
p "\n";
p "Granule / channel info:\n";
Array.iteri (fun i granule ->
p " Granule %d:\n" i;
Array.iteri (fun j gc ->
p " Channel %d:\n" j;
p " Part2_3: %d (offset %d)\n" gc.gc_part2_3_length gc.gc_part2_3_offset;
p " big_values: %d\n" gc.gc_big_values;
p " global_gain: %d\n" gc.gc_global_gain;
p " scf_comp_i: %d\n" gc.gc_scf_compress_index;
(match gc.gc_window with
| Window_normal w -> (
p " Normal window\n";
p " Tables: %d,%d,%d\n" w.normal_table_select1 w.normal_table_select2 w.normal_table_select3;
p " Region 0,1: %d,%d\n" w.normal_region_0_count w.normal_region_1_count;
)
| Window_other w -> (
p " Other window\n";
p " Block type: %s\n" (match w.other_block_type with
| Block_type_long -> "INVALID!"
| Block_type_short -> "Short"
| Block_type_start -> "Start"
| Block_type_stop -> "Stop"
);
p " Mixed block? %b\n" w.other_mixed_block;
p " Tables: %d,%d\n" w.other_table_select1 w.other_table_select2;
p " Sub block gain: %d,%d,%d\n" w.other_sub_block_gain1 w.other_sub_block_gain2 w.other_sub_block_gain3;
)
);
p " HF amp: %b\n" gc.gc_pre_flag;
p " SF scale: %d\n" gc.gc_sf_scale;
p " Count1 table %d\n" (if gc.gc_count1_table_1 then 1 else 0);
) granule;
) s.side_gc;
*)
;;
*)
(*
Side info:
9/17/32 BYTES = 136/256 bits
9: main_data_begin (8 for MPEG2)
?: private_bits
4: SCFI Band
59: Side Information Granule
12: part2_3 length (main data for this channel, granule in bits)
9: Big values
8: Global gain
4: Scalefactor compress (9 for MPEG2)
1: Window switch flag
if 1:
2: Block type
1: Mix block flag
5x2: Table Select [region]
3x3: sub_block_gain [window]
if 0:
5x3: Table select [region]
4: Region 0 count
3: Region 1 count
1: Pre flag (NOT FOR MPEG2)
1: Scale factor scale
1: Count1 table select
MPEG1 mono:
[9 main data] [5 privates] [4 SCFI] [59 Gr0] [59 Gr1]
(18 - 30) (77 - 89)
MPEG1 stereo:
[9 main data] [3 privates] [4 SCFI0] [4 SCFI1] [59 Gr0ch1] [59 Gr0ch2] [59 Gr1ch1] [59 Gr1ch2]
20 79 138 197
MPEG2 mono:
[8 main data] [1 privates] [63 Gr*]
(9 - 21)
MPEG2 stereo:
[8 main data] [2 privates] [63 Gr*ch1] [63 Gr*ch2]
(10 - 22) (73 - 85)
*)
(*******************)
(* READ QUANTIZERS *)
(*******************)
(* It ends when r_at = r_to *)
let read_quantizers state file_state k gc in_ptr r_at r_to =
let p = state.q_print_recompress in
let s = Ptr.Ref.new_seq (Ptr.Ref.of_ptr in_ptr) in
Ptr.Ref.set_seq s r_at;
(*let debug = false in*)
if state.q_debug_recompress then (
(* p [Str "Starting on %S at %d, going to %d\n" (String.sub (to_bin (Ptr.Ref.to_string s.Ptr.Ref.seq_ref)) s.Ptr.Ref.seq_at (r_to - s.Ptr.Ref.seq_at)) s.Ptr.Ref.seq_at r_to;*)
let str = String.sub (to_bin (Ptr.Ref.to_string s.Ptr.Ref.seq_ref)) s.Ptr.Ref.seq_at (r_to - s.Ptr.Ref.seq_at) in
p [Str "Starting on "; Str str; Str " at "; Int s.Ptr.Ref.seq_at; Str ", going to "; Int r_to];
);
let decoder_error_ref = ref false in
(* let out_quants = Array.make num_quants 0 in*)
let out_quants_16_ptr = Ptr.make (num_quants * 2) 16 in
let (region0, region1, region2, table0, table1, table2) = (match gc.gc_window with
| Window_normal w -> (
let scfend0 = w.normal_region_0_count + 1 in
let scfend1 = w.normal_region_1_count + 1 + scfend0 in
let region0 = min gc.gc_big_values ((global_scalefactors k.header_samplerate false).(scfend0) lsr 1) in
let region1 = min gc.gc_big_values ((global_scalefactors k.header_samplerate false).(scfend1) lsr 1) - region0 in
(region0, region1, gc.gc_big_values - region0 - region1, w.normal_table_select1, w.normal_table_select2, w.normal_table_select3)
)
| Window_other w -> (
let region0 = if w.other_block_type = Block_type_short && not w.other_mixed_block then (
(global_scalefactors k.header_samplerate true).(9 / 3) lsr 1 * 3
) else (
(global_scalefactors k.header_samplerate false).(8) lsr 1
) in
(min region0 gc.gc_big_values, max 0 (gc.gc_big_values - region0), 0, w.other_table_select1, w.other_table_select2, 0)
)
) in
p [
Str " L = (";
Int region0; Str ","; Int region1; Str ","; Int region2; Str "), ht = (";
Int table0; Str ","; Int table1; Str ","; Int table2; Str ")"
];
let index =
let (overboard, new_ptr_loc, new_index) = Mp3framehuffman.decode_all_quants in_ptr s.Ptr.Ref.seq_at out_quants_16_ptr r_to (region0 * 2) table0 (region1 * 2) table1 (region2 * 2) table2 num_quants gc.gc_count1_table_1 decoder_error_ref in
p [Str "Got new index "; Int new_index; Str " at bit pos "; Int new_ptr_loc; Str " after all quants decoded"];
if new_ptr_loc > r_to then (
p [Str "OOPS! decode_all_quants went overboard (bit "; Int new_ptr_loc; Str " > target "; Int r_to; Str ")"];
decoder_error_ref := true;
);
Ptr.Ref.set_seq s new_ptr_loc;
if overboard then (
p [Str " Num_quants exceeded"];
if file_state#freq_warn then (
(* calling #freq_warn will automatically turn it off for future frames *)
P.print_always [Str "WARNING: too many frequencies; files may be decoded differently by some players"]
)
);
new_index
in
for i = index to num_quants - 1 do
Ptr.put_16_of_int out_quants_16_ptr (2 * i) 0;
done;
(*
if s.Ptr.Ref.seq_at > r_to then (
p [Str " OOPS! Decoding count1 went a little overboard (pos "; Int s.Ptr.Ref.seq_at; Str " > "; Int r_to; Str ")"];
decoder_error_ref := true;
);
*)
if state.q_debug_recompress then (
(*
Printf.printf "%sREAD_QUANTIZERS_M1: (%d) - [" tabs index;
for i = 0 to num_quants - 1 do
Printf.printf " %d" (Ptr.get_int_of_16 out_quants_16_ptr (2 * i));
done;
Printf.printf " ]\n";
*)
p [
Str " READ_QUANTIZERS: ("; Int index; Str ") - [";
Fun (fun print -> for i = 0 to num_quants - 1 do
print (Str " ");
print (Int (Ptr.get_int_of_16 out_quants_16_ptr (2 * i)));
done);
Str " ]"
];
);
(out_quants_16_ptr, !decoder_error_ref)
;;
(*********************)
(* READ SCALEFACTORS *)
(*********************)
let read_scalefactors_m1 state scfi_tuple prev_scf_option gc s file_state k in_ptr =
let (scfia,scfib,scfic,scfid) = scfi_tuple in
let p = state.q_print_recompress in
let make_initial_array = match (prev_scf_option, scfi_tuple) with
| (None, _) -> (fun x -> Array.make x 0)
| (Some _, (false,false,false,false)) -> (fun x -> Array.make x 0) (* If scfi indicates to not use anything from previous frame, just recreate the array. This helps for short blocks, when the array is the wrong length anyway *)
| (Some y, _) -> (fun x -> Array.sub y 0 x)
in
let (bits1,bits2) = scalefactor_compress_m1.(gc.gc_scf_compress_index) in
let (num1,num2,scf_out) = match gc.gc_window with
| Window_normal _ -> (
(* Normal *)
(11, 10, make_initial_array 21)
)
| Window_other x when x.other_block_type <> Block_type_short -> (
(* Start or stop (actually the same as normal) *)
(11, 10, make_initial_array 21)
)
| Window_other x when x.other_mixed_block -> (
(* Short, mixed block *)
(17, 18, make_initial_array 35) (* Mixed blocks seem to have 36 scalefactors, but only 33 scalefactor bands. However, the way the windows are set up, there are a total of 35 scalefactor scales *)
)
| Window_other _ -> (
(* Short block *)
(18, 18, make_initial_array 36) (* Short blocks have 39 scalefactors, but only 36 scalefactor bands *)
)
in
(* Perhaps I should check for short frames somewhere? Or maybe just assume that the file has SCFSI set to false for short frames already *)
let rec read_stuff i = (
let num_bits = if i < num1 then bits1 else bits2 in
p [Str "reading "; Int num_bits; Str " bits from "; Int s.Ptr.Ref.seq_at; Str " (len "; Int s.Ptr.Ref.seq_ref.Ptr.Ref.lentot; Str " bytes)"];
p [Str "seq fast is "; Hex (8,s.Ptr.Ref.seq_get_fast_int); Str ", next bytes is "; Int s.Ptr.Ref.seq_get_fast_next_byte];
if i >= Array.length scf_out then (
p [Str "!"];
) else if i < 6 then (
if not scfia then (scf_out.(i) <- get_seq s num_bits; p [Str "0: "; Int scf_out.(i)]);
read_stuff (succ i)
) else if i < 11 then (
if not scfib then (scf_out.(i) <- get_seq s num_bits; p [Str "1: "; Int scf_out.(i)]);
read_stuff (succ i)
) else if i < 16 then (
if not scfic then (scf_out.(i) <- get_seq s num_bits; p [Str "2: "; Int scf_out.(i)]);
read_stuff (succ i)
) else if i < 21 then (
if not scfid then (scf_out.(i) <- get_seq s num_bits; p [Str "3: "; Int scf_out.(i)]);
read_stuff (succ i)
) else (
scf_out.(i) <- get_seq s num_bits; p [Str "+: "; Int scf_out.(i)];
read_stuff (succ i)
)
) in
read_stuff 0;
(* read_stuff_s s 0;*)
(* if debug && debug_more then Printf.printf "\n";*)
(* if debug then Printf.printf "SCF compress (%d,%d)\n" bits1 bits2;*)
p [
Str " READ_SCALEFACTORS_M1: ("; Int bits1; Str ","; Int bits2; Str ")="; Int num1; Str ","; Int num2; Str " - [";
Fun (fun print -> Array.iter (fun n -> print (Str " "); print (Int n)) scf_out);
Str " ] ";
(* Fun (fun print -> Array.iter (fun n -> print (Str (if n then "#" else "."))) scfi)*)
Fun (print_scfi scfi_tuple)
]; (*tabs bits1 bits2 num1 num2 (Array.fold_left (fun so_far gnu -> so_far ^ " " ^ (string_of_int gnu)) "" scf_out);*)
(* if debug then Array.iter (fun q -> Printf.printf "%s" (if q then "#" else ".")) scfi;*)
(* if debug then Printf.printf "\n";*)
let r_to = gc.gc_part2_3_length + gc.gc_part2_3_offset in
let (qp,error) = read_quantizers state file_state k gc in_ptr s.Ptr.Ref.seq_at r_to in
(scf_out, qp, error)
;;
let read_scalefactors_m2 state is gc s =
let p = state.q_print_recompress in
let (bits0, bits1, bits2, bits3) = if is then (
scalefactor_compress_m2_is.(gc.gc_scf_compress_index)
) else (
scalefactor_compress_m2.(gc.gc_scf_compress_index)
) in
let (num0, num1, num2, num3) = scalefactor_bands_m2 is gc in
let sob1 = num0 in
let sob2 = sob1 + num1 in
let sob3 = sob2 + num2 in
let num_total = sob3 + num3 in
let scf_out = Array.make num_total 0 in
(*
let rec read_stuff i = (
if i < sob1 then (
scf_out.(i) <- get_seq s bits0; if debug && debug_more then Printf.printf "0";
read_stuff (succ i)
) else if i < sob2 then (
scf_out.(i) <- get_seq s bits1; if debug && debug_more then Printf.printf "1";
read_stuff (succ i)
) else if i < sob3 then (
scf_out.(i) <- get_seq s bits2; if debug && debug_more then Printf.printf "2";
read_stuff (succ i)
) else if i < num_total then (
scf_out.(i) <- get_seq s bits3; if debug && debug_more then Printf.printf "3";
read_stuff (succ i)
) else (
if debug && debug_more then Printf.printf "!";
)
) in
read_stuff 0;
*)
for i = 0 to sob1 - 1 do
scf_out.(i) <- get_seq s bits0;
(* if debug && debug_more then Printf.printf "0";*)
done;
for i = sob1 to sob2 - 1 do
scf_out.(i) <- get_seq s bits1;
(* if debug && debug_more then Printf.printf "1";*)
done;
for i = sob2 to sob3 - 1 do
scf_out.(i) <- get_seq s bits2;
(* if debug && debug_more then Printf.printf "2";*)
done;
for i = sob3 to num_total - 1 do
scf_out.(i) <- get_seq s bits3;
(* if debug && debug_more then Printf.printf "3";*)
done;
(* if debug && debug_more then Printf.printf "!\n";*)
if state.q_debug_recompress then (
let pf from count print =
for i = from to from + count - 1 do
print (Str " ");
print (Int scf_out.(i));
done
in
p [
Str " READ_SCALEFACTORS_M2: ("; Int bits0; Str ","; Int bits1; Str ","; Int bits2; Str ","; Int bits3;
Str ")="; Int num0; Str ","; Int num1; Str ","; Int num2; Str ","; Int num3;
Str " - ["; Fun (pf 0 num0);
Str " ]-["; Fun (pf sob1 num1);
Str " ]-["; Fun (pf sob2 num2);
Str " ]-["; Fun (pf sob3 num3);
Str " ]";
]
);
(*
if debug then (
let str0 = Array.fold_left (fun so_far gnu -> so_far ^ " " ^ (string_of_int gnu)) "" (Array.sub scf_out 0 num0) in
let str1 = Array.fold_left (fun so_far gnu -> so_far ^ " " ^ (string_of_int gnu)) "" (Array.sub scf_out sob1 num1) in
let str2 = Array.fold_left (fun so_far gnu -> so_far ^ " " ^ (string_of_int gnu)) "" (Array.sub scf_out sob2 num2) in
let str3 = Array.fold_left (fun so_far gnu -> so_far ^ " " ^ (string_of_int gnu)) "" (Array.sub scf_out sob3 num3) in
Printf.printf "%sREAD_SCALEFACTORS_M2: (%d,%d,%d,%d)=%d,%d,%d,%d - [%s ]-[%s ]-[%s ]-[%s ]\n" tabs bits0 bits1 bits2 bits3 num0 num1 num2 num3 str0 str1 str2 str3;
);
*)
scf_out
;;
(************************************************************************************************************************)
(* REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME REHUFF FRAME *)
(************************************************************************************************************************)
let rehuff_granule state (quant_ptr : Ptr.t) (*process_function*) gc (scf_bands_ptr : Ptr.t) = match gc.gc_window with
| Window_other _ -> gc
| Window_normal _ -> (
let p = state.q_print_recompress in
let process_function = match state.q_process_set with
| SSE41 -> find_best_config_sse41
| Set_base -> find_best_config_base
in
let (s_l1,s_l2,s_big,(*s_count1num : int*)_,s_t1,s_t2,s_t3,p1t1) = (
(*let (s_l1,s_l2,s_big,s_count1num,s_t1,s_t2,s_t3,p1t1) =*) process_function
quant_bits_ptr16
quant_bits_count1_char_ptr
scf_bands_ptr
quant_ptr
false (* Don't use the debug stuff yet *)
(*in
(s_l1,s_l2,s_big,s_count1num,s_t1,s_t2,s_t3,p1t1)*)
) in
(* let (s_l1,s_l2,s_big,s_t1,s_t2,s_t3,p1t1) = smallest_config in*)
if state.q_debug_recompress then (
p [Str " NEW: ("; Int s_l1; Str ","; Int s_l2; Str ","; Int s_big; Str ","; Int s_t1; Str ","; Int s_t2; Str ","; Int s_t3; Str ","; Bool p1t1; Str ")"];
);
{gc with
gc_big_values = s_big;
gc_window = Window_normal {normal_table_select1 = s_t1; normal_table_select2 = s_t2; normal_table_select3 = s_t3; normal_region_0_count = s_l1; normal_region_1_count = s_l2};
gc_count1_table_1 = p1t1;
}
)
;; (* rehuff_granule quants gc scf_quants *)
(*********************************************************************************)
(* DECODE FRAME DECODE FRAME DECODE FRAME DECODE FRAME DECODE FRAME DECODE FRAME *)
(*********************************************************************************)
let decode_side_info : type id chan. (id,chan) f1_t -> (id,chan) side_internal_t = fun f ->
let s = Ptr.Ref.new_seq f.f1_side.side_raw in
let gs = get_seq s in
match f.f1_header.header_id with
| MPEG1 -> (
let read_gc part2_3_offset = (
let part2_3_length = gs 12 in
let big_values = gs 9 in
let global_gain = gs 8 in
let scf_compress = gs 4 in
let window_flag = gs 1 in
let window = if window_flag = 0 then (
let huff1 = gs 5 in
let huff2 = gs 5 in
let huff3 = gs 5 in
let r0 = gs 4 in
let r1 = gs 3 in
Window_normal {
normal_table_select1 = huff1;
normal_table_select2 = huff2;
normal_table_select3 = huff3;
normal_region_0_count = r0;
normal_region_1_count = r1;
}
) else (
let block_type_index = gs 2 in
let mixed_block = gs 1 in
let huff1 = gs 5 in
let huff2 = gs 5 in
let sb_gain1 = gs 3 in
let sb_gain2 = gs 3 in
let sb_gain3 = gs 3 in
Window_other {
other_block_type = [| Block_type_long; Block_type_start; Block_type_short; Block_type_stop |].(block_type_index);
other_mixed_block = (mixed_block = 1);
other_table_select1 = huff1;
other_table_select2 = huff2;
other_sub_block_gain1 = sb_gain1;
other_sub_block_gain2 = sb_gain2;
other_sub_block_gain3 = sb_gain3;
}
) in
let pre_flag = gs 1 in
let sf_scale = gs 1 in
let count1_table = gs 1 in
({
gc_part2_3_length = part2_3_length;
gc_part2_3_offset = part2_3_offset;
gc_big_values = big_values;
gc_global_gain = global_gain;
gc_scf_compress_index = scf_compress;
gc_window = window;
gc_pre_flag = (pre_flag = 1);
gc_sf_scale = sf_scale;
gc_count1_table_1 = (count1_table = 1);
}, part2_3_offset + part2_3_length)
) in
match f.f1_header.header_channel_mode with
| Mono -> (
let main_data = gs 9 in
let _ = gs 5 in
let a = gs 1 in
let b = gs 1 in
let c = gs 1 in
let d = gs 1 in
let side_scfi = SCFI_mono (a = 1, b = 1, c = 1, d = 1) in
let (side_gc1, new_so_far) = read_gc 0 in
let (side_gc2, _ ) = read_gc new_so_far in
{
side_main_data_begin = main_data;
side_scfi = side_scfi;
side_gc = GC_1_mono (side_gc1, side_gc2);
}
)
| Stereo _ -> (
let main_data = gs 9 in
let _ = gs 3 in
let a = gs 1 in
let b = gs 1 in
let c = gs 1 in
let d = gs 1 in
let e = gs 1 in
let f = gs 1 in
let g = gs 1 in
let h = gs 1 in
let side_scfi = SCFI_stereo ((a = 1, b = 1, c = 1, d = 1), (e = 1, f = 1, g = 1, h = 1)) in
let (side_gc1, new_so_far) = read_gc 0 in
let (side_gc2, new_so_far) = read_gc new_so_far in
let (side_gc3, new_so_far) = read_gc new_so_far in
let (side_gc4, _ ) = read_gc new_so_far in
{
side_main_data_begin = main_data;
side_scfi = side_scfi;
side_gc = GC_1_stereo (side_gc1, side_gc2, side_gc3, side_gc4);
}
)
)
| MPEG2 _ -> (
let read_gc part2_3_offset = (
let part2_3_length = gs 12 in
let big_values = gs 9 in
let global_gain = gs 8 in
let scf_compress = gs 9 in
let window_flag = gs 1 in
let window = if window_flag = 0 then (
let huff1 = gs 5 in
let huff2 = gs 5 in
let huff3 = gs 5 in
let r0 = gs 4 in
let r1 = gs 3 in
Window_normal {
normal_table_select1 = huff1;
normal_table_select2 = huff2;
normal_table_select3 = huff3;
normal_region_0_count = r0;
normal_region_1_count = r1;
}
) else (
let block_type_index = gs 2 in
let mixed_block = gs 1 in
let huff1 = gs 5 in
let huff2 = gs 5 in
let sb_gain1 = gs 3 in
let sb_gain2 = gs 3 in
let sb_gain3 = gs 3 in
Window_other {
other_block_type = [| Block_type_long; Block_type_start; Block_type_short; Block_type_stop |].(block_type_index);
other_mixed_block = (mixed_block = 1);
other_table_select1 = huff1;
other_table_select2 = huff2;
other_sub_block_gain1 = sb_gain1;
other_sub_block_gain2 = sb_gain2;