├── .gitattributes ├── .gitignore ├── Brighten.py ├── DPCM.py ├── Extract ├── descramble.py └── extract_samples.py ├── FORMAT.md ├── Import2080.py ├── Import80.py ├── Import990.py ├── LICENSE ├── README.md ├── ROMImport.py ├── ROMScramble.py ├── SMPL Extract.py ├── Template.bin └── runme.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /Brighten.py: -------------------------------------------------------------------------------- 1 | import sys, math, platform, os 2 | 3 | def run(fname): 4 | wav = open(fname, "rb") 5 | print(fname) 6 | #print(fname) 7 | audioFile = wav.read() 8 | 9 | wav.seek(0) 10 | bitRate = audioFile[34] 11 | if bitRate != 16 and bitRate != 24 and bitRate != 32: 12 | print("Error: unsupported bitrate of input!") 13 | return 14 | dataChk = audioFile.find(b'data') 15 | dataPrefix = wav.read(dataChk + 4) 16 | wav.seek(dataChk + 4) 17 | sampleCount = int(int.from_bytes(wav.read(4), "little") / (bitRate / 8)) 18 | 19 | smplLoop = sampleCount - 2 20 | smplEnd = sampleCount - 1 21 | smplChk = audioFile.find(b'smpl') 22 | dataOff = dataChk + 8 23 | if dataChk < smplChk and smplChk < dataChk + sampleCount * bitRate / 8 and dataChk > -1: 24 | smplChk = audioFile.find(b'smpl', 0, dataOff) 25 | if smplChk == -1: 26 | smplChk = audioFile.find(b'smpl', dataOff + dataSz) 27 | if smplChk >= 0 and smplChk + 64 < len(audioFile): 28 | wav.seek(smplChk + 52) 29 | smplLoop = int.from_bytes(wav.read(4), "little") 30 | smplEnd = int.from_bytes(wav.read(4), "little") 31 | 32 | wav.seek(dataOff) 33 | wavSamplesPrep = [] 34 | wavSamples = [] 35 | wavSamplesFinal = [] 36 | for i in range(sampleCount): 37 | End1 = int.from_bytes(wav.read(1), "big") 38 | End2 = int.from_bytes(wav.read(1), "big") 39 | End3 = 0 40 | End4 = 0 41 | Endian = (End2 << 8) + End1 42 | if bitRate > 16: 43 | End3 = int.from_bytes(wav.read(1), "big") 44 | Endian = (End3 << 16) + (End2 << 8) + End1 45 | if bitRate > 24: 46 | End4 = int.from_bytes(wav.read(1), "big") 47 | Endian = (End4 << 16) + (End3 << 16) + (End2 << 8) + End1 48 | if Endian >= 1 << (bitRate - 1): 49 | Endian -= 1 << bitRate 50 | if bitRate == 16: 51 | Endian = Endian << 8 52 | wavSamplesPrep.append(Endian) 53 | dataSuffix = wav.read() 54 | for i in range(16): 55 | wavSamplesPrep.append(wavSamplesPrep[smplEnd - sampleCount + smplLoop + i]) 56 | sampleCountB = len(wavSamplesPrep) 57 | prevDelta = 0 58 | newBitRate = max(bitRate, 24) 59 | wavSamples = [] 60 | prevDelta = 0 61 | prevEndian = 0 62 | for i in range(sampleCountB): 63 | Endian = wavSamplesPrep[i] * 15 / 16 64 | if i > 0: 65 | Endian -= wavSamplesPrep[i - 1] * 15 / 64 66 | if i < len(wavSamplesPrep) - 1: 67 | Endian -= wavSamplesPrep[i + 1] * 15 / 64 68 | wavSamples.append(round(Endian)) 69 | for i in range(sampleCount): 70 | wavSamplesFinal.append(wavSamples[i]) 71 | if not os.path.exists("Brighter"): 72 | os.mkdir("Brighter") 73 | newWav = open("Brighter" + os.path.sep + fname, "wb") 74 | newWav.write(dataPrefix[:4]) 75 | if bitRate == 16: 76 | newSize = int.from_bytes(dataPrefix[4:8], "little") + sampleCount 77 | if sampleCount % 2 == 1: 78 | newSize += 3 79 | newWav.write(newSize.to_bytes(4,"little")) 80 | else: 81 | newWav.write(dataPrefix[4:8]) 82 | newWav.write(dataPrefix[8:28]) 83 | if bitRate == 16: 84 | newSize = int(int.from_bytes(dataPrefix[28:32], "little") * 1.5) 85 | if sampleCount % 2 == 1: 86 | newSize += 3 87 | newWav.write(newSize.to_bytes(4,"little")) 88 | else: 89 | newWav.write(dataPrefix[28:32]) 90 | newWav.write(int(newBitRate / 8).to_bytes(1,"little")) 91 | newWav.write(dataPrefix[33].to_bytes(1,"little")) 92 | newWav.write(newBitRate.to_bytes(1,"little")) 93 | newWav.write(dataPrefix[35].to_bytes(1,"little")) 94 | 95 | newWav.write(dataPrefix[36:]) 96 | if bitRate == 16: 97 | if sampleCount % 2 == 1: 98 | newWav.write(int(sampleCount * 3 + 3).to_bytes(4,"little")) 99 | else: 100 | newWav.write(int(sampleCount * 3).to_bytes(4,"little")) 101 | else: 102 | newWav.write(int(sampleCount * bitRate / 8).to_bytes(4,"little")) 103 | for i in range(len(wavSamplesFinal)): 104 | newWav.write((wavSamplesFinal[i] % (1 << newBitRate)).to_bytes(int(newBitRate / 8), "little")) 105 | if bitRate == 16 and sampleCount % 2 == 1: 106 | newWav.write((0).to_bytes(int(newBitRate / 8), "little")) 107 | newWav.write(dataSuffix) 108 | 109 | wav.close() 110 | newWav.close() 111 | 112 | return 113 | 114 | folder = input("Enter a relative folder for samples to brighten: ") 115 | for file in os.listdir(folder): 116 | if file.endswith(".wav"): 117 | os.chdir(folder) 118 | run(file) 119 | os.chdir("..") 120 | -------------------------------------------------------------------------------- /DPCM.py: -------------------------------------------------------------------------------- 1 | import sys, math, platform, os 2 | 3 | def logo(x): 4 | if abs(x) <= 128: 5 | return 0 6 | elif abs(x >> 1) <= 128: 7 | return 1 8 | elif abs(x >> 2) <= 128: 9 | return 2 10 | elif abs(x >> 3) <= 128: 11 | return 3 12 | elif abs(x >> 4) <= 128: 13 | return 4 14 | elif abs(x >> 5) <= 128: 15 | return 5 16 | elif abs(x >> 6) <= 128: 17 | return 6 18 | elif abs(x >> 7) <= 128: 19 | return 7 20 | elif abs(x >> 8) <= 128: 21 | return 8 22 | elif abs(x >> 9) <= 128: 23 | return 9 24 | elif abs(x >> 10) <= 128: 25 | return 10 26 | elif abs(x >> 11) <= 128: 27 | return 11 28 | elif abs(x >> 12) <= 128: 29 | return 12 30 | elif abs(x >> 13) <= 128: 31 | return 13 32 | elif abs(x >> 14) <= 128: 33 | return 14 34 | else: 35 | return 15 36 | 37 | def DPCMEncode(coefs, deltas, samples, offset, sampleStart, loopType, sampleLoop, smplEnd, VerboseMode): 38 | value = 0 39 | loopValue = 0 40 | loopCoef = 0 41 | invalue = 0 42 | offsetCheck = 0 43 | maxexp = 0 44 | evalCheck = 0 45 | 46 | loopDC = 0 47 | if loopType == 0: 48 | loopDC = (samples[smplEnd] - samples[sampleLoop - 1]) 49 | loopLength = smplEnd - sampleLoop + 1 50 | loopAdjust = loopDC / loopLength 51 | if loopLength < 4: 52 | loopAdjust = 0 53 | if VerboseMode: print("sample loop DC offset: " + str(loopDC) + " (adj=" + str(loopAdjust) + ")") 54 | frameCount = math.ceil(smplEnd / 16) 55 | if smplEnd % 16 == 0 or int(smplEnd / 16) == int(sampleLoop / 16): 56 | frameCount += 1 57 | 58 | #encode all frames except the last one 59 | expChecked = False 60 | for frame in range(frameCount - 1): 61 | maxdelta = 0 62 | eval1 = [] 63 | eval2 = [] 64 | eval3 = [] 65 | eval4 = [] 66 | eval5 = [] 67 | eval6 = [] 68 | for i in range(16): 69 | off = frame * 16 + i 70 | if off > smplEnd: 71 | sample = 0 72 | else: 73 | sample = samples[off] 74 | if off == sampleLoop: 75 | loopFrame = frame 76 | expChecked = True 77 | if (off >= sampleLoop): 78 | adj = int(loopAdjust * (off - sampleLoop)) 79 | sample -= adj 80 | delta = (sample - invalue) 81 | eval1.append(delta) 82 | #if delta < 0: 83 | #delta += 1 84 | if abs(delta) > abs(maxdelta): 85 | maxdelta = delta 86 | invalue = sample 87 | 88 | #decide on coefficient 89 | exp = int(logo(maxdelta)) 90 | if (exp < 0): 91 | exp = 0 92 | elif (exp > 15): 93 | exp = 15 94 | 95 | for i in range(16): 96 | eval2.append((eval1[i] >> exp) % 2) 97 | eval3.append((eval1[i] >> (exp + 1)) % 2) 98 | eval4.append((eval1[i] >> (exp + 2)) % 2) 99 | eval5.append((eval1[i] >> (exp + 3)) % 2) 100 | eval6.append((eval1[i] >> (exp + 4)) % 2) 101 | if 1 not in eval2 and maxdelta != 0: 102 | exp += 1 103 | if 1 not in eval3: 104 | exp += 1 105 | if 1 not in eval4: 106 | exp += 1 107 | if 1 not in eval5: 108 | exp += 1 109 | if 1 not in eval6: 110 | exp += 1 111 | 112 | 113 | if maxexp < exp: 114 | maxexp = exp 115 | 116 | if expChecked == True: 117 | expChecked = False 118 | evalCheck = exp 119 | 120 | #store exponent 121 | if ((frame & 1) == 0): 122 | coefs[int(frame / 2)] = ((int.from_bytes(coefs[int(frame / 2)],"big") & 0xf0) | exp).to_bytes(1,"big") 123 | else: 124 | coefs[int(frame / 2)] = ((int.from_bytes(coefs[int(frame / 2)],"big") & 0x0f) | (exp << 4)).to_bytes(1,"big") 125 | 126 | #compute coefficient only once 127 | coef = 1 << exp 128 | 129 | #compute compressed sample values 130 | for i in range(16): 131 | off = frame * 16 + i 132 | if off > smplEnd: 133 | break 134 | sample = samples[off] 135 | if (off >= sampleLoop): 136 | adj = int(loopAdjust * (off - sampleLoop)) 137 | sample -= adj 138 | delta = (sample - value) 139 | 140 | if delta > (127 << exp): 141 | delta = (127 << exp) 142 | elif delta < (-128 << exp): 143 | delta = (-128 << exp) 144 | #quantize delta 145 | deltas[off] = (int((delta) >> exp) & 0xff).to_bytes(1,"big") 146 | 147 | #predict 148 | qsample = int.from_bytes(deltas[off], "little") 149 | if qsample >= 128: 150 | qsample -= 256 151 | preddelta = qsample << exp 152 | 153 | if (off == sampleLoop) and loopLength >= 4: 154 | loopValue = value 155 | loopCoef = exp 156 | 157 | value += preddelta 158 | #second pass: find smallest exponent in the loop 159 | minexp = 15 160 | for i in range(sampleLoop, (frameCount - 1) * 16, 16): 161 | sampleId = i - sampleStart 162 | if sampleId > smplEnd: 163 | break 164 | frame = int(sampleId / 16) 165 | coef = int.from_bytes(coefs[int(frame / 2)], "big") 166 | 167 | if (frame & 1) == 0: 168 | exp = coef & 15 169 | else: 170 | exp = (coef >> 4) & 15 171 | if (exp < minexp): 172 | minexp = exp 173 | 174 | #third pass: count frames with minimal exponent in the loop 175 | minexpcnt = 0 176 | for i in range(sampleLoop, (frameCount - 1) * 16, 16): 177 | sampleId = i - sampleStart 178 | if sampleId > smplEnd: 179 | break 180 | frame = int(sampleId / 16) 181 | coef = int.from_bytes(coefs[int(frame / 2)], "big") 182 | 183 | if (frame & 1) == 0: 184 | exp = coef & 15 185 | else: 186 | exp = (coef >> 4) & 15 187 | if(exp == minexp): 188 | minexpcnt += 1 189 | 190 | if VerboseMode: print("minimal exponent = " + str(minexp) + " (" + str(minexpcnt) + "x)") 191 | 192 | #fourth pass: compute current DC offset and print it for debugging 193 | decodeValue = loopValue 194 | for i in range(sampleLoop, (frameCount - 1) * 16): 195 | sampleId = i - sampleStart 196 | if sampleId > smplEnd: 197 | break 198 | frame = int(sampleId / 16) 199 | coef = int.from_bytes(coefs[int(frame / 2)], "big") 200 | 201 | if (frame & 1) == 0: 202 | exp = coef & 15 203 | else: 204 | exp = (coef >> 4) & 15 205 | 206 | sample = int.from_bytes(deltas[i], "big") 207 | if sample >= 128: 208 | sample -= 256 209 | delta = sample << exp 210 | decodeValue += delta 211 | if VerboseMode: print("value=" + str(value) + ", decodeValue=" + str(decodeValue)) 212 | 213 | 214 | if int(smplEnd / 16) == int(sampleLoop / 16): 215 | print("Caution: loop in same frame") 216 | print("") 217 | return 218 | 219 | frame = frameCount - 1 220 | end = smplEnd & 0x0f 221 | 222 | #find minimum/maximum of delta in the current frame 223 | maxdelta = 0 224 | eval1 = [] 225 | eval2 = [] 226 | eval3 = [] 227 | eval4 = [] 228 | eval5 = [] 229 | eval6 = [] 230 | for i in range(min(16,end + 2)): 231 | off = frame * 16 + i 232 | if off > smplEnd: 233 | sample = samples[sampleLoop + off - smplEnd] 234 | sample = samples[off] 235 | if (off >= sampleLoop): 236 | adj = int(loopAdjust * (off - sampleLoop)) 237 | sample -= adj 238 | delta = (sample - invalue) 239 | #if delta < 0: 240 | #delta += 1 241 | eval1.append(delta) 242 | if abs(delta) > abs(maxdelta): 243 | maxdelta = delta 244 | invalue = sample 245 | 246 | lastSample = samples[smplEnd] 247 | lastSample -= int(loopAdjust * loopLength) 248 | loopDelta = (loopValue - lastSample) 249 | if loopLength < 4 or loopType != 0: 250 | loopDelta = 0 251 | 252 | adjust = int(loopDelta / (end + 1)) 253 | 254 | if VerboseMode: print("loop delta: " + str(loopDelta) + " (" + str((samples[sampleLoop - 1] - samples[smplEnd])) + ")") 255 | if (end != 0): 256 | if int(abs(loopDelta / (end + 1))) > abs(maxdelta): 257 | maxdelta = int(loopDelta / (end + 1)) 258 | elif int(abs(loopDelta)) > abs(maxdelta): 259 | maxdelta = int(loopDelta) 260 | if VerboseMode: print("loop adjust: " + str(adjust) + " over " + str(end + 1) + " samples") 261 | 262 | 263 | #decide on coefficient 264 | exp = int(logo(maxdelta)) 265 | if (exp < 0): 266 | exp = 0 267 | if (exp > 15): 268 | exp = 15 269 | 270 | for i in range(min(16,end + 2)): 271 | eval2.append((eval1[i] >> exp) % 2) 272 | eval3.append((eval1[i] >> (exp + 1)) % 2) 273 | eval4.append((eval1[i] >> (exp + 2)) % 2) 274 | eval5.append((eval1[i] >> (exp + 3)) % 2) 275 | eval6.append((eval1[i] >> (exp + 4)) % 2) 276 | if 1 not in eval2 and (exp < evalCheck): 277 | exp += 1 278 | if 1 not in eval3 and (exp < evalCheck): 279 | exp += 1 280 | if 1 not in eval4 and (exp < evalCheck): 281 | exp += 1 282 | if 1 not in eval5 and (exp < evalCheck): 283 | exp += 1 284 | if 1 not in eval6 and (exp < evalCheck): 285 | exp += 1 286 | 287 | if maxexp < exp: 288 | maxexp = exp 289 | 290 | coef = 1 << exp 291 | quant = int(adjust / coef * (end + 1)) 292 | quant *= coef 293 | if (quant != loopDelta): 294 | if VerboseMode: print("inherent DC offset: " + str(quant - loopDelta)) 295 | #store exponent 296 | if ((frame & 1) == 0): 297 | coefs[int(frame / 2)] = ((int.from_bytes(coefs[int(frame / 2)],"big") & 0xf0) | exp).to_bytes(1,"big") 298 | else: 299 | coefs[int(frame / 2)] = ((int.from_bytes(coefs[int(frame / 2)],"big") & 0x0f) | (exp << 4)).to_bytes(1,"big") 300 | 301 | for i in range(end + 1): 302 | off = frame * 16 + i 303 | sample = samples[off] 304 | adj = int(loopAdjust * (off - sampleLoop)) 305 | sample -= adj 306 | delta = sample - value + adjust 307 | if delta > (127 << exp): 308 | delta = (127 << exp) 309 | elif delta < (-128 << exp): 310 | delta = (-128 << exp) 311 | 312 | #quantize delta 313 | deltas[off] = (int((delta) >> exp) & 0xff).to_bytes(1,"big") 314 | 315 | #predict 316 | qsample = int.from_bytes(deltas[off], "big") 317 | if qsample >= 128: 318 | qsample -= 256 319 | preddelta = qsample << exp 320 | value += preddelta 321 | 322 | 323 | #Last passes: adjust using minimum 324 | residualDC = 0 325 | if loopType == 0: 326 | residualDC = (loopValue - value) 327 | if abs(residualDC) >> minexp == 0: 328 | residualDC = 0 329 | for expa in range(maxexp - minexp,-1,-1): 330 | adjSign = 0 331 | if math.floor(residualDC >> (minexp + expa)) < 0: 332 | adjSign = -1 333 | elif residualDC >> (minexp + expa) > 0: 334 | adjSign = 1 335 | if (residualDC % (1 << (minexp + expa + 8)) >= 0) and residualDC != 0: 336 | adjustment = residualDC >> (minexp + expa) 337 | if VerboseMode: print("correcting error exactly: " + str(adjustment) + " (" + str(residualDC) + ")") 338 | #adjusting once per sample 339 | for i in range(sampleLoop, (frameCount - 1) * 16): 340 | sampleId = i - sampleStart 341 | frame = int(sampleId / 16) 342 | coef = int.from_bytes(coefs[int(frame / 2)], "big") 343 | if ((frame & 1) == 0): 344 | exp = coef & 0x0f 345 | else: 346 | exp = (coef >> 4) & 0x0f 347 | 348 | if (exp == (minexp + expa) and adjustment != 0): 349 | #perform adjustment 350 | if (0 < int.from_bytes(deltas[i], "big") < 127) or (255 > int.from_bytes(deltas[i], "big") > 128): 351 | byteConv = (int.from_bytes(deltas[i],"big") + adjSign) % 256 352 | deltas[i] = byteConv.to_bytes(1,"big") 353 | adjustment -= adjSign 354 | residualDC -= (adjSign << (minexp + expa)) 355 | 356 | if VerboseMode: print("adjustment: " + str(adjustment)) 357 | 358 | decodeValue = 0 359 | for i in range(sampleLoop, smplEnd + 1): 360 | sampleId = i - sampleStart 361 | frame = int(sampleId / 16) 362 | coef = int.from_bytes(coefs[int(frame / 2)], "big") 363 | 364 | if ((frame & 1) == 0): 365 | exp = coef & 0x0f 366 | else: 367 | exp = (coef >> 4) & 0x0f 368 | sample = int.from_bytes(deltas[i],"big") 369 | if sample >= 128: 370 | sample -= 256 371 | delta = sample << exp 372 | if delta >= 128 << exp: 373 | delta = exp % (128 << exp) 374 | elif delta < -128 << exp: 375 | delta = delta % (128 << exp) - (128 << exp) 376 | decodeValue += delta 377 | if abs(decodeValue) >> minexp == 0: 378 | decodeValue = 0 379 | #check if there is some DC offset 380 | if (decodeValue != 0 and smplEnd - sampleLoop > 1) and loopType == 0: 381 | print("DC offset: " + str(decodeValue)) 382 | elif VerboseMode: 383 | print("no DC offset") 384 | print("") 385 | 386 | def Encode(fname, loopType, smplLoop, smplEnd, VerboseMode): 387 | pwav1 = open(fname, "rb") 388 | pwav2 = open(fname + ".wav", "wb") 389 | pwavr = pwav1.read() 390 | bitRate = pwavr[34] 391 | pwav1.seek(0) 392 | pwav2.write(pwav1.read(pwavr.find(b'data') + 4)) 393 | pwavs = int.from_bytes(pwav1.read(4), "little") 394 | pwav2.write(pwavs.to_bytes(4, "little")) 395 | inbuf = [] 396 | midbuf = [] 397 | outbuf = [] 398 | clip = False 399 | clipbuf = [] 400 | for i in range(int(pwavs / bitRate * 8)): 401 | if bitRate != 24 and bitRate != 32: 402 | print("Error: unsupported bitrate of input!") 403 | return 404 | if bitRate == 24: 405 | inread = int.from_bytes(pwav1.read(3), "little") 406 | if inread >= 1 << 23: 407 | inread -= (1 << 24) 408 | inbuf.append(inread) 409 | else: 410 | inread = int.from_bytes(pwav1.read(4), "little") 411 | if inread >= 1 << 31: 412 | inread -= (1 << 32) 413 | inbuf.append(inread) 414 | for i in range(len(inbuf)): 415 | if i == 0: 416 | midbuf.append(round(inbuf[i])) 417 | clipbuf.append(round(inbuf[i])) 418 | else: 419 | midbuf.append(round((inbuf[i] * 3 - midbuf[len(midbuf) - 1]) / 3)) 420 | clipbuf.append(round((inbuf[i] * 3 + inbuf[i - 1]) / 3)) 421 | for i in range(len(midbuf) - 1, -1, -1): 422 | if i == len(midbuf) - 1: 423 | outbuf.append(round(midbuf[i])) 424 | else: 425 | outbuf.append(round((midbuf[i] * 3 - outbuf[len(outbuf) - 1]) / 3)) 426 | if abs(clipbuf[i] * 3 + clipbuf[i + 1]) / 3 >= (1 << (bitRate - 1)): 427 | clip = True 428 | for i in range(len(outbuf)): 429 | if bitRate == 24: 430 | pwav2.write((round(outbuf[len(inbuf) - 1 - i]) & ((1 << 24) - 1)).to_bytes(3,"little")) 431 | else: 432 | pwav2.write((round(outbuf[len(inbuf) - 1 - i]) & ((1 << 32) - 1)).to_bytes(4,"little")) 433 | pwav2.write(pwav1.read()) 434 | pwav2.close() 435 | pwav1.close() 436 | 437 | wav = open(fname, "rb") 438 | if clip == True: 439 | print("Warning: " + fname + " clipping! Compressing with alternate frequencies...") 440 | wav.close() 441 | wav = open(fname + ".wav", "rb") 442 | #print(fname) 443 | audioFile = wav.read() 444 | wav.seek(0) 445 | bitRate = audioFile[34] 446 | if bitRate != 24 and bitRate != 32: 447 | print("Error: unsupported bitrate of input!") 448 | return 449 | dataChk = audioFile.find(b'data') 450 | wav.seek(dataChk + 4) 451 | sampleCount = int(int.from_bytes(wav.read(4), "little") / (bitRate / 8)) 452 | wav.seek(dataChk + 4) 453 | sampleStart = 0 454 | smplLoop = int(smplLoop) 455 | smplEnd = int(smplEnd) 456 | if smplLoop == 0 and smplEnd == 0: 457 | smplLoop = sampleCount - 1 458 | smplEnd = sampleCount 459 | #smplLoop += 1 460 | #smplEnd += 1 461 | 462 | coefLen = math.ceil((smplEnd + 2) / 32) 463 | 464 | coefs = [] 465 | for i in range(coefLen): 466 | coefs.append(b'\x00') 467 | deltas = [] 468 | for i in range(coefLen * 32): 469 | deltas.append(b'\x00') 470 | print("sample loop: " + str(smplLoop) + " to " + str(smplEnd)) 471 | 472 | wav.seek(dataChk + 8) 473 | wavSamplesPrep = [] 474 | wavSamples = [] 475 | for i in range(sampleCount): 476 | End1 = int.from_bytes(wav.read(1), "big") 477 | End2 = int.from_bytes(wav.read(1), "big") 478 | End3 = int.from_bytes(wav.read(1), "big") 479 | Endian = (End3 << 16) + (End2 << 8) + End1 480 | End4 = 0 481 | if bitRate > 16: 482 | if bitRate > 24: 483 | End4 = int.from_bytes(wav.read(1), "big") 484 | Endian = (End4 << 24) + (End3 << 16) + (End2 << 8) + End1 485 | if Endian >= 1 << (bitRate - 1): 486 | Endian -= 1 << bitRate 487 | wavSamplesPrep.append(Endian) 488 | if loopType == 1 and i >= smplEnd: 489 | continue 490 | for i in range(smplEnd - (smplEnd % 16)): 491 | if loopType == 1: 492 | wavSamplesPrep.append(0) 493 | elif smplEnd + i < sampleCount: 494 | End1 = int.from_bytes(wav.read(1), "big") 495 | End2 = int.from_bytes(wav.read(1), "big") 496 | End3 = int.from_bytes(wav.read(1), "big") 497 | Endian = (End3 << 16) + (End2 << 8) + End1 498 | End4 = 0 499 | if bitRate > 16: 500 | if bitRate > 24: 501 | End4 = int.from_bytes(wav.read(1), "big") 502 | Endian = (End4 << 16) + (End3 << 16) + (End2 << 8) + End1 503 | if Endian >= 1 << (bitRate - 1): 504 | Endian -= 1 << bitRate 505 | wavSamplesPrep.append(Endian) 506 | else: 507 | wavSamplesPrep.append(wavSamplesPrep[smplLoop + i - 1]) 508 | sampleCount = len(wavSamplesPrep) 509 | prevDelta = 0 510 | for i in range(sampleCount): 511 | wavSamples.append(wavSamplesPrep[i] >> (bitRate - 17)) 512 | 513 | DPCMEncode(coefs, deltas, wavSamples, 0, sampleStart, loopType, smplLoop, smplEnd, VerboseMode) 514 | foldersplit = "/" 515 | if platform.system() == "Windows": 516 | foldersplit = "\\" 517 | os.remove(fname + ".wav") 518 | 519 | try: 520 | output1 = open(fname + "_exp.bin", "wb") 521 | for i in range(coefLen): 522 | output1.write(coefs[i]) 523 | output1.close() 524 | except: 525 | print("Error: cannot open exponent file!") 526 | return 527 | try: 528 | output2 = open(fname + "_delt.bin", "wb") 529 | for i in range(coefLen * 32): 530 | output2.write(deltas[i]) 531 | output2.close() 532 | except: 533 | print("Error: cannot open delta file!") 534 | return 535 | -------------------------------------------------------------------------------- /Extract/descramble.py: -------------------------------------------------------------------------------- 1 | def descramble_data8(word): 2 | return ((word & 0x02) << 6) | ((word & 0x08) << 3) | ((word & 0x40) >> 1) | \ 3 | ((word & 0x80) >> 3) | ((word & 0x20) >> 2) | ((word & 0x10) >> 2) | \ 4 | ((word & 0x01) << 1) | ((word & 0x04) >> 2) 5 | 6 | 7 | def descramble_data16(word): 8 | return ((word & 0x0002) << 6) | ((word & 0x0008) << 3) | ((word & 0x0040) >> 1) | \ 9 | ((word & 0x0080) >> 3) | ((word & 0x0020) >> 2) | ((word & 0x0010) >> 2) | \ 10 | ((word & 0x0001) << 1) | ((word & 0x0004) >> 2) | ((word & 0x0200) << 6) | \ 11 | ((word & 0x0800) << 3) | ((word & 0x4000) >> 1) | ((word & 0x8000) >> 3) | \ 12 | ((word & 0x2000) >> 2) | ((word & 0x1000) >> 2) | ((word & 0x0100) << 1) | \ 13 | ((word & 0x0400) >> 2) 14 | 15 | 16 | def descramble_addr(addr, width): 17 | if width == 8: 18 | return ((addr & 0x01) << 1) | ((addr & 0x02) << 3) | ((addr & 0x04) >> 2) | \ 19 | ((addr & 0x08) >> 1) | ((addr & 0x10) >> 1) | ((addr & 0x20) << 10) | \ 20 | ((addr & 0x40) << 4) | ((addr & 0x80) << 10) | ((addr & 0x100) << 6) | \ 21 | ((addr & 0x200) >> 4) | ((addr & 0x400) >> 3) | ((addr & 0x800) << 1) | \ 22 | ((addr & 0x1000) << 4) | ((addr & 0x2000) >> 7) | ((addr & 0x4000) << 4) | \ 23 | ((addr & 0x8000) >> 4) | ((addr & 0x10000) >> 3) | ((addr & 0x20000) >> 8) | \ 24 | ((addr & 0x40000) >> 10) | (addr & 0xFFF80000) 25 | else: 26 | return ((addr & 0x02) << 3) | ((addr & 0x10) >> 3) | ((addr & 0x20) << 3) | \ 27 | ((addr & 0x40) << 6) | ((addr & 0x80) >> 1) | ((addr & 0x100) << 5) | \ 28 | ((addr & 0x200) << 2) | ((addr & 0x400) >> 1) | ((addr & 0x800) << 5) | \ 29 | ((addr & 0x1000) >> 5) | ((addr & 0x2000) >> 8) | ((addr & 0x8000) << 2) | \ 30 | ((addr & 0x10000) >> 6) | ((addr & 0x20000) >> 2) | (addr & 0xFFFC400D) 31 | 32 | 33 | def determine_rom_type(buf): 34 | if buf.startswith(b'JP-800'): 35 | return 8, "JP-800" 36 | elif buf.startswith(b'Roland'): 37 | if buf[0xC:0xF] == b'O\xB0S': 38 | return 8, "SR-JV80" 39 | elif buf[0xC:0xF] == b'O\xB0X': 40 | return 16, "SRX" 41 | else: 42 | raise ValueError(f"Unknown ROM type: {buf[0xC:0xF]}") 43 | else: 44 | raise ValueError(f"Invalid ROM: {buf[:6]}") 45 | 46 | 47 | def descramble(filename): 48 | try: 49 | with open(filename, 'rb') as f: 50 | buf = f.read() 51 | except: 52 | print(f"Error: Cannot open {filename}") 53 | return 54 | 55 | outbuf = bytearray(len(buf)) 56 | 57 | width, rom_type = determine_rom_type(buf) 58 | 59 | print(rom_type + " ROM detected.") 60 | 61 | if width == 16: 62 | for i in range(0, len(buf), 2): 63 | addr = descramble_addr(i, width) 64 | tmp = descramble_data16(int.from_bytes(buf[i:i + 2], 'little')) 65 | outbuf[addr:addr + 2] = tmp.to_bytes(2, 'little') 66 | else: 67 | for i in range(len(buf)): 68 | addr = descramble_addr(i, width) 69 | tmp = descramble_data8(buf[i]) 70 | outbuf[addr] = tmp 71 | 72 | return outbuf 73 | -------------------------------------------------------------------------------- /Extract/extract_samples.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os.path 3 | import struct 4 | import sys 5 | import wave 6 | import re 7 | import json 8 | import descramble 9 | import argparse 10 | import platform 11 | 12 | BLOCK_SIZE = 1024 * 1024 13 | used_samples = set() 14 | 15 | 16 | def loop_type_to_str(loop_type_value): 17 | if loop_type_value == 0x00: 18 | return "forward" 19 | if loop_type_value == 0x01: 20 | return "pingpong" 21 | if loop_type_value == 0x02: 22 | return "noloop" 23 | if loop_type_value == 0x04: 24 | return "reverse" 25 | if loop_type_value == 0x06: 26 | return "reverse" 27 | 28 | return "unknown" 29 | 30 | 31 | def loop_type_to_sfz_loop_type(loop_type_value): 32 | if loop_type_value == 0x00: 33 | return "forward" 34 | if loop_type_value == 0x01: 35 | return "alternate" 36 | if loop_type_value == 0x06: 37 | return "backward" 38 | 39 | return None 40 | 41 | 42 | def loop_type_to_wav_type(loop_type_value): 43 | if loop_type_value == 0x00: 44 | return 0 45 | if loop_type_value == 0x01: 46 | return 1 47 | if loop_type_value == 0x06: 48 | return 2 49 | 50 | return None 51 | 52 | 53 | def modelid_to_str(model_id): 54 | if model_id == 0x02: 55 | return "JV80" 56 | elif model_id == 0x03: 57 | return "JD990" 58 | elif model_id == 0x05: 59 | return "JV1080" 60 | else: 61 | return "unknown: " + hex(model_id) 62 | 63 | 64 | def number_to_note(note_number): 65 | # Define the note names 66 | note_names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] 67 | 68 | # Determine the note and octave 69 | note = note_names[(note_number - 36) % 12] 70 | octave = (note_number // 12) - 1 71 | 72 | return note + str(octave) 73 | 74 | 75 | def read_header(block_num, file): 76 | offset = block_num * BLOCK_SIZE 77 | header = {} 78 | 79 | file.seek(offset + 0x20) 80 | card_name_bytes = file.read(16) 81 | header["card_name"] = card_name_bytes.decode( 82 | 'ascii').strip().replace("\x00", "") # Strip to remove any potential padding or trailing spaces 83 | 84 | file.seek(offset + 0x53) 85 | header["supported_model_id"] = struct.unpack(">B", file.read(1))[0] 86 | header["supported_model_id_str"] = modelid_to_str(header["supported_model_id"]) 87 | 88 | file.seek(offset + 0x40) 89 | header["sample_rate"] = struct.unpack(">H", file.read(2))[0] * 100 90 | 91 | file.seek(offset + 0x60) 92 | header["number_of_samples"] = struct.unpack(">H", file.read(2))[0] 93 | header["number_of_multisamples"] = struct.unpack(">H", file.read(2))[0] 94 | header["number_of_drumkits"] = struct.unpack(">H", file.read(2))[0] 95 | header["number_of_patches"] = struct.unpack(">H", file.read(2))[0] 96 | 97 | file.seek(offset + 0x80) 98 | header["sample_table_position"] = struct.unpack(">I", file.read(4))[0] 99 | header["multisample_table_position"] = struct.unpack(">I", file.read(4))[0] 100 | header["drumkit_table_position"] = struct.unpack(">I", file.read(4))[0] 101 | header["patch_table_position"] = struct.unpack(">I", file.read(4))[0] 102 | 103 | return header 104 | 105 | 106 | def read_multisamples_table(file, multisamples_table_pos, header): 107 | multisamples = [] 108 | 109 | file.seek(multisamples_table_pos) 110 | 111 | for i in range(header["number_of_multisamples"]): 112 | multisample = {} 113 | name_bytes = file.read(12) 114 | multisample["multisample_id"] = i 115 | multisample["multisample_name"] = name_bytes.decode( 116 | 'ascii').strip() # Strip to remove any potential padding or trailing spaces 117 | multisample["high_key"] = [] 118 | for _ in range(16): 119 | high_key = struct.unpack(">B", file.read(1))[0] 120 | # print(str(high_key) + "/" + number_to_note(high_key)) 121 | multisample["high_key"].append(high_key) 122 | 123 | # print("---------") 124 | 125 | # sample id: 65535 is probably unused 126 | multisample["sample_id"] = [] 127 | for _ in range(16): 128 | sample_id = struct.unpack(">H", file.read(2))[0] 129 | # print(sample_id) 130 | multisample["sample_id"].append(sample_id) 131 | 132 | # print("=========") 133 | 134 | multisamples.append(multisample) 135 | 136 | return multisamples 137 | 138 | 139 | def read_sample_table(file, sample_table_pos, header): 140 | samples = [] 141 | file.seek(sample_table_pos) 142 | for i in range(header["number_of_samples"]): 143 | sample = {} 144 | sample["id"] = i 145 | sample["volume"] = struct.unpack(">B", file.read(1))[0] 146 | sample["sample_start"] = struct.unpack(">I", b'\x00' + file.read(3))[0] 147 | sample["loop_start"] = struct.unpack(">I", b'\x00' + file.read(3))[0] 148 | sample["sample_end"] = struct.unpack(">I", b'\x00' + file.read(3))[0] 149 | sample["unknown"] = struct.unpack(">H", file.read(2))[0] 150 | sample["loop_type"] = struct.unpack(">B", file.read(1))[0] 151 | sample["loop_type_str"] = loop_type_to_str(sample["loop_type"]) 152 | sample["root_key"] = struct.unpack(">B", file.read(1))[0] 153 | sample["root_key_str"] = number_to_note(sample["root_key"]) 154 | sample["fine_tune"] = struct.unpack(">H", file.read(2))[0] 155 | sample["loop_fine_tune"] = struct.unpack(">H", file.read(2))[0] 156 | sample["sample_offset"] = 0 157 | sample["sample_delay"] = (sample["sample_start"] % 16) 158 | for j in range(len(samples)): 159 | if sample["sample_end"] == samples[j]["sample_end"]: 160 | if sample["sample_start"] < samples[j]["sample_start"]: 161 | sample["sample_offset"] = 0 162 | samples[j]["sample_offset"] = samples[j]["sample_start"] - sample["sample_start"] 163 | samples[j]["sample_start"] -= samples[j]["sample_offset"] 164 | sample["sample_delay"] = sample["sample_start"] % 16 165 | elif sample["sample_start"] > samples[j]["sample_start"]: 166 | sample["sample_offset"] = sample["sample_start"] - samples[j]["sample_start"] 167 | sample["sample_start"] -= sample["sample_offset"] 168 | sample["sample_delay"] = samples[j]["sample_start"] % 16 169 | sample["sample_trim"] = 0 170 | samples.append(sample) 171 | return samples 172 | 173 | 174 | def read_all_exponents(block_count, block_size, file): 175 | # For each block, extract exponents 176 | all_exponents = [] 177 | 178 | for block_number in range(block_count): 179 | block_start_offset = block_number * block_size 180 | exponent_start_offset = block_start_offset + 1024 181 | 182 | file.seek(exponent_start_offset) 183 | exponents_in_block = file.read(31*1024) 184 | all_exponents.append(exponents_in_block) 185 | 186 | return all_exponents 187 | 188 | 189 | def get_block_number(sample_start, block_size): 190 | block_start = sample_start // block_size 191 | 192 | return block_start 193 | 194 | 195 | def create_sampler_chunk(loop_start, loop_end, loop_type, framerate, root_note): 196 | smpl_chunk = ( 197 | b'smpl' + # Chunk ID 198 | (36 + 24).to_bytes(4, byteorder='little') + # Chunk size (36 bytes for header + 24 bytes per loop) 199 | (0).to_bytes(4, byteorder='little') + # Manufacturer 200 | (0).to_bytes(4, byteorder='little') + # Product 201 | (int(1e9 / framerate)).to_bytes(4, byteorder='little') + # Sample period in ns 202 | # (0).to_bytes(4, byteorder='little') + # Sample period in ns 203 | root_note.to_bytes(4, byteorder='little') + # MIDI unity note 204 | (0).to_bytes(4, byteorder='little') + # MIDI pitch fraction 205 | (0).to_bytes(4, byteorder='little') + # SMPTE format 206 | (0).to_bytes(4, byteorder='little') + # SMPTE offset 207 | (1).to_bytes(4, byteorder='little') + # Number of sample loops 208 | (0).to_bytes(4, byteorder='little') + # Sampler data 209 | (0).to_bytes(4, byteorder='little') + # Cue point ID 210 | loop_type.to_bytes(4, byteorder='little') + # Loop type (0 = forward loop) 211 | loop_start.to_bytes(4, byteorder='little') + # Loop start 212 | loop_end.to_bytes(4, byteorder='little') + # Loop end 213 | (0).to_bytes(4, byteorder='little') + # Fraction 214 | (0).to_bytes(4, byteorder='little') # Play count (0 = infinite) 215 | ) 216 | 217 | return smpl_chunk 218 | 219 | 220 | def create_instrument_chunk(root_note, fine_tuning, gain, low_note, high_note, low_velocity, high_velocity): 221 | inst_chunk = ( 222 | b'inst' + # Chunk ID 223 | (7).to_bytes(4, byteorder='little') + # Chunk size (7 bytes) 224 | root_note.to_bytes(1, byteorder='little') + # unshifted note / root note (1 byte) 225 | (0).to_bytes(1, byteorder='little') + # fine tuning (1 byte) 226 | (0).to_bytes(1, byteorder='little') + # gain (1 byte) 227 | low_note.to_bytes(1, byteorder='little') + # low note (1 byte) 228 | high_note.to_bytes(1, byteorder='little') + # high note (1 byte) 229 | (0).to_bytes(1, byteorder='little') + # low velocity (1 byte) 230 | (127).to_bytes(1, byteorder='little') + # high velocity (1 byte) 231 | (0).to_bytes(1, byteorder='little') # padding for even number of bytes in the chunk 232 | ) 233 | 234 | return inst_chunk 235 | 236 | 237 | def decode_dpcm(deltas, exponents, sample_start, block_of_sample): 238 | decoded_samples_24bit = [] 239 | decoded_sample = 0 240 | 241 | num_frames = math.ceil(len(deltas) / 16) 242 | 243 | if num_frames == 0: 244 | num_frames = 1 245 | 246 | sample_start_offset_in_block = (sample_start - 31 * 1024 - 1024) - (block_of_sample * BLOCK_SIZE) 247 | for frame in range(num_frames): 248 | exp_byte = exponents[(sample_start_offset_in_block // (16*2)) + frame//2] 249 | if frame & 1 == 0: 250 | exp = exp_byte & 0x0F 251 | else: 252 | exp = (exp_byte >> 4) & 0x0F 253 | 254 | for i in range(16): 255 | index = frame * 16 + i 256 | 257 | if index >= len(deltas): 258 | break 259 | 260 | delta_byte = deltas[index] 261 | if delta_byte >= 128: 262 | delta_byte -= 256 263 | 264 | original_delta = delta_byte << exp 265 | decoded_sample += original_delta 266 | clipped_sample = decoded_sample << 7 267 | 268 | # 24-bit clipping 269 | if clipped_sample < -8388608: 270 | clipped_sample = -8388608 271 | if clipped_sample > 8388607: 272 | clipped_sample = 8388607 273 | 274 | decoded_samples_24bit.append(clipped_sample) 275 | 276 | return decoded_samples_24bit 277 | 278 | 279 | def loop_unroll_pingpong(pcm_data, loop_start, end_sample): 280 | loop_data = pcm_data[loop_start:end_sample] 281 | reversed_inverted_loop_data = [-x if x != -8388608 else 8388607 for x in loop_data][::-1] 282 | 283 | unrolled_pcm_data = pcm_data + reversed_inverted_loop_data 284 | new_sample_end = end_sample + len(reversed_inverted_loop_data) 285 | 286 | return new_sample_end, unrolled_pcm_data 287 | 288 | 289 | def loop_unroll_reverse(sample, pcm_data, loop_start, end_sample): 290 | # It turns out that Roland means with loop invese that always the whole sample is inversed. 291 | # The loop points seem to be irrelevant. 292 | reversed_loop_data = [x for x in pcm_data][::-1] 293 | 294 | # unrolled_pcm_data = pcm_data[:loop_start-1] + reversed_loop_data 295 | unrolled_pcm_data = reversed_loop_data 296 | new_sample_end = sample["sample_end"] 297 | 298 | return new_sample_end, unrolled_pcm_data 299 | 300 | 301 | def write_samples_to_pcm(file, multisamples, samples, all_exponents, loop_unroll_flag, header): 302 | name_whitelisted_characters = r'[^a-zA-Z0-9_]' 303 | 304 | print("=[multisample samples]==================") 305 | # step 1: write multisamples 306 | fine_tune_low = None 307 | fine_tune_high = None 308 | start_list = [] 309 | end_list = [] 310 | for idx_multisample, multisample in enumerate(multisamples): 311 | sample_ids = multisample["sample_id"] 312 | multisample_name_compact = re.sub(r'[<>:"\|?*]', '_', multisample["multisample_name"])#.replace(" ", "_").lower() 313 | #multisample_name_compact = re.sub(name_whitelisted_characters, '', multisample_name_compact) 314 | 315 | multisample_id = str(multisample['multisample_id'] + 1).zfill(3) 316 | 317 | sfz_content = "" 318 | #sfz_content_la = "" 319 | # group opcode unsupported by falcon, thus removed and inlined 320 | # sfz_content = "\n" 321 | # sfz_content += " lovel=0 hivel=127\n" 322 | for idx_sample_prep, sample_id_prep in enumerate(sample_ids): 323 | if sample_id_prep == 65535: 324 | continue 325 | 326 | startMin = samples[sample_id_prep]["sample_start"] 327 | endMax = samples[sample_id_prep]["sample_end"] 328 | finalID = sample_id_prep 329 | for sample_id_search in range(header["number_of_samples"]): 330 | if samples[sample_id_prep]["sample_end"] == samples[sample_id_search]["sample_end"]: 331 | finalID = min(finalID,sample_id_search) 332 | startMin = min(samples[sample_id_prep]["sample_start"], samples[sample_id_search]["sample_start"]) 333 | 334 | sample_id = finalID 335 | idx_sample = idx_sample_prep 336 | 337 | sample = samples[sample_id] 338 | used_samples.add(sample_id) 339 | 340 | #if samples[sample_id_prep]["sample_offset"] > 0: 341 | #print(multisample_name_compact) 342 | #print(samples[sample_id_prep]["sample_offset"]) 343 | 344 | block_of_sample = get_block_number(startMin, BLOCK_SIZE) 345 | data_offset_in_block = (block_of_sample * BLOCK_SIZE + 1024 + (31 * 1024)) 346 | 347 | length = endMax - startMin + 1 + (startMin % 16) 348 | if length % 16 > 0: 349 | while length % 16 > 0: 350 | length += 1 351 | 352 | if length <= 0: 353 | print("sample start before end. skipping.") 354 | continue 355 | 356 | 357 | file.seek(startMin-(startMin % 16)) 358 | deltas = file.read(length) 359 | 360 | exponents_block = all_exponents[block_of_sample] 361 | pcm_data_24bit = decode_dpcm(deltas, exponents_block, startMin - (startMin % 16), block_of_sample) 362 | 363 | start_sample_offset = startMin - 1024 - 31*1024 - block_of_sample*BLOCK_SIZE 364 | 365 | loop_start = samples[sample_id_prep]["loop_start"] - 1024 - 31*1024 - block_of_sample*BLOCK_SIZE - start_sample_offset 366 | end_sample = samples[sample_id_prep]["sample_end"] - 1024 - 31*1024 - block_of_sample*BLOCK_SIZE - start_sample_offset 367 | 368 | #if loop_unroll_flag and sample['loop_type_str'] == "pingpong": 369 | #end_sample, pcm_data_24bit = loop_unroll_pingpong(pcm_data_24bit, loop_start, end_sample) 370 | 371 | #if loop_unroll_flag and sample['loop_type_str'] == "reverse": 372 | #end_sample, pcm_data_24bit = loop_unroll_reverse(sample, pcm_data_24bit, loop_start, end_sample) 373 | 374 | bytes_list = [(sample % 16777216).to_bytes(3, "little") for sample in pcm_data_24bit] 375 | pcm_data_bytearray = b''.join(bytes_list) 376 | 377 | multisample_sample_id = str(idx_sample+1).zfill(2) 378 | 379 | high_key = multisample["high_key"][idx_sample] 380 | high_key_str = number_to_note(high_key) 381 | 382 | low_key = 0 383 | if idx_sample > 0: 384 | low_key = multisample["high_key"][idx_sample-1]+1 385 | low_key_str = number_to_note(low_key) 386 | 387 | filename = f"{sample_id}".zfill(5) + ".wav" 388 | 389 | #inst_chunk = None 390 | #if sample["root_key"] is not None: 391 | #inst_chunk = create_instrument_chunk(sample['root_key'], 0, 0, low_key, high_key, 0, 127) 392 | 393 | wav_loop_type = loop_type_to_wav_type(sample['loop_type']) 394 | framerate = header["sample_rate"] 395 | smpl_chunk = None 396 | 397 | #if loop_unroll_flag and (samples[sample_id_prep]'loop_type_str'] == "pingpong" or samples[sample_id_prep]'loop_type_str'] == "reverse"): 398 | #wav_loop_type = 0 399 | 400 | #if wav_loop_type is not None and (loop_start >= 0) and (loop_start <= end_sample): 401 | #smpl_chunk = create_sampler_chunk(loop_start, end_sample, wav_loop_type, framerate, sample['root_key']) 402 | 403 | with wave.open(filename, 'wb') as wf: 404 | wf.setnchannels(1) 405 | wf.setsampwidth(3) # 2=16bit, 3=24bit, 4=32bit 406 | wf.setframerate(framerate) 407 | wf.writeframes(pcm_data_bytearray) 408 | 409 | #add_chunk(filename, smpl_chunk) 410 | #if inst_chunk is not None: 411 | #add_chunk(filename, inst_chunk) 412 | 413 | fine_tune = sample["fine_tune"] 414 | 415 | if fine_tune_low is None: 416 | fine_tune_low = fine_tune 417 | if fine_tune_high is None: 418 | fine_tune_high = fine_tune 419 | 420 | if fine_tune < fine_tune_low: 421 | fine_tune_low = fine_tune 422 | 423 | if fine_tune > fine_tune_high: 424 | fine_tune_high = fine_tune 425 | 426 | fine_tune -= 1024 427 | loop_fine_tune = sample["loop_fine_tune"] - 1024 428 | 429 | region_content = ("\nsample=" + str(filename) + 430 | "\nregion_label=" + str(sample_id_prep).zfill(5) + ".wav" + 431 | "\namplitude=" + str(round(sample["volume"] / 1.27, 3)) + 432 | "\nlokey=" + str(low_key) + "\nhikey=" + str(high_key) + 433 | "\npitch_keycenter=" + str(sample["root_key"]) + 434 | "\ntune=" + str(round((fine_tune*100 / 1024), 3)) + 435 | "\ndelay_samples=" + str(samples[sample_id_prep]["sample_delay"]) + 436 | "\noffset=" + str(samples[sample_id_prep]["sample_offset"])) 437 | sfz_content += region_content 438 | #sfz_content_la += region_content 439 | 440 | sfz_loop_type = loop_type_to_sfz_loop_type(samples[sample_id_prep]["loop_type"]) 441 | 442 | if loop_unroll_flag: 443 | sfz_loop_type = "forward" 444 | 445 | if (samples[sample_id_prep]['loop_type_str'] == "reverse"): 446 | sfz_content += ("\ndirection=reverse") 447 | #sfz_content_la += ("\ndirection=reverse") 448 | 449 | if ((0 <= loop_start <= end_sample and sfz_loop_type is not None) and 450 | not (samples[sample_id_prep]['loop_type_str'] == "reverse")): 451 | sfz_content += ("\nloop_start=" + str(loop_start + samples[sample_id_prep]["sample_delay"]) + 452 | "\nloop_end=" + str(end_sample + samples[sample_id_prep]["sample_delay"]) + 453 | "\nloop_type=" + str(sfz_loop_type) + 454 | "\nlooptune=" + str(round((loop_fine_tune*100 / 1024), 3)) + 455 | "\nloop_mode=loop_continuous") 456 | #sfz_content_la += ("\nloop_start=" + str(loop_start) + 457 | #"\nloop_end=" + str(end_sample+1) + 458 | #"\nloop_type=" + str(sfz_loop_type) + 459 | #"\nloop_mode=loop_continuous" 460 | #) 461 | else: 462 | loop_content = "\nloop_mode=no_loop" + "\nlooptune=" + str(round((loop_fine_tune*100 / 1024), 3)) 463 | sfz_content += loop_content 464 | #sfz_content_la += loop_content 465 | 466 | sfz_content += "\n\n" 467 | #sfz_content_la += "\n" 468 | 469 | sfz_filename = f"{multisample_id}-{multisample_name_compact}.sfz" 470 | if platform.system() != "Windows": 471 | sfz_filename = sfz_filename.replace("/",":") 472 | #sfz_filename_la = f"{multisample_id}-{multisample_name_compact}_la.sfz" 473 | with open(sfz_filename, 'w') as sfz_file: 474 | sfz_file.write(sfz_content) 475 | #with open(sfz_filename_la, 'w') as sfz_file: 476 | #sfz_file.write(sfz_content_la) 477 | 478 | # print("fine_tune_high: " + str(fine_tune_high)) 479 | # print("fine_tune_low: " + str(fine_tune_low)) 480 | 481 | print("done.") 482 | 483 | 484 | def add_chunk(filename, chunk): 485 | if chunk is not None: 486 | with open(filename, 'rb') as original_wav: 487 | original_wav_data = original_wav.read() 488 | 489 | with open(filename, 'wb') as updated_wav: 490 | updated_wav.write(original_wav_data) 491 | updated_wav.write(chunk) 492 | updated_wav.seek(0, 2) 493 | final_size = updated_wav.tell() 494 | final_size -= 8 495 | updated_wav.seek(4) 496 | updated_wav.write(final_size.to_bytes(4, byteorder='little')) 497 | 498 | 499 | def main(scrambled_rom_file, loop_unroll=False): 500 | output_filename = scrambled_rom_file + ".descrambled.bin" 501 | if not os.path.exists(output_filename): 502 | descrambled_rom = descramble.descramble(scrambled_rom_file) 503 | with open(output_filename, 'wb') as file: 504 | file.write(descrambled_rom) 505 | 506 | print(f'Descrambled ROM has been written to {output_filename}') 507 | 508 | with open(output_filename, "rb") as file: 509 | for i in range(1): 510 | print("-[Header Block " + str(i) + "]--------------------------") 511 | header = read_header(i, file) 512 | print(json.dumps(header, indent=4, sort_keys=True)) 513 | header = read_header(0, file) 514 | 515 | print("---------------------------") 516 | 517 | all_exponents = read_all_exponents(8, BLOCK_SIZE, file) 518 | samples = read_sample_table(file, header["sample_table_position"], header) 519 | multisamples = read_multisamples_table(file, header["multisample_table_position"], header) 520 | # print(json.dumps(multisamples, indent=4, sort_keys=True)) 521 | #samples = decorate_samples_with_multisample_name(multisamples, samples) 522 | # print(json.dumps(samples, indent=4, sort_keys=True)) 523 | write_samples_to_pcm(file, multisamples, samples, all_exponents, loop_unroll, header) 524 | 525 | 526 | if __name__ == "__main__": 527 | parser = argparse.ArgumentParser(description="Extract waveforms and SFZ files from an SR-JV80 card ROM image") 528 | parser.add_argument("filename", type=str, help="The name of the file to process") 529 | parser.add_argument("--loopunroll", action="store_true", help="Unroll pingpong loops as forward loops") 530 | args = parser.parse_args() 531 | 532 | main(args.filename, args.loopunroll) 533 | -------------------------------------------------------------------------------- /FORMAT.md: -------------------------------------------------------------------------------- 1 | # SRJV Format Information 2 | 3 | ## General 4 | 5 | The SR-JV80 ROM format consists of a scrambled collection of 8 1MB blocks, big endian format, merged into one ROM image file. Each block contains the following: 6 | 7 | * 1 KB of header information 8 | * 31 KB of exponents for the compressed sample data 9 | * 992KB of everything else, mostly delta samples 10 | 11 | > * The first block contains compatible data for one series of models, usually the JV-80, in the header section 12 | > 13 | > * If there are specific patches and drumkits for another model (i.e. JV-1080+ or the JD-990), the compatible data for that model is located in the second block's header section 14 | > 15 | > * The sample, multisample, patch, and drumkit tables are all stored in what's otherwise reserved for ADPCM delta samples. Theoretically, these tables can be positioned anywhere in that section, but in the standard cards, these are reserved for the end of the last block. 16 | 17 | ## Header 18 | 19 | * 0x0000000 - 32 bytes - encrypted information about the card (perversely, the scrambling program will make these bytes readable to the average human being, whereas unscrambling is needed for the rest of the block) 20 | * 0x0000020 - 16 bytes - ASCII name of the card 21 | * 0x0000030 - 10 bytes - ROM date 22 | * 0x000003a - 6 bytes - unknown purpose, usually "0xffffffffffff" 23 | * 0x0000040 - 4 byte - unknown purpose, usually "0x01400000" 24 | * 0x0000044 - 1 byte - block number to point to with more model data (i.e. "0x10" in the first block to the second, "0x20" in the second to third, etc.) Last block with important data has this set to "0x08" 25 | * 0x0000050 - 2 bytes - unknown purpose, seemingly always "0x0201" in the first block 26 | * 0x0000053 - 1 byte - supported model ID. Known values: 0x02 (JV-80), 0x03 (JD-990), 0x05 (JV-1080) 27 | * 0x0000054 - 1 byte - number of drumkits per bank? 28 | * 0x000005f - 1 byte - unknown purpose, "0x03" or "0x00" 29 | * 0x0000060 - 2 bytes - number of raw samples (first block only) 30 | * 0x0000062 - 2 bytes - number of multisamples (first block only) 31 | * 0x0000066 - 2 bytes - number of patches (max 256) 32 | * 0x0000068 - 2 bytes - number of drumkits (max 8, possibly?) 33 | * 0x000007f - 1 byte - unknown purpose 34 | * 0x0000080 - 4 bytes - pointer to start of sample table (first table if not first block) 35 | * 0x0000084 - 4 bytes - pointer to start of multisample table (first table if not first block) 36 | * 0x000008c - 4 bytes - pointer to start of patch table 37 | * 0x0000090 - 4 bytes - pointer to start of drumkit table 38 | * 0x00000bc - 4 bytes - unknown table pointer 39 | * 0x00000fd - 3 bytes - first and last bytes are the block number 40 | 41 | ## Sample Table 42 | 43 | (per entry, 18 bytes each) 44 | * 0x000000 - 1 byte - volume byte (max is 0x7f) 45 | * 0x000001 - 3 bytes - pointer to sample start 46 | * 0x000004 - 3 bytes - pointer to sample loop start 47 | * 0x000007 - 3 bytes - pointer to sample end 48 | * 0x00000a - 2 bytes - unknown purpose 49 | * 0x00000c - 1 byte - loop type. Known values: 0x00 (forward loop), 0x01 (ping-pong loop), 0x02 (no loop), 0x04 (reverse), 0x06 (reverse, non-JD only) 50 | * 0x00000d - 1 byte - root key 51 | * 0x00000e - 2 bytes - fine tune, 1/1024ths of a semitone 52 | * 0x000010 - 2 bytes - loop fine tune, 1/1024ths of a semitone 53 | 54 | ## Multisample Table 55 | 56 | (per entry, 60 bytes each): 57 | * 0x000000 - 12 bytes - ASCII name of multisample 58 | * 0x00000c - 16 bytes - high key of sample, 1 byte for each of 16 samples 59 | * 0x00001c - 32 bytes - sample ID in order of sample table, 2 bytes for each of 16 samples 60 | 61 | ## Patch Table Information 62 | 63 | Obviously the patch data format varies depending on model. The JV-80 and JD-990 formats are stored in a fairly straightforward manner, with slight arrangement variations from their SysEx equivalents (and without the SysEx headers, obviously). Unfortunately, with the JV-1080, to save space, the patch data is compressed by number of bits each parameter is supposed to use. Add to the complications that when a parameter spans multiple bytes, the least significant bits are transferred to the most significant bits of the next byte in line. A Python module has already been created to handle most parameters from the JV-2080 (importance being the JV-2080 introduced patch categories, also stored in this table), but if you wish to look into specific parameters for yourself, quick advice is to read the SysEx manual, note how many bytes all parameters use total, and determine the bit, not byte, offset from that. -------------------------------------------------------------------------------- /Import2080.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | offset = 0 4 | bits = [] 5 | bitResult = [] 6 | isSysex = False 7 | 8 | def parseBits(bitNum): 9 | global offset 10 | global bits 11 | global out_file 12 | global bitResult 13 | for k in range(8): 14 | if k < bitNum: 15 | bitResult.append(bits[offset]) 16 | offset += 1 17 | 18 | def run(in_string): 19 | global offset 20 | global bits 21 | global out_file 22 | global bitResult 23 | in_file = open(in_string + ".syx", "rb") 24 | out_file = open(in_string + ".patches", "wb") 25 | if in_file.read(1) == b'\xf0': 26 | isSysex = True 27 | startOffset = 0 28 | if isSysex == True: 29 | in_file.seek(9) 30 | firstMessage = int.from_bytes(in_file.read(1),"big") 31 | if (firstMessage < 32): 32 | startOffset = 12 33 | in_file.seek(0,2) 34 | patchCount = int((in_file.tell() - startOffset) / 645) 35 | 36 | in_file.seek(startOffset) 37 | 38 | for i in range(patchCount): 39 | scan = in_file.tell() 40 | result = out_file.tell() 41 | bits.clear() 42 | bitResult.clear() 43 | if isSysex == True: 44 | in_file.seek(scan + 9) 45 | for j in range(74): 46 | byte = int.from_bytes(in_file.read(1), "big") 47 | bits.append(byte & 1) 48 | bits.append((byte & 2) >> 1) 49 | bits.append((byte & 4) >> 2) 50 | bits.append((byte & 8) >> 3) 51 | bits.append((byte & 16) >> 4) 52 | bits.append((byte & 32) >> 5) 53 | bits.append((byte & 64) >> 6) 54 | bits.append((byte & 128) >> 7) 55 | for k in range(4): 56 | in_file.seek(11,1) 57 | for j in range(129): 58 | byte = int.from_bytes(in_file.read(1), "big") 59 | bits.append(byte & 1) 60 | bits.append((byte & 2) >> 1) 61 | bits.append((byte & 4) >> 2) 62 | bits.append((byte & 8) >> 3) 63 | bits.append((byte & 16) >> 4) 64 | bits.append((byte & 32) >> 5) 65 | bits.append((byte & 64) >> 6) 66 | bits.append((byte & 128) >> 7) 67 | else: 68 | for j in range(590): 69 | byte = int.from_bytes(in_file.read(1), "big") 70 | bits.append(byte & 1) 71 | bits.append((byte & 2) >> 1) 72 | bits.append((byte & 4) >> 2) 73 | bits.append((byte & 8) >> 3) 74 | bits.append((byte & 16) >> 4) 75 | bits.append((byte & 32) >> 5) 76 | bits.append((byte & 64) >> 6) 77 | bits.append((byte & 128) >> 7) 78 | offset = 0 79 | for j in range(12): 80 | parseBits(7) 81 | #MFX 82 | parseBits(6) 83 | for j in range(12): 84 | parseBits(7) 85 | parseBits(2) 86 | for j in range(3): 87 | parseBits(7) 88 | parseBits(4) 89 | parseBits(7) 90 | parseBits(4) 91 | parseBits(7) 92 | #Chorus 93 | for j in range(5): 94 | parseBits(7) 95 | parseBits(2) 96 | #Reverb 97 | parseBits(3) 98 | for j in range(2): 99 | parseBits(7) 100 | parseBits(5) 101 | parseBits(7) 102 | #Misc Common 103 | offset += 8 104 | parseBits(4) 105 | offset -= 16 106 | parseBits(4) 107 | offset += 8 108 | for j in range(3): 109 | parseBits(7) 110 | parseBits(4) 111 | parseBits(6) 112 | for j in range(6): 113 | parseBits(1) 114 | parseBits(7) 115 | for j in range(2): 116 | parseBits(4) 117 | for j in range(4): 118 | parseBits(2) 119 | parseBits(1) 120 | parseBits(3) 121 | parseBits(2) 122 | parseBits(1) 123 | #Tone Structure 124 | parseBits(4) 125 | parseBits(2) 126 | parseBits(4) 127 | parseBits(2) 128 | #JV-2080 and Up: Clock Source and Category 129 | parseBits(1) 130 | parseBits(7) 131 | for b in range(12): 132 | bitResult.append(0) 133 | #Tones 134 | for t in range(4): 135 | parseBits(1) 136 | parseBits(2) 137 | parseBits(7) 138 | offset += 8 139 | parseBits(4) 140 | offset -= 16 141 | parseBits(4) 142 | offset += 8 143 | parseBits(2) 144 | parseBits(1) 145 | parseBits(2) 146 | parseBits(4) 147 | parseBits(3) 148 | parseBits(7) 149 | #Mods 150 | for j in range(5): 151 | parseBits(7) 152 | for j in range(4): 153 | parseBits(1) 154 | parseBits(2) 155 | for j in range(12): 156 | parseBits(5) 157 | parseBits(7) 158 | #LFO's 159 | for j in range(2): 160 | parseBits(3) 161 | parseBits(1) 162 | parseBits(7) 163 | parseBits(3) 164 | parseBits(7) 165 | parseBits(2) 166 | parseBits(7) 167 | parseBits(2) 168 | #Pitch 169 | parseBits(7) 170 | parseBits(7) 171 | parseBits(5) 172 | parseBits(4) 173 | parseBits(5) 174 | parseBits(7) 175 | parseBits(4) 176 | parseBits(4) 177 | parseBits(4) 178 | for j in range(10): 179 | parseBits(7) 180 | #Filter 181 | parseBits(3) 182 | parseBits(7) 183 | parseBits(4) 184 | parseBits(7) 185 | parseBits(7) 186 | parseBits(7) 187 | parseBits(3) 188 | parseBits(7) 189 | parseBits(4) 190 | parseBits(4) 191 | parseBits(4) 192 | for j in range(10): 193 | parseBits(7) 194 | #Amp 195 | parseBits(7) 196 | parseBits(2) 197 | parseBits(7) 198 | parseBits(4) 199 | parseBits(3) 200 | parseBits(7) 201 | parseBits(4) 202 | parseBits(4) 203 | parseBits(4) 204 | for j in range(10): 205 | parseBits(7) 206 | parseBits(4) 207 | parseBits(6) 208 | parseBits(7) 209 | parseBits(7) 210 | parseBits(7) 211 | #Output 212 | parseBits(2) 213 | parseBits(7) 214 | parseBits(7) 215 | parseBits(7) 216 | for b in range(8): 217 | bitResult.append(0) 218 | 219 | offset = 0 220 | for i in range(401): 221 | theSum = bitResult[offset] 222 | theSum += bitResult[offset + 1] << 1 223 | theSum += bitResult[offset + 2] << 2 224 | theSum += bitResult[offset + 3] << 3 225 | theSum += bitResult[offset + 4] << 4 226 | theSum += bitResult[offset + 5] << 5 227 | theSum += bitResult[offset + 6] << 6 228 | theSum += bitResult[offset + 7] << 7 229 | offset += 8 230 | out_file.write(theSum.to_bytes(1,"big")) 231 | in_file.seek(scan + 590) 232 | if isSysex == True: 233 | in_file.seek(scan + 645) 234 | in_file.close() 235 | out_file.close() 236 | 237 | -------------------------------------------------------------------------------- /Import80.py: -------------------------------------------------------------------------------- 1 | import os 2 | import math 3 | 4 | offset = 0 5 | bits = [] 6 | bitResult = [] 7 | isSysex = False 8 | 9 | def parseBits(bitNum): 10 | global offset 11 | global bits 12 | global bitResult 13 | for k in range(8): 14 | if k < bitNum: 15 | bitResult.append(bits[offset]) 16 | offset += 1 17 | 18 | def run(in_string): 19 | global offset 20 | global bits 21 | global bitResult 22 | isSysex = False 23 | in_file = open(in_string + ".syx", "rb") 24 | out_file = open(in_string + ".patches", "wb") 25 | if in_file.read(1) == b'\xf0': 26 | isSysex = True 27 | in_file.seek(0,2) 28 | patchCount = int((in_file.tell()) / 549) 29 | in_file.seek(0) 30 | offset = 0 31 | 32 | for i in range(patchCount): 33 | scan = 549 * i 34 | result = out_file.tell() 35 | bits = [] 36 | bitCount = 0 37 | in_file.seek(scan + 9) 38 | for j in range(34): 39 | byte = int.from_bytes(in_file.read(1), "big") 40 | if bitCount == 26: 41 | byte = (byte - 64) % 256 42 | bits.append(byte & 1) 43 | bits.append((byte & 2) >> 1) 44 | bits.append((byte & 4) >> 2) 45 | bits.append((byte & 8) >> 3) 46 | bits.append((byte & 16) >> 4) 47 | bits.append((byte & 32) >> 5) 48 | bits.append((byte & 64) >> 6) 49 | bits.append((byte & 128) >> 7) 50 | bitCount += 1 51 | for k in range(4): 52 | in_file.seek(11,1) 53 | for j in range(115): 54 | byte = int.from_bytes(in_file.read(1), "big") 55 | if bitCount == 34 + (k * 115) and byte > 1: 56 | byte = 1 57 | #if bitCount == 42 + (k * 115): 58 | #byte = byte ^ 1 59 | #if bitCount == 43 + (k * 115): 60 | #byte = byte ^ 1 61 | if bitCount == 45 + (k * 115): 62 | byte = (byte - 64) % 256 63 | if bitCount == 47 + (k * 115): 64 | byte = (byte - 64) % 256 65 | if bitCount == 49 + (k * 115): 66 | byte = (byte - 64) % 256 67 | if bitCount == 51 + (k * 115): 68 | byte = (byte - 64) % 256 69 | if bitCount == 53 + (k * 115): 70 | byte = (byte - 64) % 256 71 | if bitCount == 55 + (k * 115): 72 | byte = (byte - 64) % 256 73 | if bitCount == 57 + (k * 115): 74 | byte = (byte - 64) % 256 75 | if bitCount == 59 + (k * 115): 76 | byte = (byte - 64) % 256 77 | if bitCount == 61 + (k * 115): 78 | byte = (byte - 64) % 256 79 | if bitCount == 63 + (k * 115): 80 | byte = (byte - 64) % 256 81 | if bitCount == 65 + (k * 115): 82 | byte = (byte - 64) % 256 83 | if bitCount == 67 + (k * 115): 84 | byte = (byte - 64) % 256 85 | if bitCount == 76 + (k * 115): 86 | byte = (byte - 64) % 256 87 | if bitCount == 77 + (k * 115): 88 | byte = (byte - 64) % 256 89 | if bitCount == 78 + (k * 115): 90 | byte = (byte - 64) % 256 91 | if bitCount == 87 + (k * 115): 92 | byte = (byte - 64) % 256 93 | if bitCount == 88 + (k * 115): 94 | byte = (byte - 64) % 256 95 | if bitCount == 89 + (k * 115): 96 | byte = (byte - 64) % 256 97 | if bitCount == 90 + (k * 115): 98 | byte = (byte - 64) % 256 99 | if bitCount == 91 + (k * 115): 100 | byte = (byte - 64) % 256 101 | if bitCount == 94 + (k * 115): 102 | byte = (byte - 64) % 256 103 | if bitCount == 98 + (k * 115): 104 | byte = (byte - 64) % 256 105 | if bitCount == 100 + (k * 115): 106 | byte = (byte - 64) % 256 107 | if bitCount == 102 + (k * 115): 108 | byte = (byte - 64) % 256 109 | if bitCount == 104 + (k * 115): 110 | byte = (byte - 64) % 256 111 | if bitCount == 106 + (k * 115): 112 | byte = (byte - 64) % 256 113 | if bitCount == 113 + (k * 115): 114 | byte = (byte - 64) % 256 115 | if bitCount == 117 + (k * 115): 116 | byte = (byte - 64) % 256 117 | if bitCount == 135 + (k * 115): 118 | byte = (byte - 64) % 256 119 | bits.append(byte & 1) 120 | bits.append((byte & 2) >> 1) 121 | bits.append((byte & 4) >> 2) 122 | bits.append((byte & 8) >> 3) 123 | bits.append((byte & 16) >> 4) 124 | bits.append((byte & 32) >> 5) 125 | bits.append((byte & 64) >> 6) 126 | bits.append((byte & 128) >> 7) 127 | bitCount += 1 128 | 129 | for j in range(12): 130 | parseBits(8) 131 | #Reverb 132 | offset = 104 133 | parseBits(3) 134 | offset = 136 135 | parseBits(2) 136 | for j in range(2): 137 | bitResult.append(0) 138 | offset = 96 139 | parseBits(1) 140 | offset = 112 141 | parseBits(8) 142 | parseBits(8) 143 | parseBits(8) 144 | offset = 136 145 | #Chorus 146 | offset = 144 147 | parseBits(8) 148 | parseBits(8) 149 | offset = 160 150 | parseBits(7) 151 | offset = 176 152 | parseBits(1) 153 | offset = 168 154 | parseBits(8) 155 | offset = 184 156 | #Misc 157 | parseBits(8) 158 | parseBits(8) 159 | parseBits(8) 160 | parseBits(8) 161 | parseBits(4) 162 | offset = 248 163 | parseBits(1) 164 | offset = 240 165 | parseBits(1) 166 | offset = 232 167 | parseBits(1) 168 | offset = 224 169 | parseBits(1) 170 | offset = 264 171 | parseBits(7) 172 | offset = 256 173 | parseBits(1) 174 | 175 | offset = 272 176 | for tone in range(4): 177 | scanT = offset 178 | resultT = out_file.tell() 179 | 180 | offset = scanT 181 | parseBits(2) 182 | offset = scanT + 40 183 | parseBits(4) 184 | offset = scanT + 32 185 | parseBits(1) 186 | offset = scanT + 24 187 | parseBits(1) 188 | offset = scanT + 16 189 | parseBits(4) 190 | offset = scanT + 8 191 | parseBits(4) 192 | for j in range(8): 193 | bitResult.append(0) 194 | offset = scanT + 48 195 | parseBits(8) 196 | #offset = scanT + 64 197 | #parseBits(1) 198 | offset = scanT + 56 199 | parseBits(8) 200 | #offset = scanT + 72 201 | #parseBits(1) 202 | 203 | offset = scanT + 80 204 | #Mods A 205 | ModStart = offset 206 | offset = ModStart 207 | parseBits(4) 208 | offset = ModStart + 16 209 | parseBits(4) 210 | offset = ModStart + 32 211 | parseBits(4) 212 | offset = ModStart + 48 213 | parseBits(4) 214 | offset = ModStart + 8 215 | parseBits(8) 216 | offset = ModStart + 24 217 | parseBits(8) 218 | offset = ModStart + 40 219 | parseBits(8) 220 | offset = ModStart + 56 221 | parseBits(8) 222 | #Mods B 223 | ModStart = offset 224 | offset = ModStart 225 | parseBits(4) 226 | offset = ModStart + 16 227 | parseBits(4) 228 | offset = ModStart + 32 229 | parseBits(4) 230 | offset = ModStart + 48 231 | parseBits(4) 232 | offset = ModStart + 8 233 | parseBits(8) 234 | offset = ModStart + 24 235 | parseBits(8) 236 | offset = ModStart + 40 237 | parseBits(8) 238 | offset = ModStart + 56 239 | parseBits(8) 240 | #Mods C 241 | ModStart = offset 242 | offset = ModStart 243 | parseBits(4) 244 | offset = ModStart + 16 245 | parseBits(4) 246 | offset = ModStart + 32 247 | parseBits(4) 248 | offset = ModStart + 48 249 | parseBits(4) 250 | offset = ModStart + 8 251 | parseBits(8) 252 | offset = ModStart + 24 253 | parseBits(8) 254 | offset = ModStart + 40 255 | parseBits(8) 256 | offset = ModStart + 56 257 | parseBits(8) 258 | #LFO1 259 | LFOStart = offset 260 | offset = LFOStart 261 | parseBits(3) 262 | parseBits(3) 263 | parseBits(1) 264 | bitResult.append(0) 265 | parseBits(7) 266 | bitResult.append(0) 267 | offset = LFOStart + 40 268 | parseBits(4) 269 | offset = LFOStart + 32 270 | parseBits(4) 271 | offset = LFOStart + 56 272 | parseBits(7) 273 | offset = LFOStart + 48 274 | parseBits(1) 275 | offset = LFOStart + 88 276 | #LFO2 277 | parseBits(3) 278 | parseBits(3) 279 | parseBits(1) 280 | bitResult.append(0) 281 | parseBits(7) 282 | bitResult.append(0) 283 | offset = LFOStart + 128 284 | parseBits(4) 285 | offset = LFOStart + 120 286 | parseBits(4) 287 | offset = LFOStart + 144 288 | parseBits(7) 289 | offset = LFOStart + 136 290 | parseBits(1) 291 | #LFOMix 292 | offset = LFOStart + 64 293 | parseBits(8) 294 | parseBits(8) 295 | parseBits(8) 296 | offset = LFOStart + 152 297 | parseBits(8) 298 | parseBits(8) 299 | parseBits(8) 300 | offset = LFOStart + 176 301 | #Pitch 302 | PitchStart = offset 303 | parseBits(8) 304 | parseBits(8) 305 | parseBits(4) 306 | offset = PitchStart + 320 307 | parseBits(4) 308 | 309 | offset = PitchStart + 24 310 | parseBits(4) 311 | offset = PitchStart + 56 312 | parseBits(4) 313 | offset = PitchStart + 32 314 | parseBits(8) 315 | parseBits(4) 316 | parseBits(4) 317 | offset = PitchStart + 64 318 | parseBits(8) 319 | parseBits(8) 320 | parseBits(8) 321 | parseBits(8) 322 | parseBits(8) 323 | parseBits(8) 324 | parseBits(8) 325 | parseBits(8) 326 | parseBits(8) 327 | offset = PitchStart + 136 328 | #Filter 329 | FilStart = offset 330 | offset = FilStart + 8 331 | parseBits(8) 332 | parseBits(7) 333 | parseBits(1) 334 | parseBits(4) 335 | offset = FilStart + 72 336 | parseBits(4) 337 | offset = FilStart + 40 338 | parseBits(3) 339 | offset = FilStart 340 | parseBits(2) 341 | for j in range(3): 342 | bitResult.append(0) 343 | offset = FilStart + 48 344 | parseBits(8) 345 | parseBits(4) 346 | parseBits(4) 347 | offset = FilStart + 80 348 | parseBits(7) 349 | bitResult.append(0) 350 | 351 | parseBits(8) 352 | parseBits(8) 353 | parseBits(8) 354 | parseBits(8) 355 | parseBits(8) 356 | parseBits(8) 357 | parseBits(8) 358 | parseBits(8) 359 | offset = FilStart + 152 360 | 361 | #Level 362 | LevStart = offset 363 | parseBits(8) 364 | offset = LevStart + 24 365 | parseBits(4) 366 | offset = LevStart + 16 367 | parseBits(4) 368 | offset = LevStart + 48 369 | parseBits(4) 370 | parseBits(4) 371 | offset = LevStart + 8 372 | parseBits(4) 373 | offset = LevStart + 96 374 | parseBits(4) 375 | offset = LevStart + 64 376 | parseBits(3) 377 | offset = LevStart + 40 378 | parseBits(2) 379 | for j in range(1): 380 | bitResult.append(0) 381 | offset = scanT + 64 382 | parseBits(1) 383 | offset = scanT + 72 384 | parseBits(1) 385 | offset = LevStart + 72 386 | parseBits(8) 387 | parseBits(4) 388 | parseBits(4) 389 | offset = LevStart + 104 390 | parseBits(8) 391 | parseBits(8) 392 | parseBits(8) 393 | parseBits(8) 394 | parseBits(8) 395 | parseBits(8) 396 | parseBits(8) 397 | 398 | #Sends 399 | parseBits(8) 400 | parseBits(8) 401 | parseBits(8) 402 | 403 | resultOff = 362 * 8 * i 404 | for j in range(362): 405 | theSum = bitResult[resultOff] 406 | theSum += bitResult[resultOff + 1] << 1 407 | theSum += bitResult[resultOff + 2] << 2 408 | theSum += bitResult[resultOff + 3] << 3 409 | theSum += bitResult[resultOff + 4] << 4 410 | theSum += bitResult[resultOff + 5] << 5 411 | theSum += bitResult[resultOff + 6] << 6 412 | theSum += bitResult[resultOff + 7] << 7 413 | resultOff += 8 414 | out_file.write(theSum.to_bytes(1,"big")) 415 | offset = 0 416 | in_file.seek(scan + 549) 417 | in_file.close() 418 | out_file.close() 419 | -------------------------------------------------------------------------------- /Import990.py: -------------------------------------------------------------------------------- 1 | import os 2 | import math 3 | 4 | offset = 0 5 | bits = [] 6 | bitResult = [] 7 | chkSum = 0 8 | isSysex = False 9 | 10 | def parseBits(bitNum): 11 | global offset 12 | global bits 13 | global bitResult 14 | for k in range(8): 15 | if k < bitNum: 16 | bitResult.append(bits[offset]) 17 | offset += 1 18 | 19 | def run(in_string): 20 | global offset 21 | global bits 22 | global bitResult 23 | isSysex = False 24 | in_file = open(in_string + ".syx", "rb") 25 | out_file = open(in_string + ".patches", "wb") 26 | if in_file.read(1) == b'\xf0': 27 | isSysex = True 28 | in_file.seek(11) 29 | startOffset = 0 30 | if isSysex == True: 31 | in_file.seek(9) 32 | firstMessage = int.from_bytes(in_file.read(1),"big") 33 | if (firstMessage < 32): 34 | startOffset = 12 35 | 36 | SQCheck = False 37 | in_file.seek(324 + startOffset) 38 | if in_file.read(1) == b'\xf0': 39 | SQCheck = True 40 | 41 | in_file.seek(0,2) 42 | patchCount = int((in_file.tell() - startOffset) / 519) 43 | 44 | in_file.seek(startOffset) 45 | 46 | offset = 0 47 | 48 | for i in range(patchCount): 49 | scan = in_file.tell() 50 | result = out_file.tell() 51 | bits = [] 52 | bitCount = 0 53 | in_file.seek(scan + 9) 54 | for j in range(118): 55 | byte = int.from_bytes(in_file.read(1), "big") 56 | if bitCount == 117 and byte & 3 == 0: 57 | byte += 3 58 | elif bitCount == 117: 59 | byte -= 1 60 | bits.append(byte & 1) 61 | bits.append((byte & 2) >> 1) 62 | bits.append((byte & 4) >> 2) 63 | bits.append((byte & 8) >> 3) 64 | bits.append((byte & 16) >> 4) 65 | bits.append((byte & 32) >> 5) 66 | bits.append((byte & 64) >> 6) 67 | bits.append((byte & 128) >> 7) 68 | bitCount += 1 69 | in_file.seek(11,1) 70 | bitCount = 0 71 | for k in range(4): 72 | for j in range(92): 73 | if k == 2 and bitCount == 184 and SQCheck == True: 74 | in_file.seek(11,1) 75 | byte = int.from_bytes(in_file.read(1), "big") 76 | if bitCount == (k * 92) and byte > 1: 77 | byte = 1 78 | bits.append(byte & 1) 79 | bits.append((byte & 2) >> 1) 80 | bits.append((byte & 4) >> 2) 81 | bits.append((byte & 8) >> 3) 82 | bits.append((byte & 16) >> 4) 83 | bits.append((byte & 32) >> 5) 84 | bits.append((byte & 64) >> 6) 85 | bits.append((byte & 128) >> 7) 86 | bitCount += 1 87 | if k == 2 and bitCount == 256 and SQCheck == False: 88 | in_file.seek(11,1) 89 | 90 | offset = 25 * 8 91 | parseBits(4) 92 | offset = 24 * 8 93 | parseBits(4) 94 | offset = 0 95 | for j in range(16): 96 | parseBits(8) 97 | parseBits(7) 98 | offset = 27 * 8 99 | parseBits(1) 100 | offset = 17 * 8 101 | parseBits(7) 102 | offset = 28 * 8 103 | parseBits(1) 104 | offset = 18 * 8 105 | parseBits(8) 106 | offset = 20 * 8 107 | parseBits(6) 108 | offset = 30 * 8 109 | parseBits(1) 110 | parseBits(1) 111 | offset = 21 * 8 112 | parseBits(4) 113 | offset = 32 * 8 114 | parseBits(3) 115 | offset = 19 * 8 116 | parseBits(1) 117 | offset = 22 * 8 118 | parseBits(3) 119 | offset = 23 * 8 120 | parseBits(3) 121 | offset = 117 * 8 122 | parseBits(2) 123 | 124 | offset = 29 * 8 125 | parseBits(7) 126 | offset = 26 * 8 127 | parseBits(1) 128 | offset = 40 * 8 129 | parseBits(3) 130 | offset = 34 * 8 131 | parseBits(5) 132 | offset = 41 * 8 133 | parseBits(3) 134 | offset = 35 * 8 135 | parseBits(5) 136 | offset = 42 * 8 137 | for j in range(8): 138 | parseBits(8) 139 | parseBits(2) 140 | parseBits(2) 141 | parseBits(2) 142 | parseBits(2) 143 | parseBits(8) 144 | parseBits(8) 145 | parseBits(8) 146 | parseBits(8) 147 | parseBits(8) 148 | parseBits(8) 149 | parseBits(8) 150 | parseBits(8) 151 | offset = 37 * 8 152 | parseBits(5) 153 | offset = 36 * 8 154 | parseBits(3) 155 | offset = 39 * 8 156 | parseBits(5) 157 | offset = 33 * 8 158 | parseBits(1) 159 | offset = 38 * 8 160 | parseBits(2) 161 | 162 | #Effects 163 | offset = 62 * 8 164 | parseBits(8) 165 | parseBits(3) 166 | offset = 66 * 8 167 | parseBits(3) 168 | offset = 100 * 8 169 | parseBits(2) 170 | offset = 64 * 8 171 | parseBits(4) 172 | offset = 67 * 8 173 | parseBits(4) 174 | offset = 65 * 8 175 | parseBits(8) 176 | offset = 68 * 8 177 | parseBits(8) 178 | 179 | parseBits(5) 180 | offset = 91 * 8 181 | parseBits(3) 182 | offset = 70 * 8 183 | parseBits(1) 184 | parseBits(1) 185 | parseBits(1) 186 | parseBits(1) 187 | offset = 92 * 8 188 | parseBits(1) 189 | parseBits(1) 190 | parseBits(2) 191 | offset = 74 * 8 192 | for j in range(17): 193 | parseBits(8) 194 | offset = 95 * 8 195 | for j in range(5): 196 | parseBits(8) 197 | offset = 102 * 8 198 | parseBits(7) 199 | offset = 101 * 8 200 | parseBits(1) 201 | offset = 103 * 8 202 | parseBits(8) 203 | offset = 105 * 8 204 | parseBits(7) 205 | offset = 104 * 8 206 | parseBits(1) 207 | offset = 106 * 8 208 | parseBits(8) 209 | offset = 108 * 8 210 | parseBits(7) 211 | offset = 107 * 8 212 | parseBits(1) 213 | offset = 109 * 8 214 | parseBits(8) 215 | offset = 110 * 8 216 | parseBits(8) 217 | offset = 111 * 8 218 | for j in range(6): 219 | parseBits(8) 220 | 221 | offset = 944 222 | for tone in range(4): 223 | scanT = offset 224 | resultT = out_file.tell() 225 | 226 | #Pitch 227 | for k in range(2): 228 | bitResult.append(0) 229 | offset = scanT 230 | parseBits(1) 231 | offset = scanT + 12 * 8 232 | parseBits(5) 233 | offset = scanT + 2 * 8 234 | parseBits(7) 235 | offset = scanT + 1 * 8 236 | parseBits(1) 237 | offset = scanT + 4 * 8 238 | parseBits(7) 239 | offset = scanT + 5 * 8 240 | parseBits(1) 241 | for k in range(2): 242 | bitResult.append(0) 243 | offset = scanT + 11 * 8 244 | parseBits(5) 245 | offset = scanT + 13 * 8 246 | parseBits(1) 247 | offset = scanT + 7 * 8 248 | parseBits(8) 249 | parseBits(8) 250 | parseBits(8) 251 | parseBits(8) 252 | offset = scanT + 64 * 8 253 | parseBits(8) 254 | offset = scanT + 73 * 8 255 | parseBits(8) 256 | offset = scanT + 17 * 8 257 | for k in range(7): 258 | parseBits(8) 259 | offset = scanT + 14 * 8 260 | parseBits(8) 261 | parseBits(8) 262 | parseBits(5) 263 | offset = scanT + 3 * 8 264 | parseBits(3) 265 | 266 | #TVF 267 | offset = scanT + 24 * 8 268 | parseBits(2) 269 | offset = scanT + 27 * 8 270 | parseBits(6) 271 | offset = scanT + 25 * 8 272 | parseBits(8) 273 | parseBits(8) 274 | offset = scanT + 28 * 8 275 | parseBits(8) 276 | offset = scanT + 65 * 8 277 | parseBits(8) 278 | offset = scanT + 74 * 8 279 | parseBits(8) 280 | offset = scanT + 32 * 8 281 | for k in range(8): 282 | parseBits(8) 283 | offset = scanT + 29 * 8 284 | parseBits(8) 285 | parseBits(8) 286 | parseBits(5) 287 | offset = scanT + 58 * 8 288 | parseBits(3) 289 | 290 | #TVA 291 | offset = scanT + 40 * 8 292 | parseBits(8) 293 | parseBits(2) 294 | offset = scanT + 43 * 8 295 | parseBits(6) 296 | offset = scanT + 42 * 8 297 | parseBits(8) 298 | offset = scanT + 44 * 8 299 | parseBits(8) 300 | parseBits(4) 301 | offset = scanT + 62 * 8 302 | parseBits(2) 303 | offset = scanT + 71 * 8 304 | parseBits(2) 305 | offset = scanT + 66 * 8 306 | parseBits(8) 307 | offset = scanT + 75 * 8 308 | parseBits(8) 309 | offset = scanT + 49 * 8 310 | for k in range(7): 311 | parseBits(8) 312 | offset = scanT + 46 * 8 313 | parseBits(8) 314 | parseBits(8) 315 | parseBits(5) 316 | offset = scanT + 67 * 8 317 | parseBits(3) 318 | 319 | #LFO's 320 | offset = scanT + 59 * 8 321 | parseBits(7) 322 | offset = scanT + 63 * 8 323 | parseBits(1) 324 | offset = scanT + 60 * 8 325 | parseBits(7) 326 | offset = scanT + 57 * 8 327 | parseBits(1) 328 | offset = scanT + 61 * 8 329 | parseBits(8) 330 | 331 | offset = scanT + 68 * 8 332 | parseBits(7) 333 | offset = scanT + 72 * 8 334 | parseBits(1) 335 | offset = scanT + 69 * 8 336 | parseBits(7) 337 | offset = scanT + 66 * 8 338 | parseBits(1) 339 | offset = scanT + 70 * 8 340 | parseBits(8) 341 | 342 | #Control 343 | 344 | offset = scanT + 56 * 8 345 | parseBits(4) 346 | offset = scanT + 6 * 8 347 | parseBits(4) 348 | 349 | #Mods 350 | offset = scanT + 76 * 8 351 | parseBits(4) 352 | offset = scanT + 78 * 8 353 | parseBits(4) 354 | offset = scanT + 80 * 8 355 | parseBits(4) 356 | offset = scanT + 82 * 8 357 | parseBits(4) 358 | offset = scanT + 84 * 8 359 | parseBits(4) 360 | offset = scanT + 86 * 8 361 | parseBits(4) 362 | offset = scanT + 88 * 8 363 | parseBits(4) 364 | offset = scanT + 90 * 8 365 | parseBits(4) 366 | offset = scanT + 77 * 8 367 | parseBits(8) 368 | offset = scanT + 79 * 8 369 | parseBits(8) 370 | offset = scanT + 81 * 8 371 | parseBits(8) 372 | offset = scanT + 83 * 8 373 | parseBits(8) 374 | offset = scanT + 85 * 8 375 | parseBits(8) 376 | offset = scanT + 87 * 8 377 | parseBits(8) 378 | offset = scanT + 89 * 8 379 | parseBits(8) 380 | offset = scanT + 91 * 8 381 | parseBits(8) 382 | 383 | resultOff = 379 * 8 * i 384 | for j in range(379): 385 | theSum = bitResult[resultOff] 386 | theSum += bitResult[resultOff + 1] << 1 387 | theSum += bitResult[resultOff + 2] << 2 388 | theSum += bitResult[resultOff + 3] << 3 389 | theSum += bitResult[resultOff + 4] << 4 390 | theSum += bitResult[resultOff + 5] << 5 391 | theSum += bitResult[resultOff + 6] << 6 392 | theSum += bitResult[resultOff + 7] << 7 393 | resultOff += 8 394 | out_file.write(theSum.to_bytes(1,"big")) 395 | offset = 0 396 | in_file.seek(scan + 519) 397 | in_file.close() 398 | out_file.close() 399 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SRJV 2 | 3 | ## Info 4 | 5 | This toolkit should make it feasible to import custom samples into an SR-JV80 ROM image. To make full use of this, it's ideal you also have a way to burn the created images onto an SR-JV80 card. The recommendation is the ROMulator tool by Sector101: 6 | 7 | https://www.sector101.co.uk/sr-jv-romulator.html 8 | 9 | With enough further hacking, it is possible to load the imported multisamples as is into the RolandCloud VST's for testing. 10 | 11 | In addition, experimental patch support is also included. As it is now, the format of the ROM suggests it usually has two different patch tables per card: what's seemingly required is the patch data that's directly compatible for, namely, the JV-80, the other known compatible patches being for the JV-2080 and, famously for SR-JV80-04, the JD-990. Currently the way patch importing works assumes any of these three models, though the creator does not guarantee the required SysEx for the JV-80 will be identical in the ROM due to inability to verify with such a synth. 12 | 13 | UPDATE: 1/7/2023 Out of pressure for it, the creator also caved and included a wave extractor script that also puts in the effort of converting the tables into SFZ files. Use on official ROM's at your own risk: this is included solely in order to verify the data. 14 | 15 | ## Pre-requisites 16 | 17 | * Python 3 18 | 19 | ## Additional Notes About Sample Importing 20 | 21 | 1. Total filesize needs to conform to the size of the ROM image, meaning ideally your sample set should be 23 MB in 24-bit PCM audio or less. The remaining space is needed for the definition tables and headers. 22 | 23 | 2. Due to the ROM's being organized in 1 MB blocks, a single sample cannot be larger than exactly 992KB after compression. 24 | 25 | 3. All imported audio needs to be in mono with a bitrate of 24-bit, or 32-bit linear PCM. 26 | 27 | 4. If you wish to have a reverse playback variation of a multisample without needing to import duplicate samples, make sure to have "REV" in the name of the alternate sfz file. Currently the way the script works is to import both versions at once and pick one as needed to avoid too much complexity. 28 | 29 | 5. There can be no more than 255 multisamples in a ROM, and each multisample is limited to 16 samples. 30 | 31 | 6. There is an optional "Brighten.py" script which can be used to fix higher frequencies of wav files in advance if you decide it sounds too muddy when imported. Resulting files will be placed in a "Brighter" subdirectory and must replace the original files in their original locations when ready. 32 | 33 | ## Usage 34 | 35 | 1. Compile all of the samples you wish to use, accompanied by an SFZ file for the sake of the multisample entries. 36 | 37 | >1a. Each SFZ filename should preferably begin with "xxx-" where the x's are numbers, though anything else for the first four characters that organize them the way you wish for the ROM will do. The format also only allows up to twelve characters, so anything more than 16 characters (including the prefix) will be truncated! Additionally, the required opcodes for full use of these tools are "sample" and "hikey". 38 | 39 | >1b. All samples in the SFZ files should point to WAV samples located in the same directory. As of November 30th, 2023, the 'smpl' chunk is no longer required, but it's still recommended if you want to save space on the ROM by avoiding duplicate sample table entries. 40 | 41 | 2. If you're particularly technically savvy, an additional but optional step is to edit the headers of the included Template ROM. This will be necessary if you wish to import a recognizable card other than that ID. 42 | 43 | 3. If you wish to import patches as well, make sure there is a SysEx bank dump of JV-2080, JD-990, and/or JV-80 presets included. These dumps should be stored in the following path relative to the samples to import: "Patches/2080.syx" for JV-2080 patches, "Patches/80.syx" for JV-80 patches, and "Patches/990.syx" for JD990 patches. Note that if you wish to import more patches than the user bank size of the model allows (64 for JV-80 and JD-990, 128 for JV-2080), you'll need to merge multiple SysEx files into one (the assumed maximum is 256). 44 | 45 | 4. It should now hopefully be as simple as running "runme.py". 46 | 47 | >4a. One way is to run it without arguments via Python 3, in which case you will be prompted for input folder, output filename, the option to import patches, and an option for verbose output (particularly useful if some samples report DC offset). 48 | 49 | >4b. The other method is to run it in your command line tool with arguments: "runme.py -i (input folder) -o (output file) (-p) (-v) 50 | 51 | The resulting file for loading into a card via ROMulator should now be available for testing. If you're savvy enough to convert to SRX ROM's on your own as well, it's recommended you load an SRX conversion based on the additionally-created "Result.bin" into RolandCloud SRX-series VST's first in case of audio output issues, which is a very real possibility with DC offset in particular, knowing the nature of DPCM audio. If this is not an option, be sure to also check the output of the scripts, turning on verbose mode as needed in order to determine problematic samples. 52 | 53 | 54 | ## Footnotes 55 | 56 | Credit goes to https://github.com/hackyourlife for the SR-JV80 Scrambling C code, and for the Java classes making it possible to feasibly encode in the FCE-DPCM format. Technically, said code was since converted into Python for the sake of portability, but credit is still due for using them as a basis. 57 | 58 | Additional credit goes to https://archive.org/details/@jv80tinkerer for their jv80_wave_extractor script as a foundation for the new extractor script, even though some changes had to be made for a seamless process, particularly increasing the bit depth to 24-bit and avoiding duplicate samples to make reimporting easier. -------------------------------------------------------------------------------- /ROMImport.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import sys 3 | import os 4 | import shutil 5 | import math 6 | import re 7 | from datetime import datetime 8 | 9 | import DPCM 10 | import Import80 11 | import Import990 12 | import Import2080 13 | 14 | def run(tmpDir, PatchImport, VerboseMode): 15 | shutil.copyfile("Template.bin", "Result.bin") 16 | template = open("Result.bin", "rb+") 17 | templateCoef = open("Result.bin", "rb+") 18 | template.seek(48) 19 | today = datetime.now() 20 | template.write('{0:04d}'.format(today.year).encode('utf-8')) 21 | template.seek(53) 22 | template.write('{0:02d}'.format(today.month).encode('utf-8')) 23 | template.seek(56) 24 | template.write('{0:02d}'.format(today.day).encode('utf-8')) 25 | template.seek(64) 26 | romSR = 32000 27 | 28 | template.seek(32768) 29 | templateCoef.seek(1024) 30 | sampleTable = open("SampleTable.bin", "wb") 31 | 32 | foldersplit = "/" 33 | if platform.system() == "Windows": 34 | foldersplit = "\\" 35 | 36 | 37 | endCheck = [] 38 | dupPreCheck = [] 39 | 40 | sampleRate = [] 41 | bitRate = 0 42 | smplVol = [] 43 | smplDelay = [] 44 | smplStart = [] 45 | smplStartN = [] 46 | smplLoop = [] 47 | smplLoopType = [] 48 | smplEnd = [] 49 | rootKey = [] 50 | fineTune = [] 51 | loopTune = [] 52 | 53 | sampleCount = -1 54 | sampleIDs = [] 55 | multiCount = -1 56 | newBlock = 0 57 | sourceDir = tmpDir 58 | orDir = os.getcwd() 59 | os.chdir(sourceDir) 60 | counter = 0 61 | dupCheck = [] 62 | dataChunkList = [] 63 | sampleFound = [] 64 | sampleFinder = -1 65 | 66 | for newBlock in range(8): 67 | for filename in sorted(os.listdir(os.getcwd()), key=os.path.getsize, reverse=True): 68 | if filename.endswith(".wav"): 69 | if ("=" + filename) in dupPreCheck: 70 | continue 71 | fineTuneResult = 1024 72 | loopTuneResult = 1024 73 | 74 | dataChunkValid = False 75 | audioFile = open(filename, "rb") 76 | audioRead = audioFile.read() 77 | audioFile.seek(34) 78 | bitRate = int.from_bytes(audioFile.read(2), "little") / 8 79 | 80 | dataOff = audioRead.find(b'data') 81 | audioFile.seek(dataOff + 4) 82 | dataSz = int.from_bytes(audioFile.read(4), "little") 83 | 84 | finalSample = 0 85 | chnkOff = audioRead.find(b'smpl') 86 | if dataOff < chnkOff and chnkOff < dataOff + dataSz: 87 | chnkOff = audioRead.find(b'smpl', 0, dataOff) 88 | if chnkOff == -1: 89 | chnkOff = audioRead.find(b'smpl', dataOff + dataSz) 90 | if chnkOff >= 0 and chnkOff + 64 < len(audioRead): 91 | audioFile.seek(chnkOff + 56) 92 | finalSample = int.from_bytes(audioFile.read(4), "little") 93 | else: 94 | finalSample = (dataSz / bitRate) 95 | 96 | if template.tell() + finalSample + (finalSample % 32) >= 1048576 * (newBlock + 1): 97 | audioFile.close() 98 | continue 99 | 100 | dupPreCheck.append("=" + filename) 101 | 102 | smplLoopMax = 0 103 | smplEndMax = 0 104 | template.seek(math.ceil(template.tell() / 32) * 32) 105 | sampleFinder += 1 106 | sampleFound.append(False) 107 | 108 | if chnkOff >= 0: 109 | dataChunkValid = True 110 | sampleCount += 1 111 | sampleIDs.append("=" + filename) 112 | dataChunkList.append(dataChunkValid) 113 | audioFile.seek(24) 114 | sampleRate.append(int.from_bytes(audioFile.read(4), "little")) 115 | audioFile.seek(chnkOff + 20) 116 | rootKey.append(int.from_bytes(audioFile.read(4), "little")) 117 | fineTuneResult = 1024 + round(float(int.from_bytes(audioFile.read(4), "little")) * 1024 / 100) 118 | smplVol.append(127) 119 | if chnkOff + 64 < len(audioRead): 120 | audioFile.seek(chnkOff + 48) 121 | smplStart.append(template.tell()) 122 | smplDelay.append(0) 123 | smplStartN.append(0) 124 | smplLoopType.append(int.from_bytes(audioFile.read(4), "little")) 125 | smplLoop.append(int.from_bytes(audioFile.read(4), "little")) 126 | smplEnd.append(int.from_bytes(audioFile.read(4), "little")) 127 | loopTuneResult = 1024 + round(float(int.from_bytes(audioFile.read(4), "little")) * 1024 / 100) 128 | else: 129 | smplLoopType.append(0) 130 | buff = int(dataSz / bitRate) 131 | smplStart.append(template.tell()) 132 | smplDelay.append(0) 133 | smplStartN.append(0) 134 | smplLoop.append(buff - 2) 135 | smplEnd.append(buff - 1) 136 | smplLoopType.append(2) 137 | loopTuneResult = 1024 138 | fineTune.append(fineTuneResult) 139 | loopTune.append(loopTuneResult) 140 | 141 | if sampleRate[sampleCount] != romSR: 142 | pitchFix = 12 * math.log(sampleRate[sampleCount] / romSR, 2) 143 | pitchFixStep = math.floor(pitchFix) 144 | pitchFixDecim = pitchFix - pitchFixStep 145 | rootKey[sampleCount] -= pitchFixStep 146 | fineTune[sampleCount] += int(pitchFixDecim * 1024) 147 | if fineTune[sampleCount] < 0: 148 | while fineTune[sampleCount] < 0: 149 | rootKey[sampleCount] += 1 150 | fineTune[sampleCount] += 1024 151 | elif fineTune[sampleCount] >= 2048: 152 | while fineTune[sampleCount] >= 2048: 153 | rootKey[sampleCount] -= 1 154 | fineTune[sampleCount] -= 1024 155 | 156 | for multiname in sorted(os.listdir(os.getcwd())): 157 | if multiCount == 254 : continue 158 | if multiname.endswith(".sfz"): 159 | sfzFile = open(os.getcwd() + foldersplit + multiname, "r") 160 | sfzText = "" + (" \n" + sfzFile.read()).split("",1)[1] 161 | sfzFile.close() 162 | RegionList = sfzText.split("") 163 | if len(RegionList) > 0: 164 | for i in range(min(16, len(RegionList))): 165 | if "=" + filename in RegionList[i] and dataChunkValid == False: 166 | if sampleFound[sampleFinder] == True: 167 | continue 168 | buff = int(dataSz / bitRate) 169 | sampleFound[sampleFinder] = True 170 | 171 | audioFile.seek(24) 172 | sampleRatePrep = (int.from_bytes(audioFile.read(4), "little")) 173 | if "loop_mode=loop_sustain" in RegionList[i] or "loop_mode=loop_continuous" in RegionList[i]: 174 | if "loop_type=alternate" in RegionList[i]: 175 | smplLoopTypePrep = (1) 176 | else: 177 | reverseFind = re.findall('direction=reverse', RegionList[i]) 178 | if len(reverseFind) > 0: 179 | smplLoopTypePrep = (6) 180 | else: 181 | smplLoopTypePrep = (0) 182 | else: 183 | reverseFind = re.findall('direction=reverse', RegionList[i]) 184 | if len(reverseFind) > 0: 185 | smplLoopTypePrep = (6) 186 | else: 187 | smplLoopTypePrep = (2) 188 | rootKeyFind = re.findall('pitch_keycenter=(\\d+)', RegionList[i]) 189 | rootKeyPrep = 60 190 | if len(rootKeyFind) > 0: 191 | rootKeyPrep = (int(rootKeyFind[0])) 192 | 193 | smplDelayFind = re.findall('delay_samples=(\\d+)', RegionList[i]) 194 | smplDelayPrep = 0 195 | if len(smplDelayFind) > 0: 196 | smplDelayPrep = (int(smplDelayFind[0])) 197 | 198 | smplStartFind = re.findall('offset=(\\d+)', RegionList[i]) 199 | smplStartPrep = 0 200 | if len(smplStartFind) > 0: 201 | smplStartPrep = (int(smplStartFind[0])) 202 | 203 | smplLoopFind = re.findall('loop_start=(\\d+)', RegionList[i]) 204 | smplLoopPrep = (buff - 1) 205 | if len(smplLoopFind) > 0 and ("loop_mode=loop_sustain" in RegionList[i] or "loop_mode=loop_continuous" in RegionList[i]): 206 | smplLoopPrep = (int(smplLoopFind[0])) 207 | 208 | smplEndFind = re.findall('loop_end=(\\d+)', RegionList[i]) 209 | smplEndPrep = (buff) 210 | if len(smplEndFind) > 0 and ("loop_mode=loop_sustain" in RegionList[i] or "loop_mode=loop_continuous" in RegionList[i]): 211 | smplEndPrep = (int(smplEndFind[0])) 212 | 213 | smplVolFind = re.findall('amplitude=(\\d+.?\\d*)', RegionList[i]) 214 | smplVolPrep = 127 215 | if len(smplVolFind) > 0: 216 | smplVolPrep = (round(float(max(0,min(100,float(smplVolFind[0])))) * 1.27)) 217 | 218 | smplTuneFind = re.findall('\ntune=(-?\\d+.?\\d*)', RegionList[i]) 219 | if len(smplTuneFind) > 0: 220 | fineTuneResult = 1024 + round(float(smplTuneFind[0]) * 1024 / 100) 221 | 222 | loopTuneFind = re.findall('looptune=(-?\\d+.?\\d*)', RegionList[i]) 223 | if len(loopTuneFind) > 0: 224 | loopTuneResult = 1024 + round(float(loopTuneFind[0]) * 1024 / 100) 225 | 226 | 227 | if sampleRatePrep != romSR: 228 | pitchFix = 12 * math.log(sampleRatePrep / romSR, 2) 229 | pitchFixStep = math.floor(pitchFix) 230 | pitchFixDecim = pitchFix - pitchFixStep 231 | rootKeyPrep -= pitchFixStep 232 | fineTuneResult += int(pitchFixDecim * 1024) 233 | if fineTuneResult < 0: 234 | while fineTuneResult < 0: 235 | rootKeyPrep += 1 236 | fineTuneResult += 1024 237 | elif fineTuneResult >= 2048: 238 | while fineTuneResult >= 2048: 239 | rootKeyPrep -= 1 240 | fineTuneResult -= 1024 241 | 242 | duped = False 243 | 244 | compare1 = [template.tell(), smplStartPrep, smplLoopTypePrep, rootKeyPrep, smplLoopPrep, smplEndPrep, smplVolPrep, fineTuneResult, loopTuneResult] 245 | 246 | for k in range(sampleCount + 1): 247 | compare2 = [smplStart[k], smplStartN[k], smplLoopType[k], rootKey[k], smplLoop[k], smplEnd[k], smplVol[k], fineTune[k], loopTune[k]] 248 | if compare1 == compare2: 249 | duped = True 250 | 251 | if duped == True: 252 | continue 253 | 254 | sampleCount += 1 255 | dataChunkList.append(dataChunkValid) 256 | sampleIDs.append("=" + filename) 257 | 258 | sampleRate.append(sampleRatePrep) 259 | smplLoopType.append(smplLoopTypePrep) 260 | rootKey.append(rootKeyPrep) 261 | smplStart.append(template.tell()) 262 | smplStartN.append(smplStartPrep) 263 | smplDelay.append(smplDelayPrep) 264 | smplLoop.append(smplLoopPrep) 265 | smplEnd.append(smplEndPrep) 266 | smplVol.append(smplVolPrep) 267 | 268 | fineTune.append(fineTuneResult) 269 | loopTune.append(loopTuneResult) 270 | 271 | audioFile.close() 272 | if "=" + filename not in sampleIDs: 273 | continue 274 | print(filename) 275 | #if smplLoopType[sampleCount] == 1: 276 | #print("WARNING: ping-pong looping not fully supported!") 277 | if filename not in endCheck: 278 | DPCM.Encode(filename,smplLoopType[sampleCount],smplLoop[sampleCount],smplEnd[sampleCount],VerboseMode) 279 | 280 | endCheck.append(filename) 281 | 282 | coefIn = open(filename + "_exp.bin", "rb") 283 | deltaIn = open(filename + "_delt.bin", "rb") 284 | deltaIn.seek(0,2) 285 | fullSize = deltaIn.tell() 286 | deltaIn.seek(0) 287 | 288 | if fullSize >= 1015806: 289 | print("Error: at least one sample is compressed larger than 992KB!") 290 | return 291 | 292 | template.seek(math.ceil(template.tell() / 32) * 32) 293 | 294 | templateCoef.write(coefIn.read()) 295 | template.write(deltaIn.read()) 296 | coefIn.close() 297 | deltaIn.close() 298 | counter += 1 299 | template.seek(1048576 * (newBlock + 1) + 32768) 300 | templateCoef.seek(1048576 * (newBlock + 1) + 1024) 301 | os.chdir(orDir) 302 | 303 | template.seek(96) 304 | template.write(((sampleCount + 1)).to_bytes(2,"big")) 305 | for i in range(sampleCount + 1): 306 | for j in range(1): 307 | #if (smplVol[i] * 1000000 + smplStart[i] / 16 + smplLoopType[i] * 20000000 + rootKey[i] * 40000000) in dupCheck: 308 | #continue 309 | sampleTable.write((smplVol[i]).to_bytes(1,"big")) 310 | sampleTable.write((smplStart[i] + smplStartN[i] + smplDelay[i]).to_bytes(3, "big")) 311 | sampleTable.write((smplStart[i] + smplLoop[i]).to_bytes(3, "big")) 312 | sampleTable.write((smplStart[i] + smplEnd[i]).to_bytes(3, "big")) 313 | sampleTable.write(b'\x00\x00') 314 | if smplLoopType[i] == 6: 315 | sampleTable.write(b'\x06') 316 | elif (smplEnd[i] == 0 or (smplEnd[i] - smplLoop[i] < 4) or smplLoopType[i] == 2): 317 | sampleTable.write(b'\x02') 318 | elif smplLoopType[i] == 1: 319 | sampleTable.write(b'\x01') 320 | else: 321 | sampleTable.write(b'\x00') 322 | sampleTable.write(rootKey[i].to_bytes(1, "big")) 323 | sampleTable.write(fineTune[i].to_bytes(2, "big")) 324 | sampleTable.write(loopTune[i].to_bytes(2, "big")) 325 | 326 | sampleTable.close() 327 | sampleTable = open("SampleTable.bin", "rb+") 328 | sampleTable.seek(0,2) 329 | waveOffset = 8388608 - sampleTable.tell() 330 | sampleTable.seek(0) 331 | template.seek(128) 332 | template.write(waveOffset.to_bytes(4,"big")) 333 | template.seek(waveOffset) 334 | template.write(sampleTable.read()) 335 | sampleTable.close() 336 | templateCoef.close() 337 | 338 | multiTable = open("MultiTable.bin", "wb") 339 | 340 | for filename in sorted(os.listdir(sourceDir)): 341 | if multiCount == 254 : continue 342 | if filename.endswith(".sfz"): 343 | multiName = filename.replace(".sfz","")[4:] 344 | if len(multiName) > 12: 345 | multiName = multiName[:12] 346 | elif len(multiName) < 12: 347 | for i in range(12 - len(multiName)): 348 | multiName = multiName + " " 349 | print(multiName) 350 | 351 | multiCount += 1 352 | sfzFile = open(sourceDir + foldersplit + filename, "r") 353 | sfzText = " \n" + sfzFile.read() 354 | sfzFile.close() 355 | 356 | sampleNum = [65535,65535,65535,65535,65535,65535,65535,65535, 357 | 65535,65535,65535,65535,65535,65535,65535,65535] 358 | sampleHiInt = [127,127,127,127,127,127,127,127, 359 | 127,127,127,127,127,127,127,127] 360 | 361 | RegionList = sfzText.split("") 362 | if len(RegionList) > 1: 363 | for i in range(min(16, len(RegionList) - 1)): 364 | sampleIDList = re.findall("sample=.+\\.wav",RegionList[i + 1]) 365 | if len(sampleIDList) > 0: 366 | sampleIDList[0] = "=" + (sampleIDList[0].split("="))[1] 367 | for j in range(sampleCount + 1): 368 | if sampleIDList[0] == sampleIDs[j]: 369 | if dataChunkList[j] == False: 370 | volumeCheck = 127 371 | if len(re.findall("amplitude=(\\d+.?\\d*)",RegionList[i + 1])) > 0: 372 | volumeCheck = round(float(max(0,min(100,float(re.findall("amplitude=(\\d+.?\\d*)",RegionList[i + 1])[0])))) * 1.27) 373 | startCheck = 0 374 | if len(re.findall("offset=(\\d+)",RegionList[i + 1])) > 0: 375 | startCheck = int(re.findall("offset=(\\d+)",RegionList[i + 1])[0]) 376 | loopTypeCheck = 0 377 | if "loop_type=alternate" in RegionList[i + 1]: 378 | loopTypeCheck = 1 379 | elif "direction=reverse" in RegionList[i + 1]: 380 | loopTypeCheck = 6 381 | elif "loop_mode=loop_continuous" not in RegionList[i + 1] and "loop_mode=loop_sustain" not in RegionList[i + 1]: 382 | loopTypeCheck = 2 383 | if volumeCheck == smplVol[j]: 384 | if startCheck == smplStartN[j]: 385 | if loopTypeCheck == smplLoopType[j]: 386 | #print("Match!") 387 | sampleNum[i] = j 388 | else: 389 | sampleNum[i] = j 390 | 391 | 392 | sampleHi = re.findall("hikey=[0-9]+",RegionList[i + 1]) 393 | if len(sampleHi) > 0: 394 | sampleHiInt[i] = int(((sampleHi[0]).split("="))[1]) 395 | 396 | 397 | multiTable.write(multiName.encode("ascii")) 398 | for i in range(16): 399 | multiTable.write(sampleHiInt[i].to_bytes(1,"big")) 400 | for i in range(16): 401 | multiTable.write(sampleNum[i].to_bytes(2,"big")) 402 | multiOffset = waveOffset - multiTable.tell() 403 | multiTable.close() 404 | multiTable = open("MultiTable.bin", "rb") 405 | template.seek(98) 406 | template.write((multiCount + 1).to_bytes(2,"big")) 407 | template.seek(132) 408 | template.write(multiOffset.to_bytes(4,"big")) 409 | template.seek(multiOffset) 410 | template.write(multiTable.read()) 411 | 412 | multiTable.close() 413 | patch80Offset = multiOffset 414 | patch990Offset = multiOffset 415 | patch2080Offset = multiOffset 416 | if PatchImport == True and os.path.exists(sourceDir + foldersplit + "Patches" + foldersplit + "80.syx"): 417 | template.seek(140) 418 | Import80.run(sourceDir + foldersplit + "Patches" + foldersplit + "80") 419 | patch80Table = open(sourceDir + foldersplit + "Patches" + foldersplit + "80.patches", "rb") 420 | patch80Table.seek(0,2) 421 | patch80Offset -= patch80Table.tell() 422 | patch80Count = int(patch80Table.tell() / 362) 423 | patch80Table.seek(0) 424 | template.write(patch80Offset.to_bytes(4,"big")) 425 | template.write(patch80Offset.to_bytes(4,"big")) 426 | template.seek(188) 427 | template.write(patch80Offset.to_bytes(4,"big")) 428 | template.seek(102) 429 | template.write(patch80Count.to_bytes(2,"big")) 430 | template.seek(patch80Offset) 431 | template.write(patch80Table.read()) 432 | patch80Table.close() 433 | else: 434 | template.seek(140) 435 | template.write(patch80Offset.to_bytes(4,"big")) 436 | template.write(patch80Offset.to_bytes(4,"big")) 437 | template.seek(102) 438 | template.write(b'\x00\x00') 439 | patch990Offset = patch80Offset 440 | template.seek(128 + 1048576) 441 | template.write(patch80Offset.to_bytes(4,"big")) 442 | template.write(patch80Offset.to_bytes(4,"big")) 443 | template.seek(140 + 1048576) 444 | if PatchImport == True and os.path.exists(sourceDir + foldersplit + "Patches" + foldersplit + "990.syx"): 445 | Import990.run(sourceDir + foldersplit + "Patches" + foldersplit + "990") 446 | patch990Table = open(sourceDir + foldersplit + "Patches" + foldersplit + "990.patches", "rb") 447 | patch990Table.seek(0,2) 448 | patch990Offset -= patch990Table.tell() 449 | patch990Count = int(patch990Table.tell() / 379) 450 | patch990Table.seek(0) 451 | template.write(patch990Offset.to_bytes(4,"big")) 452 | template.write(patch990Offset.to_bytes(4,"big")) 453 | template.seek(102 + 1048576) 454 | template.write(patch990Count.to_bytes(2,"big")) 455 | template.seek(patch990Offset) 456 | template.write(patch990Table.read()) 457 | patch990Table.close() 458 | else: 459 | template.write(patch990Offset.to_bytes(4,"big")) 460 | template.write(patch990Offset.to_bytes(4,"big")) 461 | template.seek(102 + 1048576) 462 | template.write(b'\x00\x00') 463 | patch2080Offset = patch990Offset 464 | 465 | template.seek(128 + 1048576 * 2) 466 | template.write(patch990Offset.to_bytes(4,"big")) 467 | template.write(patch990Offset.to_bytes(4,"big")) 468 | template.seek(140 + 1048576 * 2) 469 | if PatchImport == True and os.path.exists(sourceDir + foldersplit + "Patches" + foldersplit + "2080.syx"): 470 | Import2080.run(sourceDir + foldersplit + "Patches" + foldersplit + "2080") 471 | patch2080Table = open(sourceDir + foldersplit + "Patches" + foldersplit + "2080.patches", "rb") 472 | patch2080Table.seek(0,2) 473 | patch2080Offset -= patch2080Table.tell() 474 | patch2080Count = int(patch2080Table.tell() / 401) 475 | patch2080Table.seek(0) 476 | template.write(patch2080Offset.to_bytes(4,"big")) 477 | template.write(patch2080Offset.to_bytes(4,"big")) 478 | template.seek(102 + 1048576 * 2) 479 | template.write(patch2080Count.to_bytes(2,"big")) 480 | template.seek(patch2080Offset) 481 | template.write(patch2080Table.read()) 482 | patch2080Table.close() 483 | else: 484 | template.write(patch2080Offset.to_bytes(4,"big")) 485 | template.write(patch2080Offset.to_bytes(4,"big")) 486 | template.seek(102 + 1048576 * 2) 487 | template.write(b'\x00\x00') 488 | 489 | 490 | template.close() 491 | 492 | #os.remove("SampleTable.bin") 493 | #os.remove("MultiTable.bin") 494 | 495 | -------------------------------------------------------------------------------- /ROMScramble.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def scramble_data8(word): 4 | return ((word & 1) << 2) + ((word & 2) >> 1) + ((word & 4) << 2) + ((word & 8) << 2) + ((word & 16) << 3) + ((word & 32) << 1) + ((word & 64) >> 3) + ((word & 128) >> 6) 5 | 6 | def scramble_addr8(addr): 7 | sumUp = ((addr & 1) << 2) + ((addr & 2) >> 1) + ((addr & 4) << 1) + ((addr & 8) << 1) 8 | sumUp += ((addr & 16) >> 3) + ((addr & 32) << 4) + ((addr & 64) << 7) + ((addr & 128) << 3) 9 | sumUp += ((addr & 256) << 10) + ((addr & 512) << 8) + ((addr & 1024) >> 4) + ((addr & 2048) << 4) 10 | sumUp += ((addr & 4096) >> 1) + ((addr & 8192) << 3) + ((addr & 16384) >> 6) + ((addr & 32768) >> 10) 11 | sumUp += ((addr & 65536) >> 4) + ((addr & 131072) >> 10) + ((addr & 262144) >> 4) + (addr & 4294443008) 12 | return sumUp 13 | 14 | def run(filename_in, filename_out): 15 | #if len(arguments) < 3: 16 | #print("Usage: scramble.py descrambled.bin scrambled.bin") 17 | #return 18 | #filename_in = arguments[1] 19 | #filename_out = arguments[2] 20 | 21 | try: 22 | f = open(filename_in, "rb") 23 | except: 24 | print("Error: cannot open input file!") 25 | return 26 | f.seek(0,2) 27 | fsize = f.tell() 28 | f.seek(0) 29 | buf = bytearray(f.read()) 30 | outbuf = bytearray(fsize) 31 | f.close() 32 | 33 | #figure out ROM type: scramble first 32 bytes 34 | for i in range(32): 35 | addr = scramble_addr8(i) 36 | tmp = scramble_data8(buf[i]) 37 | #print(tmp) 38 | outbuf[addr] = tmp 39 | 40 | if outbuf[0:12].decode('UTF-8') != 'Roland JV80 ': 41 | print("Error: not an SR-JV80 ROM!") 42 | return 43 | print("ROM ID: " + (buf[32:38].decode('UTF-8'))) 44 | print("Date: " + (buf[48:58].decode('UTF-8'))) 45 | for i in range(fsize): 46 | addr = scramble_addr8(i) 47 | tmp = scramble_data8(buf[i]) 48 | outbuf[addr] = tmp 49 | 50 | try: 51 | out = open(filename_out, "wb") 52 | except: 53 | print("Error: cannot open output file!") 54 | return 55 | 56 | for i in range(fsize): 57 | out.write(outbuf[i].to_bytes(1,"big")) 58 | out.close() 59 | -------------------------------------------------------------------------------- /SMPL Extract.py: -------------------------------------------------------------------------------- 1 | import os, platform 2 | 3 | foldersplit = "/" 4 | if platform.system() == "Windows": 5 | foldersplit = "\\" 6 | 7 | directory = input("Directory of files to fix: ") 8 | for wavName in sorted(os.listdir(directory)): 9 | if wavName.endswith(".wav"): 10 | audioFile = open(directory + foldersplit + wavName, "rb") 11 | audioRead = audioFile.read() 12 | dataOff = audioRead.find(b'data') 13 | audioFile.seek(dataOff + 4) 14 | dataSz = int.from_bytes(audioFile.read(4), "little") 15 | chnkOff = audioRead.find(b'smpl') 16 | if dataOff < chnkOff and chnkOff < dataOff + dataSz: 17 | chnkOff = audioRead.find(b'smpl', 0, dataOff) 18 | if chnkOff == -1: 19 | chnkOff = audioRead.find(b'smpl', dataOff + dataSz) 20 | if chnkOff >= 0 and chnkOff + 64 < len(audioRead): 21 | audioFile.seek(chnkOff + 20) 22 | rootKey = int.from_bytes(audioFile.read(4), "little") 23 | audioFile.seek(chnkOff + 52) 24 | sampleLoop = int.from_bytes(audioFile.read(4), "little") 25 | sampleEnd = int.from_bytes(audioFile.read(4), "little") 26 | 27 | for sfzName in sorted(os.listdir(directory)): 28 | if sfzName.endswith(".sfz"): 29 | sfzFile1 = open(directory + foldersplit + sfzName, "r") 30 | sfzFile2 = open(directory + foldersplit + "tmp", "w") 31 | for line in sfzFile1.readlines(): 32 | if line == "sample=" + wavName + "\n": 33 | line = "sample=" + wavName + "\npitch_keycenter=" + str(rootKey) + "\nloop_mode=loop_continuous\nloop_start=" + str(sampleLoop) + "\nloop_end=" + str(sampleEnd) + "\n" 34 | elif line == "sample=" + wavName: 35 | line = "sample=" + wavName + "\npitch_keycenter=" + str(rootKey) + "\nloop_mode=loop_continuous\nloop_start=" + str(sampleLoop) + "\nloop_end=" + str(sampleEnd) 36 | sfzFile2.write(line) 37 | sfzFile1.close() 38 | sfzFile2.close() 39 | os.remove(directory + foldersplit + sfzName) 40 | os.rename(directory + foldersplit + "tmp", directory + foldersplit + sfzName) 41 | print(wavName) 42 | -------------------------------------------------------------------------------- /Template.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PythonBlue/SRJV/90afaa471202270dce37f9b35d21ba9f2508adde/Template.bin -------------------------------------------------------------------------------- /runme.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import shutil 4 | import argparse 5 | 6 | import DPCM 7 | import ROMImport 8 | import ROMScramble 9 | 10 | os.chdir(os.path.dirname(os.path.abspath(__file__))) 11 | 12 | Folder = "" 13 | FinalFile = "" 14 | VerboseMode = False 15 | PatchImport = False 16 | if len(sys.argv) > 1: 17 | parser = argparse.ArgumentParser() 18 | parser.add_argument('-i', '--input', type=str, default='input', help='Input folder') 19 | parser.add_argument('-o', '--output', type=str, default='Final', help='Output filename') 20 | parser.add_argument('-p', '--patches', action='store_true', help='Import patches') 21 | parser.add_argument('-v', '--verbose', action='store_true', help='Verbose mode') 22 | args = parser.parse_args() 23 | Folder = args.input 24 | if args.output.split('.')[0] == "Result": 25 | FinalFile = "Final.bin" 26 | else: 27 | FinalFile = args.output.split('.')[0] + ".bin" 28 | PatchImport = args.patches 29 | VerboseMode = args.verbose 30 | else: 31 | Folder = input("Enter the name of the relative folder to import into a ROM image: ") 32 | FinalFile = input("Enter the name of the resulting filename: ") 33 | if FinalFile.split('.')[0] == "Result": 34 | FinalFile = "Final.bin" 35 | else: 36 | FinalFile = FinalFile.split('.')[0] + ".bin" 37 | PatchImportStr = input("Import Patches? (Y if yes) ") 38 | if PatchImportStr == "y" or PatchImportStr == "Y": 39 | PatchImport = True 40 | VerboseModeStr = input("Verbose Mode? (Y if yes) ") 41 | if VerboseModeStr == "y" or VerboseModeStr == "Y": 42 | VerboseMode = True 43 | 44 | 45 | pathDiv = "/" 46 | if sys.platform == "win32": 47 | pathDiv = "\\" 48 | 49 | tmpDir = "tmp" 50 | if os.path.exists(tmpDir): 51 | shutil.rmtree(tmpDir) 52 | shutil.copytree(Folder, tmpDir) 53 | for path, dirc, files in os.walk(tmpDir): 54 | for name in sorted(files): 55 | if name.endswith(".wav"): 56 | shutil.copy(Folder + pathDiv + name, tmpDir + pathDiv + name) 57 | 58 | ROMImport.run(tmpDir, PatchImport, VerboseMode) 59 | ROMScramble.run("Result.bin", FinalFile) 60 | 61 | #os.remove("sampleList.txt") 62 | os.remove("SampleTable.bin") 63 | os.remove("MultiTable.bin") 64 | shutil.rmtree(tmpDir) 65 | print("Done!") 66 | --------------------------------------------------------------------------------