def write_stream(self, stream: BinaryIO): if isinstance(stream, BinaryWriter): wtr = stream else: wtr = BinaryWriter(stream) wtr.write_uint32(0) # placeholder for file length for p in self.params: if isinstance(p, int): wtr.write_uint16(1) wtr.write_uint32(p) elif isinstance(p, float): wtr.write_uint16(2) wtr.write_float(p) elif isinstance(p, str): wtr.write_uint16(3) wtr.write_uint16(len(p) + 1) wtr.write_string(p) for c in self.commands: wtr.write_uint16(0) wtr.write_uint16(c.command) for p in c.params: if isinstance(p, int): wtr.write_uint16(1) wtr.write_uint32(p) elif isinstance(p, float): wtr.write_uint16(2) wtr.write_float(p) elif isinstance(p, str): wtr.write_uint16(3) wtr.write_uint16(len(p) + 1) wtr.write_string(p) wtr.write_uint16(0xc) wtr.seek(0) wtr.write_uint32(len(wtr.data) - 4)
def write_stream(self, stream): if isinstance(stream, BinaryWriter): wtr = stream else: wtr = BinaryWriter(stream) self.song_chunk.num_tracks = len(self.tracks) self.song_chunk.write(wtr) for track in self.tracks: track: Track track.write(wtr) self.eoc_chunk.write(wtr) self.smdl_header.file_length = wtr.tell() self.smdl_header.write(wtr) wtr.seek(0, io.SEEK_END)
def write_stream(self, stream): if not isinstance(stream, BinaryWriter): wtr = BinaryWriter(stream) else: wtr = stream wtr.write(self.original_header) wtr.seek(0) wtr.write(self.chunk_id) wtr.seek(0x31) wtr.write_uint8(self.loop_flag) wtr.write_uint8(self.channels) coding = self.coding if self.sample_rate == 32728: coding |= 4 elif self.sample_rate == 16364: coding |= 2 else: raise NotImplementedError() wtr.seek(0x100) buffer = self.buffer.copy() buffer = buffer.reshape((buffer.shape[0], buffer.shape[1] // 0x10, 0x10)) buffer = buffer.swapaxes(0, 1) wtr.write(buffer.tobytes()) size = wtr.tell() wtr.seek(0x40) wtr.write_uint32(size)
def write(self, bw: BinaryWriter): bw.seek(0x40, io.SEEK_SET) bw.write(self.label) bw.write_uint32(self.unk1) bw.write_uint32(0xFF10) bw.write_uint32(0xFFFFFFB0) bw.write_uint16(0x1) bw.write_uint16(self.tpqn) bw.write_uint16(0xFF01) bw.write_uint8(self.num_tracks) bw.write_uint8(self.num_channels) bw.write_uint32(0x0F000000) bw.write_uint32(0xFFFFFFFF) bw.write_uint32(0x40000000) bw.write_uint32(0x00404000) bw.write_uint16(0x0200) bw.write_uint16(0x0800) bw.write_uint32(0xFFFFFF00) bw.write(b"\xFF" * 16)
def write(self, bw: BinaryWriter): bw.seek(0, io.SEEK_SET) bw.write(self.magic) bw.write_uint32(0) bw.write_uint32(self.file_length) bw.write_uint16(self.version) bw.write_uint8(self.unk1) bw.write_uint8(self.unk2) bw.write_uint32(0) bw.write_uint32(0) bw.write_uint16(self.year) bw.write_uint8(self.month) bw.write_uint8(self.day) bw.write_uint8(self.hour) bw.write_uint8(self.minute) bw.write_uint8(self.second) bw.write_uint8(self.centisecond) if self.file_name[-1] != 0: self.file_name += b"\0" bw.write_string(self.file_name, size=16, encoding=None, pad=b"\xFF") bw.write_uint32(0x1) bw.write_uint32(0x1) bw.write_uint32(0xFFFFFFFF) bw.write_uint32(0xFFFFFFFF)