Advertisement
Nicknine

Pac-Man World TXTP Maker

Aug 12th, 2022 (edited)
1,304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. import os
  2. import sys
  3. import struct
  4.  
  5. _svm_ptable = [
  6.     4096, 4110, 4125, 4140, 4155, 4170, 4185, 4200,
  7.     4216, 4231, 4246, 4261, 4277, 4292, 4308, 4323,
  8.     4339, 4355, 4371, 4386, 4402, 4418, 4434, 4450,
  9.     4466, 4482, 4499, 4515, 4531, 4548, 4564, 4581,
  10.     4597, 4614, 4630, 4647, 4664, 4681, 4698, 4715,
  11.     4732, 4749, 4766, 4783, 4801, 4818, 4835, 4853,
  12.     4870, 4888, 4906, 4924, 4941, 4959, 4977, 4995,
  13.     5013, 5031, 5050, 5068, 5086, 5105, 5123, 5142,
  14.     5160, 5179, 5198, 5216, 5235, 5254, 5273, 5292,
  15.     5311, 5331, 5350, 5369, 5389, 5408, 5428, 5447,
  16.     5467, 5487, 5507, 5527, 5547, 5567, 5587, 5607,
  17.     5627, 5648, 5668, 5688, 5709, 5730, 5750, 5771,
  18.     5792, 5813, 5834, 5855, 5876, 5898, 5919, 5940,
  19.     5962, 5983, 6005, 6027, 6049, 6070, 6092, 6114,
  20.     6137, 6159, 6181, 6203, 6226, 6248, 6271, 6294,
  21.     6316, 6339, 6362, 6385, 6408, 6431, 6455, 6478,
  22.     6501, 6525, 6549, 6572, 6596, 6620, 6644, 6668,
  23.     6692, 6716, 6741, 6765, 6789, 6814, 6839, 6863,
  24.     6888, 6913, 6938, 6963, 6988, 7014, 7039, 7064,
  25.     7090, 7116, 7141, 7167, 7193, 7219, 7245, 7271,
  26.     7298, 7324, 7351, 7377, 7404, 7431, 7458, 7485,
  27.     7512, 7539, 7566, 7593, 7621, 7648, 7676, 7704,
  28.     7732, 7760, 7788, 7816, 7844, 7873, 7901, 7930,
  29.     7958, 7987, 8016, 8045, 8074, 8103, 8133, 8162,
  30.     8192
  31. ]
  32.  
  33. def SsPitchFromNote(note, fine, center, shift):
  34.     sfine=fine+shift
  35.     if sfine<0: sfine+=7
  36.     sfine>>=3
  37.  
  38.     add=0
  39.     if sfine>15:
  40.         add=1
  41.         sfine-=16
  42.  
  43.     calc=add+(note-(center-60))
  44.     pitch=_svm_ptable[16*(calc%12)+sfine]
  45.     typ=calc//12-5
  46.  
  47.     # regular shift
  48.     if typ>0: return pitch<<typ
  49.     # negative shift
  50.     if typ<0: return pitch>>-typ
  51.  
  52.     return pitch
  53.  
  54. # 60/80 - in-game pitch, 60/0 - correct pitch
  55. note=60
  56. fine=80
  57.  
  58. if __name__=="__main__":
  59.     fname=sys.argv[1]
  60.     if not fname.lower().endswith(".vca"):
  61.         sys.exit(0)
  62.     dname=os.path.dirname(fname)
  63.     bname=os.path.basename(fname)
  64.  
  65.     f=open(fname,"rb")
  66.     for i in range(999):
  67.         test=f.read(0x04)
  68.         if test==b"\xFF\xFF\xFF\xFF":
  69.             break
  70.  
  71.         f.seek(-4,1)
  72.         values=struct.unpack("<HHBBHIIII", f.read(0x18))
  73.         center=values[2]
  74.         shift=values[3]
  75.         pitch=SsPitchFromNote(note,fine,center,shift)
  76.         freq=pitch*44100//4096
  77.         comment="note: %d fine: %d center: %d shift: %d -> %s -> %s Hz" % (note,fine,center,shift,pitch,freq)
  78.         print(comment)
  79.         f2=open(os.path.join(dname,"%s_%d.txtp" % (bname,i+1)),"w")
  80.         f2.write("%s#s%d#h%d ## %s\n" % (bname,i+1,freq,comment))
  81.         f2.close()
  82.     f.close()
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement