Skip to main content

DRCinv — Audio Compression/Expansion Model-Based Inversion

DRCinv is a Python implementation of forward dynamic range compression and expansion, together with model-based inversion for audio signal reconstruction.

This repository accompanies the research work:

H. Sun, D. Fourer, and H. Maaref, “Hybrid Model-Driven Inversion of Audio Dynamic Range Compression and Expansion,” submitted to IEEE/ACM Transactions on Audio, Speech, and Language Processing, 2026.

Project page: https://hdrc-inv.github.io/ Source code: https://github.com/dfourer/DRCinv

Publication status: The project page describes the paper as submitted. Update the citation and add the DOI when the final bibliographic details are available.

Overview

Dynamic range compression and expansion are widely used to modify the amplitude dynamics of audio signals. DRCinv provides functions to simulate these processes and estimate the original signal from processed audio using a model-based inversion approach.

The implementation exposes two principal functions:

  • drc_forward: apply dynamic range compression or expansion.
  • drc_inverse: estimate the original signal from the processed signal, given the model parameters.

Installation

Install from the project directory during development:

python -m pip install -e .

Once the drcinv distribution is published on PyPI, it can be installed with:

pip install drcinv

The package requires Python 3.10 or later, NumPy and SciPy.

Quick start

import numpy as np
from drcinv import drc_forward, drc_inverse

Fs = 44100
x = 0.1 * np.sin(2 * np.pi * 440 * np.arange(Fs) / Fs)

# [threshold (dBFS), ratio, envelope attack/release (s),
#  gain attack/release (s), detector order]
q = [-20, 4, 0.01, 0.1, 0.01, 0.1, 2]

# Compress and reconstruct
processed = drc_forward(x, Fs, q, mode="comp")
reconstructed = drc_inverse(processed, Fs, q, mode="comp")

The parameter vector is q = [L, R, tau_v_att, tau_v_rel, tau_g_att, tau_g_rel, p], where L is the threshold in dBFS, R is the ratio, the four tau values are time constants in seconds, and p is the detector order (1 for peak, 2 for RMS-like detection).

Set mode="comp" for downward compression or mode="exp" for downward expansion. The inverse function also supports the numerical solver option optim="hybr" (default) or optim="brentq".

Illustrations

The following plots reproduce the visual material linked from the project webpage. Image paths are relative to this README and assume that the corresponding PNG files are stored in docs/.

Compressor

Original vs. processed signal

Original and compressed signals

Original vs. reconstructed signal

Original and reconstructed signals after compression

Expander

Original vs. processed signal

Original and expanded signals

Original vs. reconstructed signal

Original and reconstructed signals after expansion

Full audio demonstration

The repository includes examples/demo_drcinv.py, a complete audio example that reads examples/input.mp3, applies forward DRC, reconstructs the original signal, and evaluates reconstruction accuracy and processing speed.

Install the library locally and the dependencies required by the example:

python -m pip install -e .
python -m pip install soundfile matplotlib

Run from the repository root:

python examples/demo_drcinv.py

The example loads the MP3 relative to its own location, so it can find examples/input.mp3 regardless of the working directory. Stereo audio is converted to mono by averaging the channels. The code uses a peak-normalization helper for the listening files; the actual forward and inverse computations use the unnormalized signal.

Choose compression or expansion

At the beginning of examples/demo_drcinv.py, choose the processing mode and inverse solver:

mode = "exp"     # "comp" (compression) or "exp" (expansion)
optim = "hybr"   # "hybr" or "brentq"

The example defines separate parameter vectors for compression and expansion. The compression settings are:

q = [-45.0, 8.0, 0.001, 0.150, 0.0005, 0.200, 2]

The expansion settings are:

q = [-10.0, 4.0, 0.003, 0.050, 0.002, 0.080, 2]

Forward processing and reconstruction

The core of the example is:

from drcinv import drc_forward, drc_inverse

# x and Fs are loaded from the input audio file; q and mode are set above.
y = drc_forward(x, Fs, q, mode=mode)
x_rec = drc_inverse(y, Fs, q, mode=mode, optim=optim)

error = x - x_rec
print(f"Max error: {np.max(np.abs(error)):.3e}")
print(f"RMSE: {np.sqrt(np.mean(error**2)):.3e}")

Here x is the original audio, y the compressed or expanded audio, and x_rec the reconstructed signal. The full example also reports forward and inverse computation times, maximum and root-mean-square reconstruction errors, changes in RMS level, real-time factors (RTF), and inverse processing speed relative to real time.

Generated audio and figures

Running the demonstration writes the following listening files to the current working directory (where the command is launched):

  • x_listen_comp.wav, y_listen_comp.wav, x_rec_listen_comp.wav in compression mode;
  • x_listen_exp.wav, y_listen_exp.wav, x_rec_listen_exp.wav in expansion mode.

It also saves individual plots for the original, processed, and reconstructed waveforms, plus comparisons between the original and reconstructed signals and between normalized original and processed signals. The comparison plots are saved as both PDF and PNG; the other plots are saved as PDF. The script calls plt.show() to display the figures interactively.

The PNGs under docs/ are the figures included in the Illustrations section above; the demonstration does not automatically write to docs/.

Automated tests

The demonstration is an executable example, not a pytest test. Automated tests belong in tests/test_drcinv.py and should contain functions named test_*:

python -m pip install -e ".[test]"
python -m pytest tests/ -v

Citation

If you use this software in academic work, please cite the associated paper. The following entry is provisional and should be updated after publication:

@article{sun2026drcinv,
  title   = {Hybrid Model-Driven Inversion of Audio Dynamic Range Compression and Expansion},
  author  = {Sun, H. and Fourer, D. and Maaref, H.},
  journal = {IEEE/ACM Transactions on Audio, Speech, and Language Processing},
  year    = {2026},
  note    = {Submitted manuscript}
}

License

See the LICENSE file for the terms applicable to this software. Ensure that the license file is included before public distribution.

Metadata

Release files for drcinv 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drcinv 0.1.0
File Size Uploaded Provenance
drcinv-0.1.0.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for drcinv 0.1.0
File Interpreter ABI Platform
drcinv-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / drcinv-0.1.0.tar.gz

Download URL drcinv-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f99c881df75fdf62a27980e69d3f9e442565b6138d8863da3789fef165d47a24
BLAKE2b-256 checksum
How to use checksums
5b2f0feb644b7aa80cabe779863b39ad1d45869dff84955a4816ca935f8383f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / drcinv-0.1.0-py3-none-any.whl

Download URL drcinv-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f35d0acd4402b535199dc4842f0487277c10b5584a278ad4c8a80e1a5ce1a1e
BLAKE2b-256 checksum
How to use checksums
f83df7b3c6cb7f72ad2821194f91746abd1a0961e517bad27b385088c5339f08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for drcinv 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page