-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdedgen.py
55 lines (51 loc) · 1.85 KB
/
dedgen.py
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
import dedenc, os, wave
class Bank:
def __init__(self):
self.size = 16384
self.list = []
def insert(self, item, len):
if len > self.size: return False
else:
self.size = self.size - len
self.list.append(item)
return True
def tcase(a):
return a[0].upper() + a[1:]
dedpath = os.getcwd() + "/audio/deda/"
print("Generating all DEDs in {}...".format(dedpath))
filelist = os.listdir(dedpath)
lenlist = {}
for filename in filelist:
if filename[-4:].lower() == ".wav":
fl = wave.open(dedpath+filename, "rb")
nf = fl.getnframes()
ous = dedenc.wavtoded(fl.readframes(nf), fl.getframerate(), fl.getnchannels(), fl.getsampwidth())
fl.close()
lenlist[filename[:-4]] = len(ous)
ouf = open(dedpath+filename[:-4]+".ded", "wb")
ouf.write(ous)
ouf.close()
banklist = [Bank()]
inpfile = sorted(lenlist, cmp=lambda x,y: cmp(lenlist[y], lenlist[x]))
while len(inpfile) > 0:
inserted = False
item = inpfile.pop(0)
for i in banklist:
inserted = i.insert(item, lenlist[item])
if inserted: break
if not inserted:
newbank = Bank()
inserted = newbank.insert(item, lenlist[item])
if not inserted:
raise OverflowError("{}'s cry is too big to fit in one bank.".format(tcase(item)))
banklist.append(newbank)
listfile = open(dedpath+"files.asm","w")
listfile.write("; Auto-generated by dedgen.py\n")
seccount = 0
for i in banklist:
seccount = seccount + 1
listfile.write('\nSECTION "DED {0}", ROMX\n\n'.format(seccount))
for j in i.list:
listfile.write('{}DEDData:: INCBIN "audio/ded/{}.ded"\n'.format(tcase(j), j))
listfile.close()
print("{} DEDs generated and packed into {} banks.".format(len(lenlist), seccount))