Skip to main content

Python library for audio waveshaping and distortion effects

Project description

waveshaping-py

A Python library for audio waveshaping and distortion effects, ported from the C++ waveshaping library. Designed for non-realtime audio processing using numpy arrays.

Overview

This library provides mathematical waveshaping functions for audio signal processing, including:

  • Clipping: Hard, soft, cubic, algebraic, and sinusoidal clipping
  • Saturation: Tanh, arctangent, error function, exponential, and tube-style saturation
  • Folding: Foldback, sine folding, triangle folding, soft folding, and Chebyshev folding
  • Rectification: Half-wave, full-wave, precision, soft, and tube rectification
  • Polynomial: Quadratic, cubic, odd/even polynomials, Legendre and Hermite polynomials
  • Special Effects: Bitcrushing, ring modulation, amplitude modulation, noise gating, and more

Installation

From PyPI (when published)

pip install waveshaping-py

From Source

git clone https://github.com/tsugumasa320/waveshaping-py.git
cd waveshaping-py
pip install -e .

Quick Start

import numpy as np
import waveshaping as ws

# Create a test signal
t = np.linspace(0, 1, 44100)
signal = np.sin(2 * np.pi * 440 * t)

# Apply soft clipping
clipped = ws.clip.soft(signal, drive=2.0)

# Apply tube saturation
saturated = ws.saturate.tube_sat(signal, drive=1.5)

# Apply wave folding
folded = ws.fold.sine_fold(signal, threshold=0.8)

Module Structure

  • waveshaping.clip: Clipping functions
  • waveshaping.saturate: Saturation functions
  • waveshaping.fold: Wave folding functions
  • waveshaping.rectify: Rectification functions
  • waveshaping.polynomial: Polynomial waveshaping
  • waveshaping.special: Special effects
  • waveshaping.utils: Utility functions

Examples

Clipping

import waveshaping.clip as clip

# Hard clipping with threshold
hard_clipped = clip.hard(signal, threshold=0.7)

# Soft clipping with drive
soft_clipped = clip.soft(signal, drive=3.0)

# Cubic smooth clipping
cubic_clipped = clip.cubic(signal)

Saturation

import waveshaping.saturate as saturate

# Tanh saturation
tanh_sat = saturate.tanh_sat(signal, drive=2.0)

# Tube-style saturation
tube_sat = saturate.tube_sat(signal, drive=1.5)

# Exponential saturation
exp_sat = saturate.exponential(signal, drive=1.2)

Wave Folding

import waveshaping.fold as fold

# Sine folding
sine_folded = fold.sine_fold(signal, threshold=0.8)

# Foldback distortion
foldback = fold.foldback(signal, threshold=0.6)

# Chebyshev polynomial folding
cheb_folded = fold.chebyshev_fold(signal, order=5)

Requirements

  • Python >= 3.7
  • numpy >= 1.19.0
  • scipy >= 1.5.0

Development

Installing for Development

pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black waveshaping/

License

MIT License - see LICENSE file for details.

Acknowledgments

This library is inspired by and ported from the C++ waveshaping library. Mathematical implementations are based on established digital signal processing literature including "DAFX - Digital Audio Effects" and "Designing Audio Effect Plugins in C++".

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

waveshaping_py-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

waveshaping_py-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file waveshaping_py-0.1.0.tar.gz.

File metadata

  • Download URL: waveshaping_py-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for waveshaping_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81c00c1b0617f73f1c01afbf07cc333365df5e3fae83f7de82e987a17d108d90
MD5 d34aadb6b5e1c6c41865b0fb0bc483a0
BLAKE2b-256 71e612dd32e060e9ba3707d5f663c0755bf816a673b59388c382d65853e71d55

See more details on using hashes here.

File details

Details for the file waveshaping_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: waveshaping_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for waveshaping_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8cfc674cdf57a3d1361df308b528d60e01055602e2db1f8b1e011c12afb4640
MD5 237a47d3f7e8ef68df1f0772a7db8596
BLAKE2b-256 dfa7d34900a23d6fa8da8de7988dee742116fe6efd938f538b0faba5af164f59

See more details on using hashes here.

Supported by

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