- # Initial values.
- lastsample = inbuf[0]
- for i in range(channels):
- oldbit[i] = (lastsample & (1 << i)) >> i
-
- # TODO: Handle LAs with more/less than 8 channels.
- for s in inbuf:
- # Optimization: Skip identical bytes (no transitions).
- if lastsample != s:
- for i in range(channels):
- curbit = (s & (1 << i)) >> i
- # Optimization: Skip identical bits (no transitions).
- if oldbit[i] == curbit:
- continue
- elif (oldbit[i] == 0 and curbit == 1):
- rising[i] += 1
- elif (oldbit[i] == 1 and curbit == 0):
- falling[i] += 1
- oldbit[i] = curbit
+ # Total number of transitions is the sum of rising and falling edges.
+ for i in range(channels):
+ transitions[i] = rising[i] + falling[i]