fixed Python 2 compatibility

Python 2 returns the string representation with just calling
writeframes(data) instead of writeframes(data.tostring())

/tmp/post.wav
0000 0000: 52 49 46 46 C4 AA 00 00  57 41 56 45 66 6D 74 20  RIFF.... WAVEfmt
0000 0010: 10 00 00 00 01 00 01 00  80 BB 00 00 00 77 01 00  ........ .....w..
0000 0020: 02 00 10 00 64 61 74 61  A0 AA 00 00 61 72 72 61  ....data ....arra
0000 0030: 79 28 27 68 27 2C 20 5B  30 2C 20 38 30 36 35 2C  y('h', [ 0, 8065,
0000 0040: 20 31 35 36 33 35 2C 20  32 32 32 34 32 2C 20 32   15635,  22242, 2

This change adds an escape hatch that could work for both major Python
versions, except Python 3.0 and 3.1 but those should be rare and
unsupported anyway.
pull/21/head
András Veres-Szentkirályi 2021-03-02 11:18:58 +01:00
rodzic 71ddabcb1d
commit 0c09c84360
1 zmienionych plików z 2 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ from __future__ import division, with_statement
from six.moves import range
from six.moves import map
from six.moves import zip
from six import PY3
from math import sin, pi
from random import random
from contextlib import closing
@ -54,7 +55,7 @@ class SSTV(object):
wav.setnchannels(self.nchannels)
wav.setsampwidth(self.bits // 8)
wav.setframerate(self.samples_per_sec)
wav.writeframes(data)
wav.writeframes(data if PY3 else data.tostring())
def gen_samples(self):
"""generates discrete samples from gen_values()