diff options
author | Graham Northup <grissess@nexusg.org> | 2018-04-23 09:25:16 -0400 |
---|---|---|
committer | Graham Northup <grissess@nexusg.org> | 2018-04-23 09:25:16 -0400 |
commit | 6cba85974d3b86eb33beac096922d33f05d9434b (patch) | |
tree | dea6bfe55d31f45e1b7650a7d84103773b27d735 /packet.py | |
parent | f5b2fde3224de430f0342c1da4f98c028ba11c94 (diff) | |
parent | c8efa1318f4d924b86c410e576c246d1e23839fb (diff) |
Merge branch 'beta'
Diffstat (limited to 'packet.py')
-rw-r--r-- | packet.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -13,18 +13,23 @@ class Packet(object): def FromStr(cls, s): parts = struct.unpack('>9L', s) return cls(parts[0], *parts[1:]) + def as_float(self, i): + return struct.unpack('>f', struct.pack('>L', self.data[i]))[0] def __str__(self): - return struct.pack('>L'+('L'*len(self.data)), self.cmd, *self.data) + return struct.pack('>L'+(''.join('f' if isinstance(i, float) else 'L' for i in self.data)), self.cmd, *self.data) class CMD: KA = 0 # No important data PING = 1 # Data are echoed exactly QUIT = 2 # No important data - PLAY = 3 # seconds, microseconds, frequency (Hz), amplitude (0-255), port + PLAY = 3 # seconds, microseconds, frequency (Hz), amplitude (0.0 - 1.0), port CAPS = 4 # ports, client type (1), user ident (2-7) + PCM = 5 # 16 samples, encoded S16_LE def itos(i): - return struct.pack('>L', i) + return struct.pack('>L', i).rstrip('\0') def stoi(s): - return struct.unpack('>L', s)[0] + return struct.unpack('>L', s.ljust(4, '\0'))[0] + +OBLIGATE_POLYPHONE = 0xffffffff |