Skip to content

Reference library > Processors: Distortion > WaveShaper

WaveShaper

WaveShaper(input=0.0, buffer=None)

Applies wave-shaping as described in the WaveShaperBuffer buffer.

Examples

#-------------------------------------------------------------------------------
# Create a waveshaper buffer that silences any samples with amplitude < 0.5
#-------------------------------------------------------------------------------
buf = WaveShaperBuffer(lambda n: 0 if abs(n) < 0.5 else n)
sine = SineOscillator(120)
waveshaper = WaveShaper(sine, buf)
attenuated = waveshaper * 0.1
attenuated.play()
#-------------------------------------------------------------------------------
# Create a range of different waveshaper buffers, and iterate through them.
#-------------------------------------------------------------------------------
import time
import math
import random

sin_buf = WaveShaperBuffer(lambda n: math.sin(n * math.pi / 2))
cos_buf = WaveShaperBuffer(lambda n: math.cos(n * math.pi / 2))
tan_buf = WaveShaperBuffer(lambda n: math.tan(n * math.pi / 2))
tanh_buf = WaveShaperBuffer(lambda n: math.tanh(n * 20))
sinx_buf = WaveShaperBuffer(lambda n: math.sin(256 * n * math.pi / 2))
invert_buf = WaveShaperBuffer(lambda n: 1 - n if n > 0 else -1 - n)
noise_buf = WaveShaperBuffer(lambda n: random.uniform(0, n))
bufs = [sin_buf, cos_buf, tan_buf, tanh_buf, sinx_buf, invert_buf, noise_buf]

sine = SineOscillator(120)
waveshaper = WaveShaper(sine, sin_buf)
attenuated = waveshaper * 0.1
attenuated.play()

for buf in bufs:
    waveshaper.set_buffer("buffer", buf)
    time.sleep(1.0)

attenuated.stop()

Last update: 2024-01-30
Created: 2023-12-03