-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3play7.s
More file actions
11483 lines (10378 loc) · 356 KB
/
Copy pathmp3play7.s
File metadata and controls
11483 lines (10378 loc) · 356 KB
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
; ****************************************************************************
; MP3PLAY7.PRG - MP3 DECODER/PLAYER 1.0 for TRDOS 386 Operating System
; ----------------------------------------------------------------------------
; Based on
; NOCASH MP3PLAY.EXE 1.4 (Windows) ASM source code (Martin Korth, 20/09/2024)
;
; 19/02/2025
;
; [ Last Modification: 25/02/2025 ]
;
; ----------------------------------------------------------------------------
; Modified from on mp3play4.s - 01/02/2025
; ----------------------------------------------------------------------------
; Modified from on MP3PLAY.ASM (for Windows console) source code - 17/10/2024
; ****************************************************************************
; Modified from Martin Korth's 'mp3play.asm' (TASM32) source code... (v1.4)
; Applied development method:
; Disassembling 'mp3play.exe' v1.4 by using HEX-RAYS disassembler;
; then... converting disassembled code to FASM syntax,
; adding '.idata' code (by help of FASM examples) to the raw
; asm file. Converting 'proc' procedures to labels.
; and Finally: assembling mp3play.asm (single) file by using
; 'fasm mp3play.asm' command.
;
; NOTE:
; Martin Korth's MP3PLAY.EXE (v1.4, 20/09/2024) file size is 45056 bytes.
; (This) modified MP3PLAY.EXE (v1.4.0, 17/10/2024) is 37888 bytes.
;
; ---------------------------------------------------------------------------
; Assembler: FASM
; ---------------
; fasm mp3play7.s MP3PLAY7.PRG
; (from mp3play4.s to mp3play6.s)
; Modification Reference: ac97play.s - 05/02/2025
; tmp3play.s - 18/02/2025
; 21/01/2025
; Wave LED/Lighting Code Reference:
; playwav9.s - 17/01/2025
; 13/01/2025 (mp3play3.s)
; Interpolated sample rate playing method for non-VRA AC97 codecs.
; ===========================================================================
; TRDOS 386 Operating System Specific Procedures - Erdogan Tan - 20/10/2024
; ===========================================================================
; 20/10/2024
; 20/08/2024 ; TRDOS 386 v2.0.9
; TRDOS 386 system calls
_ver equ 0
_exit equ 1
_fork equ 2
_read equ 3
_write equ 4
_open equ 5
_close equ 6
_wait equ 7
_creat equ 8
_rename equ 9
_delete equ 10
_exec equ 11
_chdir equ 12
_time equ 13
_mkdir equ 14
_chmod equ 15
_rmdir equ 16
_break equ 17
_drive equ 18
_seek equ 19
_tell equ 20
_mem equ 21
_prompt equ 22
_path equ 23
_env equ 24
_stime equ 25
_quit equ 26
_intr equ 27
_dir equ 28
_emt equ 29
_ldvrt equ 30
_video equ 31
_audio equ 32
_timer equ 33
_sleep equ 34
_msg equ 35
_geterr equ 36
_fpsave equ 37
_pri equ 38
_rele equ 39
_fff equ 40
_fnf equ 41
_alloc equ 42
_dalloc equ 43
_calbac equ 44
_dma equ 45
_stdio equ 46 ; TRDOS 386 v2.0.9
; ---------------------------------------------------------------------------
; 'sys' macro in FASM format
; ---------------------------------------------------------------------------
; 11/01/2025
if 1
;%if 0
macro sys op1,op2,op3,op4
{
if op4 eq
else
mov edx, op4
end if
if op3 eq
else
mov ecx, op3
end if
if op2 eq
else
mov ebx, op2
end if
mov eax, op1
int 40h
}
;%endif
end if
; ---------------------------------------------------------------------------
; 'sys' macro in NASM format
; ---------------------------------------------------------------------------
; 09/01/2025
; 11/01/2025
if 0
;%macro sys 1-4
; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
; 03/09/2015
; 13/04/2015
; Retro UNIX 386 v1 system call.
%if %0 >= 2
mov ebx, %2
%if %0 >= 3
mov ecx, %3
%if %0 = 4
mov edx, %4
%endif
%endif
%endif
mov eax, %1
;int 30h
int 40h ; TRDOS 386 (TRDOS v2.0)
;%endmacro
end if
; ===========================================================================
; CODE
; ===========================================================================
format binary
use32
;org 0x0
; ===========================================================================
; 22/02/2025
; 20/02/2025
; 20/10/2024
start:
; 21/10/2024
call set_break ; set and clear bss section
; also set stream_start position
;;mov edx, txt_hello ; "nocash mp3 decoder v1.4, 2024" ...
;;call wrstr_edx
;mov ebx, txt_hello
; 22/02/2025
;call print_msg
; TRDOS 386 system call
; write/display message on screen
; ebx = ASCIIZ message (text) address
; ecx = max. message length (stop count before char zero)
; edx = character color (CGA)
sys _msg, txt_hello, 255, 0Bh ; cyan
; 22/02/2025
; CRLF
mov ah, 0Eh
mov ebx, 7
mov al, 0Dh
int 31h
mov al, 0Ah
int 31h
; 15/02/2025
sys _msg, txt_bdate, 255, 0Fh
sys _msg, txt_original, 255, 07h
; 20/02/2025
;call get_commandline
;jc ExitP@
;;;
; 11/01/2025
call detect_enable_audio_device
jc ExitP@
;;;
; 20/02/2025 (mp3play7.s)
;;;; ---------------------------------
; 05/02/2025 (ac97.s)
; ----------
; 30/11/2024
; (TRDOS 386 -Retro UNIX 386- argument transfer method)
; (stack: argc,argv0addr,argv1addr,argv2addr ..
; .. argv0text, argv1text ..)
; ---- argc, argv[] ----
mov esi, esp
lodsd
cmp eax, 2 ; two arguments
; (program file name & mp3 file name)
jb short pmsg_usage ; nothing to do
;mov [argc], al
shl eax, 2 ; *4
add eax, esp
; eax = last argument's address pointer
mov [argvl], eax ; last mp3 file (argument)
mov [argv], esi ; current argument (PRG file name)
lodsd ; skip program (PRG) file name
mov [argvf], esi ; 1st mp3 file (argument)
;;;; ---------------------------------
; 20/02/2025
call write_audio_dev_info
; ------------------------------------
; 20/02/2025 (mp3play7.s)
; 15/01/2025 (mp3play4.s)
; 10/01/2025 (Video memory access for buffer change indicator)
; DIRECT CGA (TEXT MODE) MEMORY ACCESS
; bl = 0, bh = 4
; Direct access/map to CGA (Text) memory (0B8000h)
sys _video, 0400h
cmp eax, 0B8000h
;je short check_p_command
; 22/02/2025
je short hide_cursor
; ------------------------------------
trdos386_error:
sys _msg, trdos386_err_msg, 255, 0Eh
mov ebx, -1 ; (not necessary) -error exit example-
jmp ExitProcess@
; ------------------------------------
; 22/02/2025
trdos386_err_msg:
db 13, 10
db 'TRDOS 386 System call error !', 13, 10, 0
; ------------------------------------
pmsg_usage:
sys _msg, txt_help, 255, 0Fh
jmp ExitP@
; ------------------------------------
; 22/02/2025
hide_cursor:
; Get the cursor type
mov ah, 03h
int 31h
mov [cursortype], cx ; save
;; Set the cursor to invisible
mov ah, 01h
mov ecx, 2607h
int 31h
; 21/01/2025
;;;; ==========================
; set wave volume led addresses
mov ebx, 0B8000h + 13*80*2
mov ebp, 80
mov edi, wleds_addr
wleds_sa_1:
mov ecx, 7
wleds_sa_2:
mov eax, 80*2
mul ecx
add eax, ebx
stosd
loop wleds_sa_2
mov eax, ebx
stosd
inc ebx
inc ebx
dec ebp
jnz short wleds_sa_1
;;;; ==========================
mov byte [wleds], 1
; ------------------------------------
; 20/02/2025 (mp3play7.s)
; 05/02/2025 (ac97play.s)
;;;; ---------------------------------
check_p_command:
; 07/12/2024
mov esi, [argv]
cmp byte [command], 'P'
je short get_previous_file
add esi, 4
cmp esi, [argvl] ; last argument (mp3 file) ptr
jna short get_next_file
jmp player_quit
; ------------------------------------
get_previous_file:
; 22/02/2025
cmp esi, [argvf] ; first argument (mp3 file) ptr
jna short get_next_file_@
sub esi, 4
; 22/02/2025
get_next_file:
; 07/12/2024
mov [argv], esi ; set as current argument
get_next_file_@:
mov esi, [esi]
;;;; ---------------------------------
; 20/02/2025 - mp3play7.s
; 15/02/2025 - tmp3play.s
; 10/02/2025 - twavply3.s
GetFileName:
; (TRDOS 386 -Retro UNIX 386- argument transfer method)
; (stack: argc,argv0addr,argv1addr,argv2addr ..
; .. argv0text, argv1text ..)
; ---- argc, argv[] ----
; 15/02/2025
mov edi, mp3_file_name
xor ecx, ecx ; 0
ScanName:
lodsb
cmp al, 0Dh ; CR
jna short a_4
cmp al, 20h
je short ScanName ; scan start of name.
stosb
mov ah, 0FFh
a_0:
inc ah
a_1:
inc ecx
lodsb
stosb
cmp al, '.'
je short a_0
cmp al, 20h
jna short a_3
and ah, ah
jz short a_2
; 20/02/2025
cmp al, '/'
jne short a_2
mov ah, 0
a_2:
cmp cl, 75 ; 64+8+'.'+3 -> offset 75 is the last chr
jb short a_1
; 20/02/2025,
sub ecx, ecx
jmp short a_4
a_3:
dec edi
or ah, ah ; if period NOT found,
jnz short a_4 ; then add a .mp3 extension.
SetExt:
; 15/02/2025
mov dword [edi], '.mp3'
;mov dword [edi], '.WAV' ; ! 64+12 is DOS limit
; but writing +4 must not
; destroy the following data
; so, 80 bytes path + 0 is possible here
add edi, 4
a_4:
mov byte [edi], 0
cmp byte [mp3_file_name], 20h
ja short mp3_filename_chk
; 20/02/2025
call set_text_mode
check_f_index:
; 22/02/2025
cmp byte [file_count], 0
jna pmsg_usage
jmp ExitP@
; ---------------------------------------------------
mp3_filename_chk:
mov eax, [edi-4]
and eax, 0FFDFDFFFh
cmp eax, '.MP3'
jne short not_valid_mp3
; ------------------------------------
xor ebp, ebp
call mp3_init
call open_and_mmap_the_file
; 22/02/2025
jnc short mp3_open_read_ok
cmp byte [file_count], 0
ja check_p_command
; 23/02/2025
cmp dword [hFile], -1
jne short mp3_read_error
mp3_open_err:
mov esi, txt_not_found
jmp short write_err_msg_exit
; ------------------------------------
; 22/02/2025
txt_not_found: ;db 13, 10
db 'Error: file not found.', 13, 10, 0
; ------------------------------------
mp3_read_error:
mov esi, txt_read_err
jmp short write_err_msg_exit
; ------------------------------------
; 22/02/2025
txt_read_err:
db 0Dh, 0Ah
db 'File read error !', 0Dh, 0Ah, 0
; ------------------------------------
mp3_open_read_ok:
call mp3_check_1st_frame
; 20/02/2025
jnc short mp3_file_ready
; ------------------------------------
not_valid_mp3:
; 22/02/2025
cmp byte [file_count], 0
ja check_p_command
mov esi, not_valid_mp3f
write_err_msg_exit:
; 20/02/2025
call set_text_mode
; not a proper/valid mp3 file !
sys _msg, esi, 255, 0Ch ; red
jmp ExitP@
; ------------------------------------
; 22/02/2025
not_valid_mp3f:
;db 13, 10
db 'Not a proper/valid MP3 file !', 13, 10, 0
; ------------------------------------
mp3_file_ready:
; 26/01/2025
.p_template:
; 22/02/2025
; [mp3_bytes_per_sample] = 2
; 22/01/2025
;;;;
; 22/02/2025
mov eax, 640
mov ebx, turn_on_leds_stereo_16bit
; 23/02/2025
mov dl, 1
cmp byte [audio_hardware], dl ; 1
ja short .stolp_s16 ; AC97
; SB16
cmp byte [mp3_num_channels], dl ; 1
ja short .stolp_s
.stolp_m:
; 22/02/2025
;cmp byte [mp3_bytes_per_sample], dl ; 1
;ja short .stolp_m16
mov ebx, turn_on_leds_mono_16bit
jmp short .stolp_m16
;.stolp_m8:
; mov dword [turn_on_leds], turn_on_leds_mono_8bit
; ;mov byte [sd_count], 80
; ; 26/01/2025
; mov word [sd_count], 80*8
; jmp short .stolp_ok
;.stolp_m16:
; mov dword [turn_on_leds], turn_on_leds_mono_16bit
; ;mov byte [sd_count], 80*2
; ; 26/01/2025
; mov word [sd_count], 80*8*2
; jmp short .stolp_ok
;.stolp_s:
; ; 22/02/2025
; ;cmp byte [mp3_bytes_per_sample], dl ; 1
; ;ja short .stolp_s16
;.stolp_s8:
; ;;mov dword [turn_on_leds], turn_on_leds_stereo_8bit
; ;;mov byte [sd_count], 80*2
; ; 26/01/2025
; ;mov word [sd_count], 80*8*2
; ;jmp short .stolp_ok
.stolp_s: ; 22/02/2025
.stolp_s16:
;mov dword [turn_on_leds], turn_on_leds_stereo_16bit
; 22/01/2025
shl eax, 1
;;mov word [sd_count], 80*4
; 26/01/2025
;mov word [sd_count], 80*8*4
.stolp_m16:
; 22/02/2025
shl eax, 1
.stolp_ok:
mov [sd_count], eax
mov [turn_on_leds], ebx
;;;;
; 22/01/2025
; Forward/Backward position change parameters (*)
mov eax, [stream_pos]
mov [stream_begin], eax ; *
mov eax, [bytes_left]
mov [stream_size], eax ; *
; 22/02/2025
mov byte [command], 0
; 22/02/2025
;;;;;
mov eax, [mp3_sample_rate]
mov [playback_f], eax
mov al, byte [mp3_num_channels]
mov byte [playback_c], al
;;;;;
; 22/02/2025
mov byte [interpolation], 1
; 13/01/2025 (interpolation procs for non-VRA AC97 codecs)
;;;; --------------------------
;mov byte [interpolation], 0
mov al, 2
cmp [audio_hardware], al ; 2
jb short .sb16 ; SB16 ; 17/02/2025
; AC97
;mov dword [get_sound_data], get_ac97_sound_data ; (**)
.chk_frq:
; 22/02/2025
mov byte [playback_c], al ; 2 ; force to stereo (for AC97)
cmp dword [mp3_sample_rate], 48000 ; 48 kHZ
jb short .chk_vra
cmp byte [mp3_num_channels], 2
; 17/02/2025
;jb short .convert ; mono (8bit or 16bit)
;cmp byte [mp3_bytes_per_sample], al ; 2
;jnb short .direct ; 16bit, stereo
; 17/02/2025
;jnb short .direct
; 22/02/2025
jnb short .ac97_48khz_s
.convert:
; 8bit m/s or 16bit mono
; 22/02/2025
;mov byte [interpolation], 1 ; convert (to 16 bit stereo)
;jmp short .indirect ; 21/01/2025
jmp short display_frame
.chk_vra:
;mov [interpolation], al ; 2 = interpolation
; 22/02/2025
inc byte [interpolation] ; 2
cmp byte [vra], 1
;jb short .indirect ; 21/01/2025
; 22/02/2025
jnb short .ac97_vra
mov dword [playback_f], 48000 ; for non-VRA codecs
jmp short display_frame
.ac97_vra:
dec byte [interpolation] ; 1 = convert (to 16 bit stereo)
cmp byte [mp3_num_channels], 2
;jb short .indirect ; mono ; 21/01/2025
; 22/02/2025
jb short display_frame
; 17/02/2025
;cmp byte [mp3_bytes_per_sample], al ; 2
;jb short .indirect ; 8 bit ; 21/01/2025
.ac97_48khz_s:
; 22/02/2025
.sb16:
; 14/01/2025
dec byte [interpolation] ; 0
;;;; --------------------------
display_frame:
; 23/02/2025
;;;;
mov al, [volume_level]
cmp al, -1
jne short skip_init_volume
; initial volume
mov al, 3 ; 0 = max, 31 = min
skip_init_volume:
call SetMasterVolume
;;;;
xor edx, edx
call setCursorPosition
; Print playing screen in white
mov eax, 1300h
mov ebx, 000Fh
mov ecx, 1999
; edx = 0
;mov edx, 0
mov ebp, Template
int 31h
call SetTotalTime
call UpdateFileInfo
;call UpdateVolume
call UpdateProgressBar
;;;; ==========================
; 20/02/2025
replay:
; 22/02/2025
cmp byte [interpolation], 1
jnb short .indirect
.direct:
;;;
; 20/10/2024
;call detect_enable_audio_device
;jc .exit
call audio_system_init
;jc .exit
jc short exit@ ; 15/01/2025
;;;
call mp3_cast_to_speaker
; 20/02/2025 (mp3play7.s)
; 15/02/2025 (tmp3play.s)
; 13/01/2025
jmp short decode_done
.indirect:
call audio_system_init_x
jc short exit@ ; 15/01/2025
call mp3_cast_to_speaker_x
;;;; --------------------------
decode_done:
exit@:
; 22/02/2025 (mp3play7.s)
; 05/02/2025 (wavplay2.s)
; 07/12/2024
;;;
; Stop Playing
;sys _audio, 0700h
; 22/02/2025
cmp byte [init_level], 1
jb short exit@@@
dec byte [init_level]
jz short exit@@ ; 1 -> 0
; Cancel callback service (for user)
sys _audio, 0900h
dec byte [init_level] ; 1 -> 0
exit@@:
; Deallocate Audio Buffer (for user)
sys _audio, 0A00h
exit@@@:
; Disable Audio Device
sys _audio, 0C00h
;;;
; 22/02/2025
cmp byte [command], 'Q'
je short player_quit
; 22/02/2025
; (Detect & Enable Audio Hardware again)
; (this is needed after disabling audio system)
call detect_enable_audio_device
jc short player_quit
mov byte [stopped], 0
;;;;
; 23/02/2025
;mov dword [mp3_initialized], 0
; 23/02/2025
; (reset to the initial value is needed)
;mov dword [mp3_huff_num_entries], 12h ; 18
;;;;
call set_break
jmp check_p_command
player_quit:
; 22/02/2025
jmp ExitProcess
; =============== S U B R O U T I N E =======================================
bswap_eax:
xchg al, ah
ror eax, 10h
xchg al, ah
retn
; =============== S U B R O U T I N E =======================================
mp3_recollect_bits:
test esi, 1
jnz short .odd
mov bp, [esi]
add esi, 2
ror bp, 8
shl ebp, 16
mov ch, 0
retn
.odd:
movzx ebp, byte [esi]
inc esi
shl ebp, 16
mov bp, [esi]
add esi, 2
ror bp, 8
shl ebp, 8
mov ch, 8
retn
; =============== S U B R O U T I N E =======================================
mp3_get_bits:
mov eax, ebp
shl ebp, cl
rol eax, cl
xor eax, ebp
sub ch, cl
js short mp3_collect_more
retn
mp3_collect_more:
mov cl, ch
add ch, 10h
rol ebp, cl
mov bp, [esi]
add esi, 2
ror bp, 8
ror ebp, cl
retn
; =============== S U B R O U T I N E =======================================
mp3_uncollect_bits:
sub esi, 2
shr ch, 3
movzx ecx, ch
sub esi, ecx
retn
; =============== S U B R O U T I N E =======================================
mp3_search_get_header:
; 16/02/2025
mov dword [mp3_extra_bytes], 0
.retry_header:
cmp dword [mp3_src_remain], 4
jb .fail_no_header
cmp byte [esi], 0FFh
jnz short .bad_header
mov al, [esi+1]
and al, 0E6h
cmp al, 0E2h
jnz short .bad_header
mov al, [esi+2]
cmp al, 0F0h
jnb short .bad_header
and al, 0Ch
cmp al, 0Ch
jnz short .good_header
.bad_header:
inc esi
dec dword [mp3_src_remain]
inc dword [mp3_extra_bytes]
mov dword [main_data_pool_wr_ptr], main_data_pool_start
jmp short .retry_header
.good_header:
mov eax, [esi]
call bswap_eax
mov [mp3_hdr_32bit_header], eax
mov dword [mp3_hdr_flag_lsf], 0
mov dword [mp3_hdr_flag_mpeg25], 0
mov dword [mp3_nb_granules], 2
test eax, 80000h
jnz short .lsf_this
mov dword [mp3_hdr_flag_lsf], 1
mov dword [mp3_nb_granules], 1
test eax, 100000h
jnz short .lsf_this
mov dword [mp3_hdr_flag_mpeg25], 1
.lsf_this:
shr eax, 10
and eax, 3
mov ecx, [mp3_hdr_flag_lsf]
add ecx, [mp3_hdr_flag_mpeg25]
movzx edx, word [mp3_freq_tab+eax*2]
shr edx, cl
lea ecx, [ecx+ecx*2]
add eax, ecx
mov [mp3_hdr_sample_rate_index], eax
mov [mp3_sample_rate], edx
; 15/02/2025
mov eax, [mp3_hdr_32bit_header]
shr eax, 10h
not eax
and eax, 1
mov [mp3_hdr_flag_crc], eax
mov eax, [mp3_hdr_32bit_header]
shr eax, 9
and eax, 1
mov [mp3_hdr_flag_padding], eax
mov eax, [mp3_hdr_32bit_header]
shr eax, 12
and eax, 0Fh
jnz short .not_free_format
call mp3_detect_free_format_block_size
jb .bad_header
mov eax, [mp3_free_format_frame_size]
jmp short .this_frame_size_plus_padding
.not_free_format:
mov edx, [mp3_hdr_flag_lsf]
shl edx, 4
add eax, edx
movzx eax, word [mp3_bitrate_tab+eax*2] ; kbit/s
imul eax, 1000 ; bit/s
mov [mp3_bit_rate], eax
imul eax, 144 ; 144=90h=8*18
xor edx, edx
div dword [mp3_sample_rate]
mov ecx, [mp3_hdr_flag_lsf]
shr eax, cl
.this_frame_size_plus_padding:
add eax, [mp3_hdr_flag_padding]
mov [mp3_src_frame_size], eax
add eax, esi
mov [mp3_src_frame_end], eax
mov eax, [mp3_hdr_32bit_header]
shr eax, 6
and eax, 3
mov [mp3_hdr_mode_val], eax
mov edx, 1
cmp al, 3
jz short .this_channels
;mov edx, 2
; 10/01/2025
inc edx
.this_channels:
mov [mp3_num_channels], edx
; 15/02/2025
.allow_stereo:
;imul edx, [mp3_bytes_per_sample]
; 17/02/2025
shl edx, 1 ; [mp3_bytes_per_sample] = 2
mov [mp3_samples_dst_step], edx
mov eax, [mp3_hdr_32bit_header]
shr eax, 4
and eax, 3
mov [mp3_hdr_mode_ext], eax
; 16/02/2025
.no_rdtsc_supported@:
;clc
retn
.fail_no_header:
; 16/02/2025
.no_rdtsc_supported@@:
mov dword [mp3_src_frame_size], 0
stc
retn
; =============== S U B R O U T I N E =======================================
mp3_bitstream_read_header_extra:
; 16/02/2025
.no_rdtsc_supported:
cmp dword [mp3_hdr_flag_crc], 0
jz short .without_crc
mov eax, ebp ; mp3mac_get_n_bits 16
shl ebp, 10h
rol eax, 10h
xor eax, ebp
sub ch, 10h
jns short .without_crc
mov cl, ch ; mp3mac_collect_more
add ch, 10h
rol ebp, cl
mov bp, [esi]
add esi, 2
ror bp, 8
ror ebp, cl
.without_crc:
cmp dword [mp3_hdr_flag_lsf], 0
jz short .pre_lsf_zero
mov dword [mp3_num_compress_bits], 9
mov eax, ebp ; mp3mac_get_n_bits 8
shl ebp, 8
rol eax, 8
xor eax, ebp
sub ch, 8
jns short .without_crc@
mov cl, ch
add ch, 10h
rol ebp, cl
mov bp, [esi]
add esi, 2
ror bp, 8
ror ebp, cl
.without_crc@:
mov [mp3_main_data_begin], eax
mov cl, byte [mp3_num_channels]
mov eax, ebp ; mp3mac_get_n_bits cl
shl ebp, cl
rol eax, cl
xor eax, ebp