def assert_soundfiles_equal(inp_fh, out_fh, preamble, dtype):
delay = find_soundfile_delay(out_fh, preamble, dtype)
assert delay != -1, "Test Preamble pattern not found"
out_fh.seek(delay)
mframes = 0
blocksize = 2048
unsigned_dtype = 'u' + dtype.lstrip('u')
inpblk = np.zeros((blocksize, inp_fh.channels), dtype=dtype)
for outblk in out_fh.blocks(blocksize, dtype=dtype, always_2d=True):
readframes = inp_fh.buffer_read_into(inpblk[:len(outblk)], dtype=dtype)
inp = inpblk[:readframes].view(unsigned_dtype)
out = outblk.view(unsigned_dtype)
npt.assert_array_equal(inp, out, "Loopback data mismatch")
mframes += readframes
print("Matched %d of %d frames; Initial delay of %d frames; %d frames truncated"
% (mframes, len(inp_fh), delay, len(inp_fh) - inp_fh.tell()))
评论列表
文章目录