mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
refactored resampler to handle arb length arrays
This commit is contained in:
parent
5b9ca6d463
commit
a04cfa62f3
2 changed files with 35 additions and 20 deletions
|
@ -51,7 +51,7 @@ fin8 = open("in8.raw", mode='wb')
|
||||||
f48 = open("out48.raw", mode='wb')
|
f48 = open("out48.raw", mode='wb')
|
||||||
fout8 = open("out8.raw", mode='wb')
|
fout8 = open("out8.raw", mode='wb')
|
||||||
|
|
||||||
resampler = codec2.resampler(N48,N8)
|
resampler = codec2.resampler()
|
||||||
|
|
||||||
for f in range(FRAMES):
|
for f in range(FRAMES):
|
||||||
|
|
||||||
|
|
|
@ -134,28 +134,43 @@ class resampler:
|
||||||
# self.nbuffer is the current number of samples in the buffer
|
# self.nbuffer is the current number of samples in the buffer
|
||||||
MEM8 = api.FDMDV_OS_TAPS_48_8K
|
MEM8 = api.FDMDV_OS_TAPS_48_8K
|
||||||
MEM48 = api.FDMDV_OS_TAPS_48K
|
MEM48 = api.FDMDV_OS_TAPS_48K
|
||||||
def __init__(self, n48, n8):
|
|
||||||
print("create 48<->8 kHz resampler with buffers of %d at 48 kHz and %d at 8 kHz" % (n48, n8))
|
def __init__(self):
|
||||||
assert (n48 / n8) == api.FDMDV_OS_48
|
print("create 48<->8 kHz resampler")
|
||||||
self.n8 = int(n8)
|
self.filter_mem8 = np.zeros(self.MEM8, dtype=np.int16)
|
||||||
self.n48 = int(n48)
|
self.filter_mem48 = np.zeros(self.MEM48)
|
||||||
self.in8 = np.zeros(self.MEM8 + self.n8, dtype=np.int16)
|
|
||||||
self.out48 = np.zeros(self.n48, dtype=np.int16)
|
|
||||||
self.in48 = np.zeros(self.MEM48 + self.n48, dtype=np.int16)
|
|
||||||
self.out8 = np.zeros(self.n8, dtype=np.int16)
|
|
||||||
def resample48_to_8(self,in48):
|
def resample48_to_8(self,in48):
|
||||||
assert in48.dtype == np.int16
|
assert in48.dtype == np.int16
|
||||||
assert len(in48) == self.n48
|
# length of input vector must be an interger multiple of api.FDMDV_OS_48
|
||||||
self.in48[self.MEM48:] = in48
|
assert(len(in48) % api.FDMDV_OS_48 == 0)
|
||||||
pin48,flag = self.in48.__array_interface__['data']
|
|
||||||
|
# concat filter memory and input samples
|
||||||
|
in48_mem = np.zeros(self.MEM48+len(in48), dtype=np.int16)
|
||||||
|
in48_mem[:self.MEM48] = self.filter_mem48
|
||||||
|
in48_mem[self.MEM48:] = in48
|
||||||
|
|
||||||
|
pin48,flag = in48_mem.__array_interface__['data']
|
||||||
pin48 += 2*self.MEM48
|
pin48 += 2*self.MEM48
|
||||||
api.fdmdv_48_to_8_short(self.out8.ctypes, pin48, self.n8);
|
n8 = int(len(in48) / api.FDMDV_OS_48)
|
||||||
return self.out8
|
out8 = np.zeros(n8, dtype=np.int16)
|
||||||
|
api.fdmdv_48_to_8_short(out8.ctypes, pin48, n8);
|
||||||
|
self.filter_mem48 = in48_mem[:self.MEM48]
|
||||||
|
|
||||||
|
return out8
|
||||||
|
|
||||||
def resample8_to_48(self,in8):
|
def resample8_to_48(self,in8):
|
||||||
assert in8.dtype == np.int16
|
assert in8.dtype == np.int16
|
||||||
assert len(in8) == self.n8
|
|
||||||
self.in8[self.MEM8:] = in8
|
# concat filter memory and input samples
|
||||||
pin8,flag = self.in8.__array_interface__['data']
|
in8_mem = np.zeros(self.MEM8+len(in8), dtype=np.int16)
|
||||||
|
in8_mem[:self.MEM8] = self.filter_mem8
|
||||||
|
in8_mem[self.MEM8:] = in8
|
||||||
|
|
||||||
|
pin8,flag = in8_mem.__array_interface__['data']
|
||||||
pin8 += 2*self.MEM8
|
pin8 += 2*self.MEM8
|
||||||
api.fdmdv_8_to_48_short(self.out48.ctypes, pin8, self.n8);
|
out48 = np.zeros(api.FDMDV_OS_48*len(in8), dtype=np.int16)
|
||||||
return self.out48
|
api.fdmdv_8_to_48_short(out48.ctypes, pin8, len(in8));
|
||||||
|
self.filter_mem8 = in8_mem[:self.MEM8]
|
||||||
|
|
||||||
|
return out48
|
||||||
|
|
Loading…
Reference in a new issue