added LPCNet torch implementation

Signed-off-by: Jan Buethe <jbuethe@amazon.de>
This commit is contained in:
Jan Buethe 2023-09-05 12:29:38 +02:00
parent 90a171c1c2
commit 35ee397e06
No known key found for this signature in database
GPG key ID: 9E32027A35B36314
38 changed files with 3200 additions and 0 deletions

View file

@ -0,0 +1,36 @@
import torch
def find(a, v):
try:
idx = a.index(v)
except:
idx = -1
return idx
def interleave_tensors(tensors, dim=-2):
""" interleave list of tensors along sequence dimension """
x = torch.cat([x.unsqueeze(dim) for x in tensors], dim=dim)
x = torch.flatten(x, dim - 1, dim)
return x
def _interleave(x, pcm_levels=256):
repeats = pcm_levels // (2*x.size(-1))
x = x.unsqueeze(-1)
p = torch.flatten(torch.repeat_interleave(torch.cat((x, 1 - x), dim=-1), repeats, dim=-1), -2)
return p
def get_pdf_from_tree(x):
pcm_levels = x.size(-1)
p = _interleave(x[..., 1:2])
n = 4
while n <= pcm_levels:
p = p * _interleave(x[..., n//2:n])
n *= 2
return p