Mercurial > touhou
comparison pytouhou/ui/music.py @ 325:cddfd3cb4797
Add music support for >PCB.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 21 Jun 2012 15:01:01 +0200 |
parents | c412df42aa15 |
children | 61caded6b4f5 |
comparison
equal
deleted
inserted
replaced
324:c412df42aa15 | 325:cddfd3cb4797 |
---|---|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 ## GNU General Public License for more details. | 12 ## GNU General Public License for more details. |
13 ## | 13 ## |
14 | 14 |
15 | 15 |
16 from pyglet.media import AudioData | 16 from pyglet.media import AudioData, AudioFormat |
17 from pyglet.media.riff import WaveSource | 17 from pyglet.media.riff import WaveSource |
18 | 18 |
19 | 19 |
20 class InfiniteWaveSource(WaveSource): | 20 class InfiniteWaveSource(WaveSource): |
21 def __init__(self, filename, start, end, file=None): | 21 def __init__(self, filename, start, end, file=None): |
49 | 49 |
50 timestamp = float(self._offset) / self.audio_format.bytes_per_second | 50 timestamp = float(self._offset) / self.audio_format.bytes_per_second |
51 duration = float(bytes) / self.audio_format.bytes_per_second | 51 duration = float(bytes) / self.audio_format.bytes_per_second |
52 | 52 |
53 return AudioData(data, bytes, timestamp, duration) | 53 return AudioData(data, bytes, timestamp, duration) |
54 | |
55 | |
56 def seek(self, timestamp): | |
57 raise NotImplementedError('irrelevant') | |
58 | |
59 | |
60 class ZwavSource(InfiniteWaveSource): | |
61 def __init__(self, filename, format, file=None): | |
62 if file is None: | |
63 file = open(filename, 'rb') | |
64 | |
65 self._file = file | |
66 | |
67 assert b'ZWAV' == self._file.read(4) | |
68 | |
69 self.audio_format = AudioFormat( | |
70 channels=format.wChannels, | |
71 sample_size=format.wBitsPerSample, | |
72 sample_rate=format.dwSamplesPerSec) | |
73 | |
74 self._start_offset = 0 | |
75 self._offset = format.intro | |
76 | |
77 self._file.seek(self._offset) | |
78 self._start = format.intro + format.start | |
79 self._end = format.intro + format.duration |