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