-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopl.py
28 lines (21 loc) · 859 Bytes
/
opl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import struct
import unittest
import wave
import oply.opl3
import oply.utils
class TestIMF(unittest.TestCase):
def _render(self, imf_path, wav_path, rate=700):
with open(imf_path, 'rb') as file:
imf = oply.utils.IMF(stream=file, rate=rate)
sequencer = oply.utils.Sequencer(imf.rate)
imf.to_sequence(sequencer)
opl3 = oply.opl3.Chip()
with wave.open(wav_path, 'wb') as wave_stream:
wave_stream.setnchannels(2)
wave_stream.setsampwidth(2)
wave_stream.setframerate(opl3.RATE)
wave_stream.setnframes(0)
for sample in opl3.render(sequencer):
wave_stream.writeframesraw(struct.pack('<hh', *sample))
def test_music(self):
self._render('05 - Welcome to a Kick In Yore Pants In Good Ole Hillville!.imf', 'penis.wav')