Skip to main content

flamo

Docs | PyPI | ICASSP25-arXiv

Open-source library for frequency-domain differentiable audio processing.

It contains differentiable implementation of common LTI audio system modules with learnable parameters.


⚙️ Optimization of audio LTI systems

Available differentiable audio signal processors - in flamo.processor.dsp:

  • Gains : Gains, Matrices, Householder Matrices
  • Filters : Biquads, State Variable Filters (SVF), Graphic Equalizers (GEQ), Parametric Equalizers (PEQ - not released yet)
  • Delays : Integer Delays, Fractional Delays

Transforms - in flamo.processor.dsp:

  • Transform : FFT, iFFT, time anti-aliasing enabled FFT and iFFT

Utilities, system designers, and optimization - in flamo.processor.system:

  • Series : Serial chaining of differentiable systems
  • Recursion : Closed loop with assignable feedforward and feedback paths
  • Shell: Container class for safe interaction between system, dataset, and loss functions

Optimization - in flamo.optimize:

  • Trainer : Handling of the training and validation steps
  • Dataset : Customizable dataset class and helper methods

🛠️ Installation

To install it via pip, on a new Python virtual environment flamo-env

python3.10 -m venv .flamo-env
source .flamo-env/bin/activate
pip install flamo

If you are using conda, you might need to install libsndfile manually

conda create -n flamo-env python=3.10
conda activate flamo-env
pip install flamo
conda install -c conda-forge libsndfile

For local installation: clone and install dependencies on a new Python virtual environment flamo-env

git clone https://github.com/gdalsanto/flamo
cd flamo
python3.10 -m venv .flamo-env
source .flamo-env/bin/activate
pip install -e .

Note that it requires python>=3.10


💻 How to use the library

We included a few examples in ./examples that take you through the library's API.

The following example demonstrates how to optimize the parameters of Biquad filters to match a target magnitude response. This is just a toy example; you can create and optimize much more complex systems by cascading modules either serially or recursively.

Import modules

import torch
import torch.nn as nn
from flamo.optimize.dataset import Dataset, load_dataset
from flamo.optimize.trainer import Trainer
from flamo.processor import dsp, system
from flamo.functional import signal_gallery, highpass_filter

Define parameters and target response with randomized cutoff frequency and gains

in_ch, out_ch = 1, 2    # input and output channels
n_sections = 2  # number of cascaded biquad sections
fs = 48000      # sampling frequency
nfft = fs*2     # number of fft points

b, a = highpass_filter(
    fc=torch.tensor(fs/2)*torch.rand(size=(n_sections, out_ch, in_ch)), 
    gain=torch.tensor(-1) + (torch.tensor(2))*torch.rand(size=(n_sections, out_ch, in_ch)), 
    fs=fs)
B = torch.fft.rfft(b, nfft, dim=0)
A = torch.fft.rfft(a, nfft, dim=0)
target_filter = torch.prod(B, dim=1) / torch.prod(A, dim=1)

Define an instance of learnable Biquads

filt = dsp.Biquad(
    size=(out_ch, in_ch), 
    n_sections=n_sections,
    filter_type='highpass',
    nfft=nfft,
    fs=fs,
    requires_grad=True,
    alias_decay_db=0,
)   

Use the Shell class to add input and output layers and to get the magnitude response at initialization Optimization is done in the frequency domain. The input will be an impulse in the time domain, thus the input layer should perform the Fourier transform. The target is the magnitude response, so the output layer takes the absolute value of the filter's output.

input_layer = dsp.FFT(nfft)
output_layer = dsp.Transform(transform=lambda x : torch.abs(x))
model = system.Shell(core=filt, input_layer=input_layer, output_layer=output_layer)    
estimation_init = model.get_freq_response()

Set up the optimization framework and launch it. The Trainer class is used to contain the model, training parameters, and training/valid steps in one class.

input = signal_gallery(1, n_samples=nfft, n=in_ch, signal_type='impulse', fs=fs)
target = torch.einsum('...ji,...i->...j', target_filter, input_layer(input))

dataset = Dataset(
    input=input,
    target=torch.abs(target),
    expand=100,
)
train_loader, valid_loader = load_dataset(dataset, batch_size=1)

trainer = Trainer(model, max_epochs=10, lr=1e-2, train_dir="./output")
trainer.register_criterion(nn.MSELoss(), 1)

trainer.train(train_loader, valid_loader)

end get the resulting response after optimization!

estimation = model.get_freq_response()

📖 Documentation

A first version of the documentation is available on the repo's Github Page. Note that we are currently working on improving the documentation to include examples, images, and a more pleasant template.


📖 Reference

This work has been submitted to ICASSP 2025. Pre-print is available on arxiv.

Dal Santo, G., De Bortoli, G. M., Prawda, K., Schlecht, S. J., & Välimäki, V. (2024). FLAMO: An Open-Source Library for Frequency-Domain Differentiable Audio Processing. arXiv preprint arXiv:2409.08723.

Download files

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

Source Distribution

flamo-0.2.17.tar.gz (23.7 MB view details)

Uploaded Source

Built Distribution

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

flamo-0.2.17-py3-none-any.whl (82.7 kB view details)

Uploaded Python 3

File details

Details for the file flamo-0.2.17.tar.gz.

File metadata

  • Download URL: flamo-0.2.17.tar.gz
  • Upload date:
  • Size: 23.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.15

File hashes

Hashes for flamo-0.2.17.tar.gz
Algorithm Hash digest
SHA256 a2129ff01e310c2d81c543ca65aae4db06ae51e642920d966fb7a5256a7bbcf6
MD5 b7f0774296e40a5e43b485f6cef043a0
BLAKE2b-256 9c6fd8e539437b980728dcf30fbbca556d094e77c9f232afeb6ac65992fc534b

See more details on using hashes here.

File details

Details for the file flamo-0.2.17-py3-none-any.whl.

File metadata

  • Download URL: flamo-0.2.17-py3-none-any.whl
  • Upload date:
  • Size: 82.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.15

File hashes

Hashes for flamo-0.2.17-py3-none-any.whl
Algorithm Hash digest
SHA256 8e1f072ced7fe4227e6a521e347b4c250fb3fbe480050b92f675ea426c8e1057
MD5 59397b769143d87199057cb7cf796ae7
BLAKE2b-256 18f4a71850b4ffa307b01186e4ee1e638b08a9db03629a28973e6ac0f9f360ca

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.17 This release

2 files

0.2.16

2 files

0.2.15

2 files

0.2.14

2 files

0.2.13

2 files

0.2.12

2 files

0.2.11

2 files

0.2.10

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.19

2 files

0.0.18

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

Supported by

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