From: Joel Holdsworth Date: Fri, 6 Apr 2012 21:01:30 +0000 (+0100) Subject: srd/i2s: Added sample-rate and bit-depth to report X-Git-Tag: libsigrokdecode-0.1.0~6 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=780a5beeaf36e7af20f4f37c0f13473f3f9bb1d3;p=libsigrokdecode.git srd/i2s: Added sample-rate and bit-depth to report --- 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