Skip to main content

Differentiable audio effect processors in PyTorch.

Project description

DiffFx

image info

A PyTorch-based library for differentiable audio effects processing.

Documentation pypi

Note: Several excellent libraries already exist, such as GRAFX, dasp-pytorch, NablAFx, and torchcomp. Some of my code is inspired by these libraries, and I'm grateful to their developers for implementing several fundamental processors. My core extension will be developing human-interpretable effect processors, where the parameters of each processor can be easily understood by humans.

Overview

DiffFx provides a collection of differentiable audio effects processors that can be integrated into neural network architectures. Most implementations follow methods from books including Audio Effects: Theory, Implementation and Application and DAFX - Digital Audio Effects (Second Edition)

Installation

pip install diffFx-pytorch

or

git clone https://github.com/ytsrt66589/diffFx-pytorch.git
cd diffFx-pytorch
pip install -e .

Quick Start

You can control each processor using either dsp_params or nn_params. dsp_params represents the exact DSP parameters used for each processor, while nn_params contains normalized parameters ranging from 0 to 1 that are internally mapped to the desired DSP parameters by each processor. dsp_params offers precise manual control over each processor, while nn_params provides learnable control for neural networks.

Using DSP Params

import torch
from diffFx_pytorch.processors.dynamics import Compressor

# Create a compressor
compressor = Compressor(sample_rate=44100)

# Process audio with direct DSP parameters
output = compressor(input_audio, dsp_params={
    'threshold_db': -20.0,
    'ratio': 4.0,
    'knee_db': 6.0,
    'attack_ms': 5.0,
    'release_ms': 50.0,
    'makeup_db': 0.0
})

Neural Network Integration

The library supports deep learning integration through normalized parameters:

import torch
import torch.nn as nn
from diffFx_pytorch.processors.dynamics import Compressor

# Create a neural network controller
class CompressorNet(nn.Module):
    def __init__(self, input_size, num_params):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(input_size, 32),
            nn.ReLU(),
            nn.Linear(32, num_params),
            nn.Sigmoid()  # Output in range [0,1]
        )
    
    def forward(self, x):
        return self.net(x)

# Initialize processor and network
comp = Compressor(sample_rate=44100)
num_params = comp.count_num_parameters()
controller = CompressorNet(input_size=16, num_params=num_params)

# Process audio with predicted parameters
features = torch.randn(batch_size, 16)
norm_params = controller(features)
output = comp(input_audio, nn_params=norm_params)

Examples

Understanding the sound characteristic of each processor

Check examples/processors/notebook to see how each processor affect sound.

Features

Implemented Effects 🎛️

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Check the to-do list above for effects that haven't been implemented yet.

Citation

If you use diffFx-pytorch in your research, please cite:

@software{difffx_pytorch,
  title = {diffFx-pytorch: Differentiable Audio Effects Processing in PyTorch},
  author = {Yen-Tung Yeh},
  year = {2024},
  url = {https://github.com/ytsrt66589/difffx-pytorch}
}

License

This project is licensed under the Apache License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

difffx_pytorch-0.0.3.tar.gz (60.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

difffx_pytorch-0.0.3-py3-none-any.whl (86.3 kB view details)

Uploaded Python 3

File details

Details for the file difffx_pytorch-0.0.3.tar.gz.

File metadata

  • Download URL: difffx_pytorch-0.0.3.tar.gz
  • Upload date:
  • Size: 60.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for difffx_pytorch-0.0.3.tar.gz
Algorithm Hash digest
SHA256 be43095322bb4cca21f068f5b64821ec6aa3a9d70cceabe4a20081a19171f9d7
MD5 cd098608f24551b827a4a4694023c3a5
BLAKE2b-256 73247bfb728d169960d62ea92f78e52f0c52bf8707cd5a979b99daf2da1cc351

See more details on using hashes here.

File details

Details for the file difffx_pytorch-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: difffx_pytorch-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 86.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for difffx_pytorch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4284491045dacf0062d630731f7ca94e8df8928f107fd6e070d384a30ea6def8
MD5 03b7e9251947edb9c1ed69958bf949d5
BLAKE2b-256 34e2c3232e475f04db7f7a2bf15dd86c9d3c0b358eb149463523b8ae27c7d862

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page