SHARE
TWEET

dedgen.py

a guest Feb 17th, 2017 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import dedenc, os, wave
  2.  
  3. class Bank:
  4.     def __init__(self):
  5.         self.size = 16384
  6.         self.list = []
  7.     def insert(self, item, len):
  8.         if len > self.size: return False
  9.         else:
  10.             self.size = self.size - len
  11.             self.list.append(item)
  12.             return True
  13.  
  14. def tcase(a):
  15.     return a[0].upper() + a[1:]
  16.  
  17. dedpath = os.getcwd() + "/audio/ded/"
  18. print("Generating all DEDs in {}...".format(dedpath))
  19. filelist = os.listdir(dedpath)
  20. lenlist = {}
  21. for filename in filelist:
  22.     if filename[-4:].lower() == ".wav":
  23.         fl = wave.open(dedpath+filename, "rb")
  24.         nf = fl.getnframes()
  25.         ous = dedenc.wavtoded(fl.readframes(nf), fl.getframerate(), fl.getnchannels(), fl.getsampwidth())
  26.         fl.close()
  27.         lenlist[filename[:-4]] = len(ous)
  28.         ouf = open(dedpath+filename[:-4]+".ded", "wb")
  29.         ouf.write(ous)
  30.         ouf.close()
  31.        
  32. banklist = [Bank()]
  33. inpfile = sorted(lenlist, cmp=lambda x,y: cmp(lenlist[y], lenlist[x]))
  34. while len(inpfile) > 0:
  35.     inserted = False
  36.     item = inpfile.pop(0)
  37.     for i in banklist:
  38.         inserted = i.insert(item, lenlist[item])
  39.         if inserted: break
  40.     if not inserted:
  41.         newbank = Bank()
  42.         inserted = newbank.insert(item, lenlist[item])
  43.         if not inserted:
  44.             raise OverflowError("{}'s cry is too big to fit in one bank.".format(tcase(item)))
  45.         banklist.append(newbank)
  46. listfile = open(dedpath+"files.asm","w")
  47. listfile.write("; Auto-generated by dedgen.py\n")
  48. seccount = 0
  49. for i in banklist:
  50.     seccount = seccount + 1
  51.     listfile.write('\nSECTION "DED {0}", ROMX, BANK[DED_{0}]\n\n'.format(seccount))
  52.     for j in i.list:
  53.         listfile.write('{}DEDData:: INCBIN "audio/ded/{}.ded"\n'.format(tcase(j), j))
  54. listfile.close()
  55. print("{} DEDs generated and packed into {} banks.".format(len(lenlist), seccount))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top