Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; AUTHORS:
  2. ; S. Kuzmin, A. Ershov, Madis Kalme 2005
  3. ; Sergey Efremenkov, Leency 2018
  4.  
  5. ; CHECK OUT README.TXT!
  6.  
  7. format binary as ""
  8.  
  9.     use32
  10.     org    0x0
  11.     db     'MENUET01'            ; 8 byte id
  12.     dd     0x01                  ; header version
  13.     dd     START                 ; start of code
  14.     dd     I_END                 ; size of image
  15.     dd     0x9000                ; memory for app
  16.     dd     0x9000                ; esp
  17.     dd     fileinfo2.path        ; I_Param , I_Icon
  18.     dd     0x0
  19.  
  20. include "mos_uzit.inc"
  21.  
  22. TAG1_X = 250     ; coordinates of ID3v1 block
  23. TAG1_Y = 40
  24.  
  25. BLOCKS_TO_READ  equ     2 ; must be greater than 1
  26. BLOCK_SIZE equ 512 ;ñêîëüêî áàéò â áëîêå
  27.  
  28. START:
  29.  
  30.     xor  eax, eax
  31.     mov  [last_err], eax
  32.     mov  [fileinfo2+4], eax      ; start block = 0
  33.     mov  dword [fileinfo2+12], BLOCKS_TO_READ*BLOCK_SIZE
  34.     mcall 70, fileinfo2
  35.  
  36. result:
  37.         push eax ebx                    ;ïîëó÷àåì ðàçìåð ôàéëà â áàéòàõ
  38.         mcall 70, fileSizeInfo
  39.        
  40.         cmp eax, 0
  41.         je @f
  42.         mov dword[size], 16384; ebx
  43.         jmp result.sizeEnd
  44. @@:
  45.         mov eax, dword[fileBuf+32]  ; íà ñàìîì äåëå òàì ðàçìåð 8 áàéò, à íå 4
  46.         mov dword[size], eax
  47. .sizeEnd:
  48.         pop ebx eax
  49.         ;mov     dword [size], 16384; ebx
  50.  
  51.         ; checking ID3v2 tag
  52.         xor     eax, eax
  53.         mov     [tagv2], eax
  54.         mov     eax, [mp3_file]
  55.         and     eax, 0x00ffffff
  56.         cmp     eax, 'ID3'
  57.         jnz     .no_id3v2
  58.         mov     eax, [mp3_file+3]
  59.         mov     [tagv2], eax
  60.  
  61.         mov     ecx, 4
  62.         mov     esi, mp3_file+6
  63.         xor     eax, eax
  64.         xor     ebx, ebx
  65.         cld
  66. .size_read:
  67.         lodsb
  68.         shl     ebx, 7
  69.         or      ebx, eax
  70.         loop    .size_read
  71.         add     ebx, 10
  72.         mov     eax, ebx
  73.         shr     eax, 9
  74.  
  75.         push eax edx
  76.         mov edx, BLOCK_SIZE
  77.         mul edx
  78.         mov dword[fileinfo2+4], eax   ; start block
  79.         pop edx eax
  80.  
  81.         shl     eax, 9
  82.  
  83.         mov     ecx, ebx
  84.         add     ecx, 3
  85.  
  86.         sub     ebx, eax
  87.         mov     edi, ebx
  88.         add     edi, mp3_file
  89.         dec     edi
  90.  
  91.         mcall 70, fileinfo2
  92.  
  93.         jmp     .loop
  94. .no_id3v2:
  95.  
  96.         mov     ecx, 3
  97.         mov     edi, mp3_file-1
  98. .loop:
  99.         inc     edi
  100.         inc     ecx
  101.         cmp     ecx, dword[size]
  102.         ja      .no_frames
  103.         mov     eax, [edi]
  104.         call    Header_Check
  105.         test    eax, eax
  106.         jz      .header_found
  107.         cmp     edi, mp3_file+BLOCKS_TO_READ*512-4
  108.         jb      .loop
  109.  
  110.         add     dword [fileinfo2+4], (BLOCKS_TO_READ-1)*BLOCK_SIZE
  111.  
  112.         mcall 70, fileinfo2
  113.  
  114.         sub     edi, (BLOCKS_TO_READ-1)*512
  115.         jmp     .loop
  116.  
  117. .no_frames:
  118.         mov     [last_err], err_bad_file
  119.         mov     [last_err_l], err_bad_file_e - err_bad_file
  120.         jmp     reading_end
  121.  
  122. .header_found:
  123. mov eax, dword [edi]
  124. sub     ecx, 4
  125. mov     [header_at], ecx
  126.  
  127.  
  128. call extract_bits
  129.  
  130. call decode_standard
  131.  
  132. call decode_layer
  133.  
  134. call decode_channels
  135.  
  136. call decode_samplerate
  137.  
  138. call decode_bitrate
  139.  
  140. call calculate_time_frame_count
  141.  
  142. ;--------------------------------------------
  143.  
  144.         mov     eax, [b1s]
  145.         and     eax, 1
  146.         shl     eax, 1                  ; eax = eax * 2
  147.         cmp     byte [shan], 11b        ; if mono
  148.         jz      @f
  149.         inc     eax
  150. @@:
  151.         mov     ebx, xing_offset
  152.         xlatb
  153.  
  154.         add     edi, eax
  155.         mov     eax, [edi]
  156.  
  157.         xor     ebx, ebx
  158.         mov     [xing_tag], ebx
  159.         cmp     eax, 'Xing'
  160.         jnz     .no_xing_tag
  161.         mov     esi, edi
  162.         add     esi, 15
  163.         std
  164.         mov     edi, xing_bytes
  165.         mov     ecx, 3*4
  166.         xor     eax, eax
  167.  
  168. .xing_read:
  169.         lodsb
  170.         mov     [edi], al
  171.         inc     edi
  172.         loop    .xing_read
  173.         cld
  174.         mov     ebx, [xing_tag]
  175.         test    ebx, 1
  176.         jz      .frames_end
  177.         mov     eax, [xing_frames]
  178.         mov     [framecount], eax
  179.         test    [b1s], 1        ; if MPEG 1 eax = eax*2
  180.         jz      @f
  181.         shl     eax, 1
  182. @@:
  183.         mov     ebx, 575
  184.         mul     ebx             ; edx:eax = eax*575
  185.         mov     ebx, [SR]
  186.         div     ebx             ; eax = edx:eax / sample rate
  187.  
  188.         mov     [time], eax
  189.  
  190.         ; calculating bitrate
  191.         xor     edx, edx
  192.         mov     ebx, 1000 / 8
  193.         mul     ebx             ; edx:eax = time * 1000
  194.         mov     ebx, eax
  195.         mov     eax, [xing_bytes]
  196.         div     ebx             ; eax = size / time*1000
  197.         mov     [BR], eax
  198.  
  199.  
  200. .frames_end:
  201.  
  202.  
  203. .no_xing_tag:
  204.  
  205. xor eax, eax
  206. xor ebx, ebx
  207. xor ecx, ecx
  208. xor edx, edx
  209. ;       ID3v1 tag reading
  210.         mov     eax, [size]     ; reading 2 last 512-byte blocks where our
  211.         mov     ebx, eax        ;       tag may be
  212.         shr     eax, 9          ; eax = size of file in full 512-byte blocks
  213.         test    eax, eax        ; if file's length is less then 512 we'll
  214.         jz      @f              ; read the whole file
  215.         dec     eax
  216. @@:
  217.         push eax edx
  218.         mov edx, BLOCK_SIZE
  219.         mul edx
  220.         mov     dword [fileinfo2+4], eax       ; start block
  221.         pop edx eax
  222.         mov     dword [fileinfo2+12], 2*BLOCK_SIZE         ; blocks to read
  223.  
  224.         shl     eax, 9
  225.         sub     ebx, eax
  226.         add     ebx, mp3_file - 128     ; if tag is present, ebx points to it
  227.         mov     esi, ebx
  228.  
  229.         xor     eax, eax
  230.         mov     [tag], eax
  231.  
  232.  
  233.         mcall   70, fileinfo2
  234.  
  235.         mov     eax, [esi]      ; checking if tag is present
  236.         and     eax, 0x00ffffff
  237.         cmp     eax, 'TAG'
  238.         jnz      @f
  239.         inc     [tag]
  240.         cld
  241.         mov     ecx, 128 / 4
  242.         mov     edi, tag.data
  243.         rep     movsd
  244.         mov     esi, tag.data
  245.         mov     ecx, 126
  246.         call    Win2Dos
  247. @@:
  248. reading_end:
  249.    call    draw_window                     ; 14.08.05 [
  250.  
  251.  
  252.         ; Öèêë ïîëó÷åíèÿ è îáðàáîòêè ñîîáùåíèé
  253.    get_event:
  254.         mov  eax,10
  255.         int  0x40
  256.         dec     eax
  257.         jnz     @f
  258.         call    draw_window
  259.         jmp     get_event
  260. @@:
  261.         dec     eax
  262.         jz      key_on_keyboard
  263.         dec     eax
  264.         jz      click_on_button
  265.         jmp     get_event
  266.  
  267.    key_on_keyboard:
  268.         mcall   2
  269.         jmp     get_event
  270.  
  271.    click_on_button:
  272.    exit:
  273.         mcall   17
  274.         ;cmp     ah, 10
  275.         ;jz      other_file
  276.  
  277.         mov  eax,-1
  278.         int  0x40
  279.  
  280.         jmp     get_event               ;     ] 14.08.05
  281.  
  282.            ; Ðèñîâàíèå îêíà
  283. draw_window:
  284.         mcall 12,1
  285.         mov  eax,0              ; function 0 : define and draw window
  286.         mov  ebx,250 shl 16 + 500
  287.         mov  ecx,250 shl 16 + 300
  288.         mov  edx,0x34aabbcc     ; color of work area RRGGBB,8->color gl
  289.                 mov  edi, header
  290.         int  0x40
  291.  
  292.         Text 20,12,0x00000000,choice, choicelen-choice
  293.         Text 110,12,0x00000000,fileinfo2.path, 60
  294.  
  295.         mov     edx, dword [last_err]
  296.         test    edx, edx
  297.         jz      .no_err
  298.         mov     eax, 4
  299.         mov     ebx, 50*65536+50
  300.         xor     ecx, ecx
  301.         mov     esi, [last_err_l]
  302.         int     0x40
  303.         jmp     draw_end
  304. .no_err:
  305.  
  306.       Text 20,40,0x00000000,S, Slen-S
  307.       Number 110,40,1*256,1,dword [S1],0x000000;
  308.       Number 122,40,1*256,1,dword [S2],0x000000;
  309.  
  310.       Text 20,60,0x00000000,L, Llen-L
  311.       Number 110,60,1*256,1,dword [La],0x000000
  312.  
  313.           Text 20,100,0x00000000,SamR, SamRlen-SamR
  314.           Number 110,100,0*256,5,dword [SR],0x000000
  315.  
  316.           Text 20,120,0x00000000,BitR, BitRlen-BitR
  317.           Number 110,120,0*256,3,dword [BR],0x000000
  318.  
  319.         mov     eax, [xing_tag]
  320.         test    eax, eax
  321.         jz      @f
  322.         Text 170,120,0x00000000,vbr, vbr_e - vbr
  323. @@:
  324.  
  325.           Text 20,140,0x00000000,Sizebyte, Sizebytelen-Sizebyte
  326.       Number 110,140,0*256,8,dword [size],0x000000
  327.  
  328.           Text 20,160,0x00000000,Timese, Timeselen-Timese
  329.           Number 110,160,0*256,4,dword [time],0x000000
  330.  
  331.           Text 20,180,0x00000000,frame, framelen-frame
  332.           Number 110,180,0*256,4,dword [frames],0x000000
  333.  
  334.         Text 20,200,0x00000000,framcount, framcountlen-framcount
  335.  
  336.         Text 20,220,0x00000000,padding, paddinglen-padding
  337.  
  338.         cmp [pad], 1
  339.         je res1
  340.         jne res2
  341.  
  342.         res1:
  343.      Text 75,220,0x00000000,da, dalen-da
  344.          jmp nex
  345.         res2:
  346.          Text 75,220,0x00000000,net, netlen-net
  347.          jmp nex
  348.  
  349.          nex:
  350.  
  351.         ; ------------------
  352.  
  353.  
  354.         Text 110,220,0x00000000,crci, crcilen-crci
  355.  
  356.         cmp [crc], 0
  357.         je res3
  358.         jne res4
  359.  
  360.         res3:
  361.      Text 160,220,0x00000000,da, dalen-da
  362.          jmp ne
  363.         res4:
  364.          Text 160,220,0x00000000,net, netlen-net
  365.          jmp ne
  366.  
  367.          ne:
  368.  
  369.          ;--------------------------
  370.  
  371.           Number 110,200,0*256,6,dword [framecount],0x000000
  372.  
  373.  
  374.           Text 20,80,0x00000000,Ka, Kalen-Ka
  375.  
  376.          cmp [K], 1
  377.          je rez1
  378.          cmp [K], 2
  379.          je rez2
  380.          cmp [K], 3
  381.          je rez3
  382.          cmp [K], 4
  383.          je rez4
  384.  
  385.          rez1:
  386.          Text 110,80,0x00000000,SC, SClen-SC
  387.          jmp next
  388.          rez2:
  389.          Text 110,80,0x00000000,DC, DClen-DC
  390.           jmp next
  391.          rez3:
  392.          Text 110,80,0x00000000,JOS, JOSlen-JOS
  393.           jmp next
  394.          rez4:
  395.          Text 110,80,0x00000000,Su, Sulen-Su
  396.  
  397. next:
  398.         Text   20,240,0,header_found, header_found_e - header_found
  399.         Number 160,240,0*256,6,dword [header_at],0x000000  ;;;;;;; HEADER AT
  400.  
  401.  
  402.  
  403.         ; ID3v2
  404.  
  405.         mcall   4, 250*65536+220, 0,id3v2, id3v2_e - id3v2
  406.         mov     edi, tagv2
  407.         mov     eax, [edi]
  408.         test    eax, eax
  409.         jz      .no_v2
  410.         mcall   4, 281*65536+220,  ,dots, dots_e - dots
  411.         xor     ecx, ecx
  412.         mov     cl, byte [edi]
  413.         mcall   47, 65536*2, , 286*65536+220, 0
  414.         mov     cl, byte [edi+1]
  415.         mcall     ,        , , 304*65536+220,
  416.  
  417.         jmp     .v2_end
  418. .no_v2:
  419.         Text   300,220,0,net, netlen- net
  420. .v2_end:
  421.  
  422.  
  423.  
  424.         ; ID3v1 info
  425.         ; Writing all field names
  426.         mov     eax, 4                  ; function 4
  427.         words2reg   ebx, TAG1_X, TAG1_Y
  428.         xor     ecx, ecx                ; color
  429.         mov     edx, id3v1
  430.         mov     esi, id3v1_e - id3v1
  431.         int     0x40
  432.  
  433.         add     ebx, 40
  434.         mov     edx, title ; length is the same, so we don't write it in esi
  435.         int     0x40
  436.  
  437.         add     ebx, 20
  438.         mov     edx, artist
  439.         inc     esi
  440.         int     0x40
  441.  
  442.         add     ebx, 20
  443.         mov     edx, album
  444.         dec     esi
  445.         int     0x40
  446.  
  447.         add     ebx, 20
  448.         mov     edx, year
  449.         dec     esi
  450.         int     0x40
  451.  
  452.         add     ebx, 20
  453.         mov     edx, genre
  454.         inc     esi
  455.         int     0x40
  456.  
  457.         add     ebx, 20
  458.         mov     edx, comment
  459.         inc     esi
  460.         inc     esi
  461.         int     0x40
  462.  
  463.         sub     ebx, 120
  464.         mov     edx, track
  465.         int     0x40
  466.  
  467.         ; checking if tag is
  468.         mov     eax, dword [tag]
  469.         test    eax, eax
  470.         jz      .no_tag1
  471.  
  472.         mov     edi, tag.data
  473.  
  474.         ; writing walues
  475.         words2reg   edx, (TAG1_X+50), (TAG1_Y+20)
  476.  
  477.         ; track number uses the 30-th byte of comment field
  478.         ; it may be the last char in comment field
  479.         ; so we check if this byte presents a track number
  480.         mov     eax, [edi+125]
  481.         test    al, al
  482.         jnz     .no_track
  483.         test    ah, ah
  484.         jz      .no_track
  485.  
  486.         mov     ebx, 3*65536
  487.         xor     ecx, ecx
  488.         mov     cl, ah
  489.         xor     esi, esi
  490.         mov     eax, 47
  491.         int     0x40
  492.  
  493. .no_track:
  494.         mov     ebx, edx
  495.         mov     edx, edi
  496.         mov     eax, 4          ; function 4
  497.         xor     ecx, ecx        ; color
  498.  
  499.         add     ebx, 20
  500.         add     edx, 3
  501.         mov     esi, 30
  502.         int     0x40            ; title
  503.  
  504.         add     ebx, 20
  505.         add     edx, esi
  506.         int     0x40            ; artist
  507.  
  508.         add     ebx, 20
  509.         add     edx, esi
  510.         int     0x40            ; album
  511.  
  512.         add     ebx, 60
  513.         add     edx, 34
  514.         dec     esi
  515.         int     0x40            ; comment
  516.  
  517.         sub     ebx, 40
  518.         mov     esi, 4
  519.         sub     edx, esi
  520.         int     0x40            ; year
  521.  
  522. .no_tag1:
  523. draw_end:
  524.     mcall 12, 2
  525. ret                             ;      (!) 14.08.05
  526.  
  527.    freq  dd   11025, 12000, 8000
  528.    Bitrate db 0,1,2, 3, 4, 5, 6, 7, 8,10,12,14,16,18,20,0,\ ; v2 l2 l3
  529.               0,1,2, 3, 4, 5, 6, 7, 8,10,12,14,16,18,20,0,\ ; v2 l2 l3
  530.               0,4,6, 7, 8,10,12,14,16,18,20,22,24,28,32,0,\ ; v2 l1
  531.               0,4,5, 6, 7, 8,10,12,14,16,20,24,28,32,40,0,\ ; v1 l3
  532.               0,4,6, 7, 8,10,12,14,16,20,24,28,32,40,48,0,\ ; v1 l2
  533.               0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,0   ; v1 l1
  534.    xing_offset   db 13, 21, 21, 36
  535. header:
  536.      db   'MP3 Info 0.7',0
  537.  
  538. S:
  539.     db 'MPEG Version:   .  '
  540. Slen:
  541.  
  542. L:
  543.     db 'Layer:   '
  544. Llen:
  545.  
  546. Ka:
  547.     db 'Channels Mode:   '
  548. Kalen:
  549.  
  550. Su:
  551.     db 'Stereo'
  552. Sulen:
  553.  
  554. JOS:
  555.     db 'Joint stereo '
  556. JOSlen:
  557.  
  558. DC:
  559.     db 'Dual channel'
  560. DClen:
  561.  
  562. SC:
  563.     db 'Single Channel (Mono)'
  564. SClen:
  565.  
  566. SamR:
  567.     db 'Sample Rate:          Hz'
  568. SamRlen:
  569.  
  570. BitR:
  571.     db 'BitRate:            Kbps'
  572. BitRlen:
  573.  
  574. Sizebyte:
  575.     db 'Size:                   bytes'
  576. Sizebytelen:
  577.  
  578. Timese:
  579.     db 'Time:               seconds'
  580. Timeselen:
  581.  
  582. frame:
  583.     db 'Frame size:         bytes'
  584. framelen:
  585.  
  586. framcount:
  587.     db 'Quantity:             frames'
  588. framcountlen:
  589.  
  590. padding:
  591.     db 'Padding:'
  592. paddinglen:
  593.  
  594. crci:
  595.     db 'CRC:'
  596. crcilen:
  597.  
  598. da:
  599.     db 'yes'
  600. dalen:
  601.  
  602. net:
  603.     db 'no'
  604. netlen:
  605. dots    db      '.  .'
  606. dots_e:
  607.  
  608. header_found    db      'Header found at:'
  609. header_found_e:
  610.  
  611. choice:
  612.     db 'File path: '
  613. choicelen:
  614. id3v2   db      'ID3v2'
  615. id3v2_e:
  616. vbr     db      '(VBR)'
  617. vbr_e:
  618. id3v1   db      'ID3v1'
  619. id3v1_e:
  620. track   db      'Track #'
  621. track_e:
  622. title   db      'Title'
  623. title_e:
  624. artist  db      'Artist'
  625. artist_e:
  626. album   db      'Album'
  627. album_e:
  628. year    db      'Year'
  629. year_e:
  630. genre   db      'Genre'
  631. genre_e:
  632. comment db      'Comment'
  633. comment_e:
  634.  
  635. err_bad_file    db      'Bad file'
  636. err_bad_file_e:
  637.  
  638. fileinfo2:
  639.   .func  dd 0            ;íîìåð ïîäôóíêöèè
  640.   .start dd 0*BLOCK_SIZE ;ïîçèöèÿ â ôàéëå (â áàéòàõ)  *512
  641.          dd 0            ;(çàðåçåðâèðîâàíî ïîä ñòàðøèé dword ïîçèöèè)
  642.   .size  dd 1*BLOCK_SIZE ;ñêîëüêî áàéò ÷èòàòü
  643.   .buf   dd mp3_file     ;óêàçàòåëü íà áóôåð, êóäà áóäóò çàïèñàíû äàííûå
  644.   .path:
  645.      db "TEST.MP3",0   ;"/RD/1/TEST.MP3",0
  646.      rb 256-($-.path)
  647.  
  648.  
  649. ;äëÿ ïîëó÷åíèÿ êîððåêòíîãî ðàçìåðà ôàéëà
  650. fileSizeInfo:
  651. dd 5 ; íîìåð ïîäôóíêöèè
  652. dd 0,0,0 ;(çàðåçåðâèðîâàíî)
  653. dd fileBuf ;óêàçàòåëü íà áóôåð, êóäà áóäóò çàïèñàíû äàííûå(40 áàéò)
  654. db 0
  655. dd fileinfo2.path
  656.  
  657. fileBuf: db 40 dup(0)
  658.  
  659.  
  660. ;=================================================
  661.    b1s          dd ?   ; standard
  662.    b1l          dd ?   ; layer
  663.    S1           dd ?
  664.    S2           dd ?
  665.    La           dd ?
  666.    shan         dd ?
  667.    K            dd ?
  668.    sam          dd ?
  669.    id           dd ?
  670.    SR           dd ?
  671.    Bita         dd ?
  672.    BR           dd ?
  673.    size         dd ?
  674.    time         dd ?
  675.    frames       dd ?
  676.  
  677.    xing_bytes   dd ?
  678.    xing_frames  dd ?
  679.    xing_tag     dd ?
  680.  
  681.    tagv2        dd ?
  682.    tag          dd ?
  683.    .data        rb 128
  684.    framecount   dd ?
  685.    pad          dd ?
  686.    priv         dd ?
  687.    modx         dd ?
  688.    copy         dd ?
  689.    orig         dd ?
  690.    emph         dd ?
  691.    crc          dd ?
  692.    header_at    dd ?
  693.    last_err     dd ?
  694.    last_err_l   dd ?
  695.  
  696.  
  697. I_END:
  698.  
  699. ;label  pre_file dword at 0x3000-4
  700. label  mp3_file dword at 0x3000
  701.  
  702.