mirror of
https://github.com/romanz/amodem.git
synced 2026-04-01 08:46:49 +08:00
sampling: refactor iteration
This commit is contained in:
@@ -53,21 +53,19 @@ class Sampler(object):
|
||||
self.offset += offset
|
||||
|
||||
def next(self):
|
||||
res = self._sample() * self.gain
|
||||
self.offset += self.freq
|
||||
return res
|
||||
return self._sample() * self.gain
|
||||
|
||||
def _sample(self):
|
||||
coeffs, begin = self.interp.get(self.offset)
|
||||
end = begin + self.interp.coeff_len
|
||||
while True:
|
||||
if self.index == end:
|
||||
return np.dot(coeffs, self.buff)
|
||||
|
||||
while self.index < end:
|
||||
self.buff[:-1] = self.buff[1:]
|
||||
self.buff[-1] = self.src.next() # throws StopIteration
|
||||
self.index += 1
|
||||
|
||||
self.offset += self.freq
|
||||
return np.dot(coeffs, self.buff)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import common
|
||||
import sys
|
||||
|
||||
Reference in New Issue
Block a user