Skip to main content

Audio limiter in Cython.

Project description

cylimiter

A small package with stateful audio limiter implementation in Cython. Since the limiter is stateful it is suitable for streaming audio processing.

We're slowly growing into other effects beyond limiter, starting with streaming reverb in v0.4.

What's new?

v0.4: Added reverb with RIR

from cylimiter import ReverbRIR

reverb = ReverbRIR()  # default RIR
# or user-provided RIR:
#  reverb = ReverbRIR([0.001, 0.021, 0.007, ...])

reverb.apply(audio)          # makes a copy
reverb.apply_inplace(audio)  # no copies with np.array input

# preserves context between calls for streaming applications
for chunk in audio_source:
    reverb.apply_inplace(chunk)

Examples

import numpy as np
from cylimiter import Limiter

limiter = Limiter(attack=0.5, release=0.9, delay=100, threshold=0.9)
chunk_size = 1200  # for streaming processing

# Example of applying limiter in-place (more efficient)
audio = np.random.randn(44100) * 10
for i in range(0, 44100, chunk_size):
    chunk = audio[i * chunk_size: (i + 1) * chunk_size]
    limiter.limit_inplace(chunk)
    # ... do sth with chunk

# Example of applying limiter that copies the signal
audio = np.random.randn(1, 44100) * 10
audio_lim = limiter.limit(audio)

# Reset the limiter to re-use it on other signals
limiter.reset()

Installation

From PyPI via pip:

pip install cylimiter

From source:

git clone https://github.com/pzelasko/cylimiter
cd cylimiter
pip install .

Re-generate C++ sources from Cython:

cd extensions
cython -3 --cplus *.pyx

Motivation

I couldn't easily find a package that implements audio limiter in Python in a suitable way for streaming audio. The closest (and the main inspiration) is this gist by @bastibe. Since the algorithm is auto-regressive, I figured C++ will be much more efficient than Python.

Project details


Download files

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

Source Distribution

cylimiter-0.4.0.tar.gz (125.8 kB view details)

Uploaded Source

Built Distribution

cylimiter-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (92.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

Details for the file cylimiter-0.4.0.tar.gz.

File metadata

  • Download URL: cylimiter-0.4.0.tar.gz
  • Upload date:
  • Size: 125.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for cylimiter-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9e93d88573e29943f93264ca890085a53e7089bb8306cf9d5fbd37c4abfc0ac7
MD5 a8a95224763dfa6254f46a0b568f35f3
BLAKE2b-256 f111d51264338c8bb18c4b81c16a34e3b4d7d2f9b21b068e527b5e63f754b615

See more details on using hashes here.

File details

Details for the file cylimiter-0.4.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cylimiter-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e94a1d38e3b3383d0cc67352143a1dd2b4d643bd91390a183ba1af4fa9c80d52
MD5 98ccd7d1fd9ddcc6096daf0dec93f4c0
BLAKE2b-256 74bf42f4ac153e03288661fd70d162269036b20fbc20fb701ed69084719ce4b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page