# HG changeset patch # User Emmanuel Gil Peyrot # Date 1340283661 -7200 # Node ID cddfd3cb479764cc2bac25af9bcc11d75ef2b191 # Parent c412df42aa15ca5ce161d45ec5d3868e7a5dcc6b Add music support for >PCB. diff --git a/pytouhou/formats/fmt.py b/pytouhou/formats/fmt.py new file mode 100644 --- /dev/null +++ b/pytouhou/formats/fmt.py @@ -0,0 +1,69 @@ +# -*- encoding: utf-8 -*- +## +## Copyright (C) 2012 Emmanuel Gil Peyrot +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published +## by the Free Software Foundation; version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## + + +from struct import unpack + + +class Track(object): + def __init__(self): + self.name = '' + + # loop info + self.intro = 0 + #self.unknown + self.start = 0 + self.duration = 0 + + # WAVE header + self.wFormatTag = 1 + self.wChannels = 2 + self.dwSamplesPerSec = 44100 + self.dwAvgBytesPerSec = 176400 + self.wBlockAlign = 4 + self.wBitsPerSample = 16 + + +class FMT(list): + @classmethod + def read(cls, file): + self = cls() + + file.seek(0) + while True: + track = Track() + track.name = unpack('<16s', file.read(16))[0] + if not ord(track.name[0]): + break + + # loop info + track.intro, unknown, track.start, track.duration = unpack('