Guest User

Vgm2VortexTrackerTxtSn_19.sdlbas

a guest
Feb 26th, 2016
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="tune.vgm"
  3.  
  4. '- .vgm to VortexTracker .txt converter - SN-76489 version
  5. '- copyleft Paulo Silva, feb'16
  6. '-------------------------------
  7. '- bugs:
  8. '- - an acute sound might appear because an issue related to volume 0 that VortexTracker doesnt support, R-- note used instead (and the converter should store which note/frequency is for a probable volume changing, and set back the note/frequency value back)
  9. '- - doesn't read yet the author/title information
  10. '- - 'L' will be useful for the loop point location
  11. '- - probably will need a sample counter before converting
  12. '- - missing noise support
  13. '- - frequncy inaccuracy from the germanic notation formula probably fixed, needs more testing
  14. '-------------------------------
  15.  
  16. ltxtm$="....|..|--- .... ....|--- .... ....|--- .... ....":ltxcr$=ltxtm$
  17. freq0=0:freq1=0:freq2=0:vol0=0:vol1=0:vol2=0
  18. patsz=64:patc=0:patid=0:freqq=0
  19. hdram=0x40:vgmv=0:veof=0
  20. dim hdrv[256]
  21.  
  22. if argc>2 then:finp$=argv(2):end if
  23. fout2$=finp$+"_vt.txt":fout3$=finp$+"_vt_debug.txt"
  24.  
  25. frmc=0:frmr=300:trg=0
  26.  
  27. frmi=735
  28. if argc>3 then:
  29.   if argv(3)="1" or ucase$(argv(2))="-PAL" then
  30.     frmi=882:end if:end if
  31.  
  32. debug=0
  33. if argc>4 then:
  34.   if argv(4)="1" or ucase$(argv(2))="-DEBUG" then
  35.     debug=1:end if:end if
  36.  
  37. '- fix: 0x0FE=440hz=A-4
  38. function nttfrq$(freqb)
  39.   e$=   "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  40.   e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  41.   e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  42.   e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  43.   e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  44.   e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  45.   e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  46.   e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8---"
  47.   tmq=141-(int((log(freqb*.99)/log(2))*12))
  48.   if tmq<1 then:tmq=1:end if
  49.   if tmq>97 then:tmq=97:end if
  50.   return mid$(e$,(tmq*3)-2,3)
  51.   end function
  52.  
  53. open finp$ for input as #1
  54. for i=0 to 255
  55.   hdrv[i]=readbyte(1)
  56.   next
  57. close #1
  58.  
  59. hdram=0x040
  60. vgmv=hdrv[8]+hdrv[9]*256
  61. if vgmv>=0x0150 then:hdram=0x080:end if
  62. if vgmv>=0x0170 then:hdram=0x100:end if
  63.  
  64. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  65. hsam$="PlayOrder=L0"
  66. for i=1 to (ttsam/(frmi*patsz))-1
  67.   hsam$=hsam$+","+str$(i)
  68.   next
  69.  
  70. open finp$ for input as #1
  71. open fout2$ for output as #2
  72. open fout3$ for output as #3
  73.  
  74. print #2,"[Module]"
  75. print #2,"VortexTrackerII=1"
  76. print #2,"Version=3.6"
  77. print #2,"Title="
  78. print #2,"Author="
  79. print #2,"NoteTable=2"
  80. print #2,"Speed=1"
  81. print #2,hsam$
  82. print #2," "
  83. print #2,"[Ornament1]":print #2,"L0":print #2," "
  84. print #2,"[Sample1]":print #2,"Tne +000_ +00_ F_ L":print #2," "
  85. print #2,"[Pattern0]"
  86.  
  87. '- the amount of header bytes depends on vgm format version
  88. for eee=0 to hdram-1:q0=readbyte(1):next  '- read offset byte first
  89. txou1$="    #("+str$(0)+")"
  90.  
  91. while veof=0:
  92.   q0=readbyte(1)
  93.  
  94.   '- vgm eof command
  95.   if q0=0x66 then:
  96.     veof=1
  97.     print #3,"--vgm-eof--"
  98.     print #2," "
  99.     end if
  100.  
  101.   '- delay 1 byte (1..16 samples)
  102.   if bitwiseand(q0,0xF0)=0x70 then
  103.     frmc=frmc+bitwiseand(q0,0xF)+1
  104.     txou1$="    #("+str$(frmc)+")"
  105.     'print #3,txou1$
  106.     end if
  107.  
  108.   '- delay 3 bytes (0..65535 samples)
  109.   if q0=0x61 then
  110.     q0=readbyte(1)
  111.     frmc=frmc+q0
  112.     q0=readbyte(1)
  113.     frmc=frmc+(q0*256)
  114.     txou1$="    #("+str$(frmc)+")"
  115.     'print #3,txou1$
  116.     end if
  117.  
  118.   '- 1 ntsc frame delay, 735 samples
  119.   if q0=0x62 then
  120.     frmc=frmc+735
  121.     txou1$="    #("+str$(frmc)+")"
  122.     'print #3,txou1$
  123.     end if
  124.  
  125.   '- 1 pal frame delay, 882 samples
  126.   if q0=0x63 then
  127.     frmc=frmc+882
  128.     txou1$="    #("+str$(frmc)+")"
  129.     'print #3,txou1$
  130.     end if
  131.  
  132.   '- updates frameout pulses
  133.   while frmr<frmc
  134.  
  135.     '- writes 1F in the first line of the first pattern
  136.     if (patc<1 and patid=0) then
  137.       ltxcr$=replace$(12,ltxcr$,"1F")
  138.       ltxcr$=replace$(26,ltxcr$,"1F")
  139.       ltxcr$=replace$(40,ltxcr$,"1F")
  140.       end if
  141.  
  142.     '- creates a new pattern  
  143.     if patc>(patsz-1) then:
  144.       print #2," "
  145.       patid=patid+1:patc=0
  146.       txou9$="[Pattern"+str$(patid)+"]"
  147.       print #2,txou9$
  148.       end if
  149.  
  150.     '- writes a pattern line in each frame
  151.     if trg=0 then
  152.       print #3,"--frameout-unchanged--"
  153.       print #2,ltxtm$
  154.     else
  155.       print #3,"--frameout--"
  156.       print #2,ltxcr$
  157.       ltxcr$=ltxtm$
  158.       trg=0
  159.       end if
  160.  
  161.     frmr=frmr+frmi
  162.     patc=patc+1
  163.     end while
  164.  
  165.   if q0=0x50 then
  166.     q0=readbyte(1)
  167.  
  168.     if bitwiseand (q0,128)=0 then
  169.  
  170.       '- channel 0 - coarse
  171.       if freqq=0 then
  172.         freq0= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq0,0x00F)) )
  173.         ltxtm1$=ltxtm$
  174.         ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  175.         ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  176.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  177.         trg=1
  178.         end if
  179.  
  180.       '- channel 1 - coarse
  181.       if freqq=1 then
  182.         freq1= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq1,0x00F)) )
  183.         ltxtm1$=ltxtm$
  184.         ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  185.         ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  186.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  187.         trg=1
  188.         end if
  189.  
  190.       '- channel 2 - coarse
  191.       if freqq=2 then
  192.         freq2= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq2,0x00F)) )
  193.         ltxtm1$=ltxtm$
  194.         ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  195.         ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  196.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  197.         trg=1
  198.         end if
  199.  
  200.       end if
  201.  
  202.     if bitwiseand (q0,128)=128 then
  203.  
  204.       '- channel 0 - fine
  205.       if bitwiseand (q0,0xF0)=0x80  then '- tone ch0
  206.         freqq=0
  207.         freq0= bitwiseor ( (bitwiseand(freq0,0xFF0)),(bitwiseand(q0,0x00F)) )
  208.         ltxtm1$=ltxtm$
  209.         ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  210.         ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  211.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  212.         trg=1
  213.         end if
  214.  
  215.       '- channel 1 - fine
  216.       if bitwiseand (q0,0xF0)=0xA0  then '- tone ch1
  217.         freqq=1
  218.         freq1= bitwiseor ( (bitwiseand(freq1,0xFF0)),(bitwiseand(q0,0x00F)) )
  219.         ltxtm1$=ltxtm$
  220.         ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  221.         ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  222.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  223.         trg=1
  224.         end if
  225.  
  226.       '- channel 2 - fine
  227.       if bitwiseand (q0,0xF0)=0xC0  then '- tone ch2
  228.         freqq=2
  229.         freq2= bitwiseor ( (bitwiseand(freq2,0xFF0)),(bitwiseand(q0,0x00F)) )
  230.         ltxtm1$=ltxtm$
  231.         ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  232.         ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  233.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  234.         trg=1
  235.         end if
  236.  
  237.       'if bitwiseand (q0,0xF0)=0xE0  then '- freq noise
  238.       '  end if
  239.  
  240.       '- channel 0 - volume
  241.       if bitwiseand (q0,0xF0)=0x90  then '- volume ch0
  242.         'freqq=0
  243.         vol0=15-bitwiseand(q0,0xF)
  244.         ltxtm1$=ltxtm$
  245.         ltxtm2$=replace$(15,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  246.         ltxcr$=replace$(15,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  247.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  248.         trg=1
  249.         end if
  250.  
  251.       '- channel 1 - volume
  252.       if bitwiseand (q0,0xF0)=0xB0  then '- volume ch1
  253.         'freqq=1
  254.         vol1=15-bitwiseand(q0,0xF)
  255.         ltxtm1$=ltxtm$
  256.         ltxtm2$=replace$(29,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  257.         ltxcr$=replace$(29,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  258.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  259.         trg=1
  260.         end if
  261.  
  262.       '- channel 2 - volume
  263.       if bitwiseand (q0,0xF0)=0xD0  then '- volume ch2
  264.         'freqq=2
  265.         vol2=15-bitwiseand(q0,0xF)
  266.         ltxtm1$=ltxtm$
  267.         ltxtm2$=replace$(43,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  268.         ltxcr$=replace$(43,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  269.         print #3,ltxtm2$+"    #("+str$(frmc)+")"
  270.         trg=1
  271.         end if
  272.  
  273.       'if bitwiseand (q0,0xF0)=0xF0  then '- volume ch3
  274.       '  end if
  275.  
  276.       end if
  277.     end if
  278.  
  279.   if eof(1)<>0 then:veof=1:end if
  280.   wend
  281.  
  282. close #1:close #2:close #3
  283.  
  284. if debug=0 then:
  285.   shell("rm "+fout3$)
  286.   end if
Add Comment
Please, Sign In to add comment