]> sigrok.org Git - libsigrokdecode.git/commitdiff
i2s: make samplerate meta data optional
authorGerhard Sittig <redacted>
Sun, 17 Dec 2017 23:05:40 +0000 (00:05 +0100)
committerUwe Hermann <redacted>
Tue, 13 Feb 2018 17:50:48 +0000 (18:50 +0100)
Only emit sound samplerate information when an input stream sample rate
was specified. Cope with the absence of a sample rate for the input
stream. Decoding is still possible, it's just that no timing information
is available.

decoders/i2s/pd.py

index 91801b4e98f9c0c6a62dcb8b92852907513f6092..bfb2c9e9f71b3952551d46499a957b7066c663ff 100644 (file)
@@ -33,9 +33,6 @@ Packet:
 <value>: integer
 '''
 
-class SamplerateError(Exception):
-    pass
-
 class Decoder(srd.Decoder):
     api_version = 3
     id = 'i2s'
@@ -92,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))
@@ -128,8 +125,6 @@ class Decoder(srd.Decoder):
         return struct.pack('<I', self.data)
 
     def decode(self):
-        if not self.samplerate:
-            raise SamplerateError('Cannot decode without samplerate.')
         while True:
             # Wait for a rising edge on the SCK pin.
             sck, ws, sd = self.wait({0: 'r'})