Skip to content

Commit

Permalink
feat: use torchlpc for fast avg, drop torchaudio dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyolicoris committed Sep 11, 2024
1 parent 86e92bc commit 3feab24
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
numpy
numba
torch>=2
torchaudio
torchlpc
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
long_description_content_type="text/markdown",
url="https://github.com/yoyololicon/torchcomp",
packages=["torchcomp"],
install_requires=["torch>=2", "torchaudio", "torchlpc", "numpy", "numba"],
install_requires=["torch>=2", "torchlpc", "numpy", "numba"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
10 changes: 4 additions & 6 deletions torchcomp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.nn.functional as F
from typing import Union
from torchaudio.functional import lfilter
from torchlpc import sample_wise_lpc

from .core import compressor_core

Expand Down Expand Up @@ -88,11 +88,9 @@ def avg(rms: torch.Tensor, avg_coef: Union[torch.Tensor, float]):
).broadcast_to(rms.shape[0])
assert torch.all(avg_coef > 0) and torch.all(avg_coef <= 1)

return lfilter(
rms,
torch.stack([torch.ones_like(avg_coef), avg_coef - 1], 1),
torch.stack([avg_coef, torch.zeros_like(avg_coef)], 1),
False,
return sample_wise_lpc(
rms * avg_coef,
avg_coef[:, None, None].broadcast_to(rms.shape + (1,)) - 1,
)


Expand Down

0 comments on commit 3feab24

Please sign in to comment.