diff options
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/i2s/i2s.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/decoders/i2s/i2s.py b/decoders/i2s/i2s.py index 23f625d..d627ebb 100644 --- a/decoders/i2s/i2s.py +++ b/decoders/i2s/i2s.py @@ -50,16 +50,29 @@ class Decoder(srd.Decoder): self.bitcount = 0 self.data = 0 self.samplesreceived = 0 + self.first_sample = None self.start_sample = None self.samplenum = -1 self.wordlength = -1 def start(self, metadata): + self.samplerate = metadata['samplerate'] self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2s') self.out_ann = self.add(srd.OUTPUT_ANN, 'i2s') def report(self): - return 'I2S: %d samples received' % self.samplesreceived + + # Calculate the sample rate + samplerate = '?' + if self.start_sample != None and \ + self.first_sample != None and \ + self.start_sample > self.first_sample: + samplerate = "%d" % (self.samplesreceived * + self.samplerate / (self.start_sample - + self.first_sample)) + + return 'I2S: %d %d-bit samples received at %sHz' % \ + (self.samplesreceived, self.wordlength, samplerate) def decode(self, ss, es, data): for samplenum, (sck, ws, sd) in data: @@ -101,6 +114,10 @@ class Decoder(srd.Decoder): self.data = 0 self.bitcount = 0 self.start_sample = self.samplenum - + + # Save the first sample position + if self.first_sample == None: + self.first_sample = self.samplenum + self.oldws = ws
\ No newline at end of file |