Ddsp
DDSP: Differentiable Digital Signal Processing
Install / Use
/learn @magenta/DdspREADME
DDSP: Differentiable Digital Signal Processing
Demos | Tutorials | Installation | Overview | Blog Post | Papers
DDSP is a library of differentiable versions of common DSP functions (such as synthesizers, waveshapers, and filters). This allows these interpretable elements to be used as part of an deep learning model, especially as the output layers for audio generation.
Getting Started
First, follow the steps in the Installation section to install the DDSP package and its dependencies. DDSP modules can be used to generate and manipulate audio from neural network outputs as in this simple example:
import ddsp
# Get synthesizer parameters from a neural network.
outputs = network(inputs)
# Initialize signal processors.
harmonic = ddsp.synths.Harmonic()
# Generates audio from harmonic synthesizer.
audio = harmonic(outputs['amplitudes'],
outputs['harmonic_distribution'],
outputs['f0_hz'])
Links
- Check out the blog post 💻
- Read the original paper 📄
- Listen to some examples 🔈
- Try out the timbre transfer demo 🎤->🎻
<a id='Demos'></a>
Demos
Colab notebooks demonstrating some of the neat things you can do with DDSP ddsp/colab/demos
-
Timbre Transfer: Convert audio between sound sources with pretrained models. Try turning your voice into a violin, or scratching your laptop and seeing how it sounds as a flute :). Pick from a selection of pretrained models or upload your own that you can train with the
train_autoencoderdemo. -
Train Autoencoder: Takes you through all the steps to convert audio files into a dataset and train your own DDSP autoencoder model. You can transfer data and models to/from google drive, and download a .zip file of your trained model to be used with the
timbre_transferdemo. -
Pitch Detection: Demonstration of self-supervised pitch detection models from the 2020 ICML Workshop paper.
<a id='Tutorials'></a>
Tutorials
To introduce the main concepts of the library, we have step-by-step colab tutorials for all the major library components
ddsp/colab/tutorials.
- 0_processor: Introduction to the Processor class.
- 1_synths_and_effects: Example usage of processors.
- 2_processor_group: Stringing processors together in a ProcessorGroup.
- 3_training: Example of training on a single sound.
- 4_core_functions: Extensive examples for most of the core DDSP functions.
Modules
The DDSP library consists of a core library (ddsp/) and a self-contained training library (ddsp/training/). The core library is split up into into several modules:
- Core: All the differentiable DSP functions.
- Processors: Base classes for Processor and ProcessorGroup.
- Synths: Processors that generate audio from network outputs.
- Effects: Processors that transform audio according to network outputs.
- Losses: Loss functions relevant to DDSP applications.
- Spectral Ops: Helper library of Fourier and related transforms.
Besides the tutorials, each module has its own test file that can be helpful for examples of usage.
<a id='Installation'></a>
Installation
Requires tensorflow version >= 2.1.0, but the core library runs in either eager or graph mode.
sudo apt-get install libsndfile-dev
pip install --upgrade pip
pip install --upgrade ddsp
<a id='Overview'></a>
Overview
Processor
The Processor is the main object type and preferred API of the DDSP library. It inherits from tfkl.Layer and can be used like any other differentiable module.
Unlike other layers, Processors (such as Synthesizers and Effects) specifically format their inputs into controls that are physically meaningful.
For instance, a synthesizer might need to remove frequencies above the Nyquist frequency to avoid aliasing or ensure that its amplitudes are strictly positive. To this end, they have the methods:
get_controls(): inputs -> controls.get_signal(): controls -> signal.__call__(): inputs -> signal. (i.e.get_signal(**get_controls()))
Where:
inputsis a variable number of tensor arguments (depending on processor). Often the outputs of a neural network.controlsis a dictionary of tensors scaled and constrained specifically for the processor.signalis an output tensor (usually audio or control signal for another processor).
For example, here are of some inputs to an Harmonic() synthesizer:
And here are the resulting controls after logarithmically scaling amplitudes, removing harmonics above the Nyquist frequency, and normalizing the remaining harmonic distribution:
<div align="center"> <img src="https://storage.googleapis.com/ddsp/github_images/example_controls.png" width="800px" alt="logo"></img> </div>Notice that only 18 harmonics are nonzero (sample rate 16kHz, Nyquist 8kHz, 18*440=7920Hz) and they sum to 1.0 at all times
ProcessorGroup
Consider the situation where you want to string together a group of Processors.
Since Processors are just instances of tfkl.Layer you could use python control flow,
as you would with any other differentiable modules.
In the example below, we have an audio autoencoder that uses a differentiable harmonic+noise synthesizer with reverb to generate audio for a multi-scale spectrogram reconstruction loss.
import ddsp
# Get synthesizer parameters from the input audio.
outputs = network(audio_input)
# Initialize signal processors.
harmonic = ddsp.synths.Harmonic()
filtered_noise = ddsp.synths.FilteredNoise()
reverb = ddsp.effects.TrainableReverb()
spectral_loss = ddsp.losses.SpectralLoss()
# Generate audio.
audio_harmonic = harmonic(outputs['amplitudes'],
outputs['harmonic_distribution'],
outputs['f0_hz'])
audio_noise = filtered_noise(outputs['magnitudes'])
audio = audio_harmonic + audio_noise
audio = reverb(audio)
# Multi-scale spectrogram reconstruction loss.
loss = spectral_loss(audio, audio_input)
ProcessorGroup (with a list)
A ProcessorGroup allows specifies a as a Directed Acyclic Graph (DAG) of processors. The main advantage of using a ProcessorGroup is that the entire signal processing chain can be specified in a .gin file, removing the need to write code in python for every different configuration of processors.
You can specify the DAG as a list of tuples dag = [(processor, ['input1', 'input2', ...]), ...] where processor is an Processor instance, and ['input1', 'input2', ...] is a list of strings specifying input arguments. The output signal of each processor can be referenced as an input by the string 'processor_name/signal' where processor_name is the name of the processor at construction. The ProcessorGroup takes a dictionary of inputs, who keys can be referenced in the DAG.
import ddsp
import gin
# Get synthesizer parameters from the input audio.
outputs = network(audio_input)
# Initialize signal processors.
harmonic = ddsp.synths.Harmonic()
filtered_noise = ddsp.synths.FilteredNoise()
add = ddsp.processors.Add()
reverb = ddsp.effects.TrainableReverb()
spectral_loss = ddsp.losses.SpectralLoss()
# Processor group DAG
dag = [
(harmonic,
['amps', 'harmonic_distribution', 'f0_hz']),
(filtered_noise,
['magnitudes']),
(add,
['harmonic/signal', 'filtered_noise/signal']),
(reverb,
['add/signal'])
]
processor_group = ddsp.processors.ProcessorGroup(dag=dag)
# Generate audio.
audio = processor_group(outputs)
# Multi-scale spectrogram reconstruction loss.
loss = spectral_loss(audio, audio_input)
ProcessorGroup (with gin)
The main advantage of a ProcessorGroup is that it can be defined with a .gin file, allowing flexible configurations without having to write new python code for every new DAG.
In the example below we pretend we have an e
