License GNU General Public License, version 3
Lines 90
Keywords
a3000 (1) a4000 (1) python (33) sample (1) wave (1) yamaha (1)
Permissions
Owner: Steven
Viewable by Everyone
Editable by Steven
Hide
Don't get spied on – We respect your privacy and provide numerous options to protect it. Join Siafoo Now or Learn More

Yamadump: Yamaha A Series Sample CD Dumper Atom Feed 0

In Brief Reads a Yamaha A Series (A3000/4000) Sample Library CD and outputs WAV files. Thanks to Stephen Norum for his useful fileformat info (http://www.mybunnyhug.com/fileformats/yamahaaseries/)... more
# 's
 1## TODO: *read command line source and target directories....
2## *clean this nasty shit up
3
4import os
5from string import maketrans
6import struct
7import io
8import wave
9
10##We have to remove non valid characters from filenames so it plays nice
11intab = '"/\*?^ &'
12outtab = '------_n'
13trantab = maketrans(intab,outtab)
14
15## Where to dump the shit
16outdir = 'D:\smps\\'
17## Where to read the shit
18indir = 'E:\\'
19
20for dirname, dirnames, filenames in os.walk(indir):
21 for filename in filenames:
22 ## 0000 file in SMPL directory contains index table to lookup F* files to human
23 ## readable sample description
24 if filename == "0000" and dirname[(len(dirname)-4):len(dirname)] =="SMPL":
25 path = os.path.join(dirname, filename)
26 print path
27 try:
28 sbank = open(path, "rb")
29 sbanksize = os.stat(path).st_size
30 ## Each "bank description" should occupy 32 bytes
31 sbankcount = sbanksize/32
32 print "## OPEN: %s banks from %s" % ((sbankcount, sbank.name))
33 ## Open up the start of the index file
34 sbank.seek(1)
35 for bank in range(sbankcount):
36 ## Read the sample description to volumename and translate it to play nice
37 volumename = sbank.read(16).translate(trantab)
38 #prepare to read bank file name
39 sbank.seek(1, os.SEEK_CUR)
40 ## Read the bank filename
41 bankname = dirname + "\\" + sbank.read(4)
42 #prepare to read next bank, discarding remainder
43 sbank.seek(11, os.SEEK_CUR)
44 print "%s, %s, %s" % (path, volumename, bankname)
45 try:
46 bankfile = io.open(bankname, "rb")
47 bankfilesize = os.stat(bankname).st_size
48 bankfile.seek(0x28)
49 samplerate = [0,0]
50 bankfile.readinto(samplerate)
51 sr = ""
52 for i in samplerate:
53 sr += i
54 samplerate = int(sr.encode('hex'), 16)
55
56 bankfile.seek(0x54)
57 bankdesc = bankfile.read(16).translate(trantab)
58 nchannels = 1
59 sampwidth = 2
60 nframes = (bankfilesize-0x200)/sampwidth
61 time = nframes / samplerate
62 comptype = 'NONE'
63 compname = 'no compression'
64
65 print "%s: %s (%s HZ) %s samples %ss" % (bankname, bankdesc, samplerate, nframes, time)
66 outfile = wave.open(outdir+bankdesc+volumename+".wav", 'wb')
67 outfile.setparams((nchannels, sampwidth, samplerate, nframes, comptype, compname))
68 print "nchannels %s, sampwidth %s, samplerate %s, nframes %s, comptype %s, compname %s" % (nchannels, sampwidth, samplerate, nframes, comptype, compname)
69 bankfile.seek(0x200)
70 framecount = 0
71 frames =""
72 while bankfile.tell() < bankfilesize:
73 buff = [0,0]
74 bankfile.readinto(buff)
75 framecount += 1
76 buff = [buff[1],buff[0]]
77 nf = ""
78 for i in buff:
79 nf += i
80 samplerate = nf.encode('hex')
81
82 frames += str(nf)
83
84 outfile.writeframes(frames)
85 print "Length of frame buffer: %s" % len(frames)
86 print "Bank file position: %s" % bankfile.tell()
87 print "Frame count: %s" % framecount
88
89 outfile.close()
90 bankfile.close()
91
92 except IOError:
93 print "ERROR: Unable to open %s as %s" % (bankfile.name, bankfile.mode)
94
95 ## Maintain offset integrity
96 bank = bank+1
97 sbank.close()
98 except IOError:
99 print "ERROR: Unable to open %s as %s" % ((sbank.name, sbank.mode))

Yamadump

Reads a Yamaha A Series (A3000/4000) Sample Library CD and outputs WAV files. Thanks to Stephen Norum for his useful fileformat info (http://www.mybunnyhug.com/fileformats/yamahaaseries/)