A context encoder for audio inpainting

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

Abstract

This paper introduces a deep learning-based "context encoder" (CE) designed for audio inpainting—the process of restoring missing fragments of audio based on the surrounding context. While traditional linear methods like Linear Predictive Coding (LPC) excel at simple, stationary instrumental notes, this neural network approach significantly outperforms them when dealing with the complex, non-stationary signals found in full musical tracks. By operating on time-frequency magnitude representations and utilizing a hybrid loss function, the model achieves superior perceptual coherence for gaps in the range of 64ms.

Introduction

In audio engineering and telecommunications, inpainting is 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 challenging because it is too long for simple sample-by-sample interpolation but often too short for "exemplar-based" methods that rely on repeating large-scale structures like a chorus. The objective 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 architecture—originally a computer vision technique—for the audio domain. The pipeline follows four key stages:

  1. Time-Frequency Representation: Instead of raw waveforms, the system uses Time-Frequency (TF) coefficients derived from a Short-Time Fourier Transform (STFT).
  2. Magnitude-Only Learning: The network predicts only the magnitude of missing TF coefficients. Phase is reconstructed post-hoc using Phase Gradient Heap Integration (PGHI) and the Griffin-Lim algorithm to avoid the "metallic" artifacts common in end-to-end neural synthesis.
  3. Architecture: The model employs an encoder-decoder structure. The encoder compresses the context (audio before and after the gap) into a latent representation, which is then processed by a fully connected layer and expanded by the decoder to generate the missing patch.
  4. Hybrid Loss Function: Training utilizes a weighted mix of Mean Squared Error (MSE) and Normalized MSE to ensure the network attends to both high-energy (loud) and low-energy (quiet) signal components.
The encoder architecture compresses the input spectrogram context into a 2048-element latent vector through six convolutional layers.
The decoder architecture uses a fully connected layer and deconvolutional layers to reconstruct the missing magnitude spectrogram patch from the latent representation.

Datasets and Evaluation

The model was evaluated on two distinct datasets:

  • NSynth: Over 300,000 musical notes from 1,006 instruments, representing "simple" audio with stable harmonics.
  • Free Music Archive (FMA): 8,000 song segments across eight genres, representing "complex" audio with multiple instruments, vocals, and transients.

Performance was measured using the Signal-to-Noise Ratio on magnitude spectrograms ($SNR_{MS}$).

Key Results and Insights

The study revealed a clear divide between stationary and non-stationary signal performance:

  • Complex Music (FMA): The DNN outperformed the reference LPC method by 1.4 dB (7.7 dB vs 6.3 dB). The network proved far more capable of handling the "chaos" and transitions of full musical mixes.
  • Simple Instruments (NSynth): LPC maintained a significant lead, outperforming the DNN by 8.6 dB. The mathematical regularity of a single, steady note is exactly what LPC was designed for, whereas the DNN's generalizations introduced unnecessary error.
  • Transition Prediction: Unlike linear methods that merely extrapolate current sounds, the DNN can "foresee" transitions. If a gap occurs between a steady tone and a loud burst, the DNN learns to place the transition within the gap, whereas linear methods often bleed noise backward inappropriately.

Limitations and Future Work

While promising, the "generalist" nature of the current model limits its peak accuracy. The authors suggest that specialized models (e.g., genre-specific inpainters) or "mixture-of-experts" architectures could improve results. Additionally, moving beyond the STFT toward perceptual transforms like "Audlet" frames or utilizing Recurrent Neural Networks (RNNs) for better long-range dependency modeling represents the next frontier for this research.

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