X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2s%2Fpd.py;h=bfb2c9e9f71b3952551d46499a957b7066c663ff;hb=2842721f189c5338d268a6e70002936289ae6069;hp=e14e5a4b4d369a079ce9e62c9fda4daf12caea6b;hpb=07e40f346ac1ed5ca98f636f2dd0ba5a7fe0011e;p=libsigrokdecode.git diff --git a/decoders/i2s/pd.py b/decoders/i2s/pd.py index e14e5a4..bfb2c9e 100644 --- a/decoders/i2s/pd.py +++ b/decoders/i2s/pd.py @@ -14,11 +14,11 @@ ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## import sigrokdecode as srd +import struct ''' OUTPUT_PYTHON format: @@ -33,9 +33,6 @@ Packet: : integer ''' -class SamplerateError(Exception): - pass - class Decoder(srd.Decoder): api_version = 3 id = 'i2s' @@ -60,6 +57,9 @@ class Decoder(srd.Decoder): ) def __init__(self): + self.reset() + + def reset(self): self.samplerate = None self.oldws = 1 self.bitcount = 0 @@ -89,12 +89,12 @@ class Decoder(srd.Decoder): self.put(self.ss_block, self.samplenum, self.out_ann, data) def report(self): - # Calculate the sample rate. samplerate = '?' if self.ss_block is not None and \ self.first_sample is not None and \ - self.ss_block > self.first_sample: + self.ss_block > self.first_sample and \ + self.samplerate: samplerate = '%d' % (self.samplesreceived * self.samplerate / (self.ss_block - self.first_sample)) @@ -113,25 +113,18 @@ class Decoder(srd.Decoder): h += b'\x01\x00' # Audio format (0x0001 == PCM) h += b'\x02\x00' # Number of channels (2) h += b'\x80\x3e\x00\x00' # Samplerate (16000) - h += b'\x00\x7d\x00\x00' # Byterate (32000) + h += b'\x00\xfa\x00\x00' # Byterate (64000) h += b'\x04\x00' # Blockalign (4) - h += b'\x10\x00' # Bits per sample (16) + h += b'\x20\x00' # Bits per sample (32) # Data subchunk h += b'data' - h += b'\xff\xff\x00\x00' # Subchunk size (65535 bytes) TODO + h += b'\xff\xff\xff\xff' # Subchunk size (4G bytes) TODO return h def wav_sample(self, sample): - # TODO: This currently assumes U32 samples, and converts to S16. - s = sample >> 16 - if s >= 0x8000: - s -= 0x10000 - lo, hi = s & 0xff, (s >> 8) & 0xff - return bytes([lo, hi]) + return struct.pack('