A Context Encoder For Audio Inpainting

Andrés Marafioti, Nathanaël Perraudin, Nicki Holighaus, Piotr Majdak

TL;DR

This paper introduces a deep learning-based "context encoder" designed to perform audio inpainting—the process of restoring missing fragments of audio (around 64ms) based on the surrounding sound. While traditional linear methods still lead for simple instrument notes, this neural network approach significantly outperforms them when dealing with the complex, non-stationary signals found in full musical tracks.

What Problem Does This Paper Address?

In audio engineering and telecommunications, "inpainting" is the equivalent of Photoshop’s content-aware fill: it’s the art of reconstructing lost or corrupted segments of a signal so that the listener never notices the glitch.

The authors target a specific "Goldilocks zone" of data loss: gaps in the range of tens of milliseconds. This duration is particularly tricky because it is too long for simple sample-by-sample interpolation (which works for micro-clicks) but often too short for "exemplar-based" methods that rely on repeating large-scale structures like a chorus or a verse. The challenge is to generate a reconstruction that is not just mathematically similar, but perceptually "coherent" with the music's rhythm, timbre, and flow.

Methods

The researchers adapted the "Context Encoder" (CE) architecture—originally a computer vision technique—for audio.

  1. Time-Frequency Representation: Instead of feeding raw waveforms into the network (which requires massive datasets and compute), they transform the audio into Time-Frequency (TF) coefficients using a Short-Time Fourier Transform (STFT).
  2. Magnitude-Only Learning: The network is trained to predict only the magnitude of the missing TF coefficients. The phase (which is notoriously difficult for neural networks to "hallucinate" accurately) is reconstructed afterward using a combination of Phase Gradient Heap Integration (PGHI) and the Griffin-Lim algorithm.
  3. Architecture: The model uses an encoder-decoder pipeline. The encoder consists of six convolutional layers that compress the context (the audio before and after the gap) into a latent representation. A fully connected layer then "spreads" this information to the decoder, which uses deconvolutional layers to generate the missing patch.
  4. Hybrid Loss Function: To train the model, they used a weighted mix of Mean Squared Error (MSE) and Normalized MSE. This ensures the network pays attention to both high-energy (loud) and low-energy (quiet) parts of the signal.

Datasets

The authors evaluated their model on two distinct types of audio:

  • NSynth: A massive dataset of over 300,000 musical notes from 1,006 different instruments. This represents "simple" audio with stable harmonics.
  • Free Music Archive (FMA): A collection of 8,000 song segments across eight genres. This represents "complex" audio with multiple instruments, vocals, and transients.

Key Insights and Ideas

  • The Stationary vs. Non-Stationary Divide: The biggest "aha" moment is the comparison with Linear Predictive Coding (LPC). LPC assumes a signal is "stationary" (it doesn't change much over time). This makes LPC nearly unbeatable for a single, steady violin note. However, music is rarely stationary—it has drum hits, frequency slides, and complex layering.
  • Foreseeing Transitions: Unlike linear methods that just "extrapolate" the current sound into the gap, the DNN can "foresee" transitions. For example, if the context before the gap is a steady tone and the context after is a loud burst, the DNN learns to place the transition inside the gap, whereas linear methods would just bleed the noise backward.
  • Phase is the Final Polish: By focusing the neural network on magnitude and using classical signal processing for phase, the authors avoid the "metallic" artifacts often found in pure end-to-end neural audio synthesis.

Key Results

The performance was measured using Signal-to-Noise Ratio on the magnitude spectrograms ($SNR_{MS}$):

  • Music (FMA): The DNN outperformed the reference LPC method by 1.4 dB (7.7 dB vs 6.3 dB). This proves the network is better at handling the "chaos" of full musical mixes.
  • Instruments (NSynth): LPC still holds the crown here, outperforming the DNN by 8.6 dB. The simple, mathematical regularity of a single note is exactly what LPC was designed for, and the DNN's generalizations actually hurt it in this specific case.
  • Gap Flexibility: A network trained on 64ms gaps was successfully used to inpaint 48ms gaps, suggesting the model is somewhat robust to varying gap lengths.

Limitations and Future Work

The authors identify several areas for growth:

  • The "Generalist" Penalty: Training one model to handle all music is difficult. They suggest that specialized models (e.g., a "Jazz" inpainter or a "Drums" inpainter) or a "mixture-of-experts" approach would likely yield much higher accuracy.
  • Perceptual Features: The STFT is a standard tool, but it doesn't perfectly match how humans hear. Future work could involve "Audlet" frames or other transforms that align more closely with the human auditory system.
  • Architecture Evolution: Simply making the convolutional network deeper didn't help much. The authors suggest moving toward Recurrent Neural Networks (RNNs) or other architectures that are better at modeling long-range dependencies in audio.

Summary updated

BibTeX
@article{marafioti2019context,
  author = {Andrés Marafioti and Nathanaël Perraudin and Nicki Holighaus and Piotr Majdak},
  title = {{A Context Encoder For Audio Inpainting}},
  journal = {IEEE ACM Trans. Audio Speech Lang. Process.},
  year = {2019},
  doi = {10.1109/taslp.2019.2947232},
}
Figure