Skip to content
Permalink
Browse files

Add distortion, softclip and crossover distortion ported from superco…

…llider
  • Loading branch information...
hecanjog committed May 12, 2019
1 parent 9e3335e commit 036f8351b3fffdb265d65364474b8334b48e7e22
Showing with 3,007 additions and 1,637 deletions.
  1. +3 −0 Makefile
  2. +2,412 −1,161 pippi/fx.c
  3. +87 −0 pippi/fx.pyx
  4. +9 −9 pippi/grains.c
  5. +1 −1 pippi/grains.pyx
  6. +481 −466 pippi/soundpipe.c
  7. +1 −0 pippi/soundpipe.pyx
  8. +13 −0 tests/test_fx.py
@@ -9,6 +9,9 @@ test-grains:
test-wavesets:
python -m unittest tests/test_wavesets.py -v

test-fx:
python -m unittest tests/test_fx.py -v

clean:
rm -rf build/
rm -rf pippi/*.c
3,573 pippi/fx.c

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -13,6 +13,93 @@ from cpython cimport bool

cdef double MINDENSITY = 0.001

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cdef double[:,:] _distort(double[:,:] snd, double[:,:] out):
""" Non-linear distortion ported from supercollider """
cdef int i=0, c=0
cdef unsigned int framelength = len(snd)
cdef int channels = snd.shape[1]
cdef double s = 0

for i in range(framelength):
for c in range(channels):
s = snd[i,c]
if s > 0:
out[i,c] = s / (1.0 + abs(s))
else:
out[i,c] = s / (1.0 - s)

return out

cpdef SoundBuffer distort(SoundBuffer snd):
""" Non-linear distortion ported from supercollider """
cdef double[:,:] out = np.zeros((len(snd), snd.channels), dtype='d')
return SoundBuffer(_distort(snd.frames, out))

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cdef double[:,:] _softclip(double[:,:] snd, double[:,:] out):
""" Soft clip ported from supercollider """
cdef int i=0, c=0
cdef unsigned int framelength = len(snd)
cdef int channels = snd.shape[1]
cdef double mags=0, s=0

for i in range(framelength):
for c in range(channels):
mags = abs(snd[i,c])
s = snd[i,c]
if mags <= 0.5:
out[i,c] = s
else:
out[i,c] = (mags - 0.25) / s

return out

cpdef SoundBuffer softclip(SoundBuffer snd):
""" Soft clip ported from supercollider """
cdef double[:,:] out = np.zeros((len(snd), snd.channels), dtype='d')
return SoundBuffer(_softclip(snd.frames, out))

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cdef double[:,:] _crossover(double[:,:] snd, double[:,:] out, double[:] amount, double[:] smooth, double[:] fade):
""" Crossover distortion ported from the supercollider CrossoverDistortion ugen """
cdef int i=0, c=0
cdef unsigned int framelength = len(snd)
cdef int channels = snd.shape[1]
cdef double s=0, pos=0, a=0, f=0, m=0

for i in range(framelength):
pos = <double>i / <double>framelength
a = _linear_pos(amount, pos)
m = _linear_pos(smooth, pos)
f = _linear_pos(fade, pos)

for c in range(channels):
s = abs(snd[i,c]) - a
if s < 0:
s *= (1.0 + (s * f)) * m

if snd[i,c] < 0:
s *= -1

out[i,c] = s

return out

cpdef SoundBuffer crossover(SoundBuffer snd, object amount, object smooth, object fade):
""" Crossover distortion ported from the supercollider CrossoverDistortion ugen """
cdef double[:] _amount = wavetables.to_window(amount)
cdef double[:] _smooth = wavetables.to_window(smooth)
cdef double[:] _fade = wavetables.to_window(fade)
cdef double[:,:] out = np.zeros((len(snd), snd.channels), dtype='d')
return SoundBuffer(_crossover(snd.frames, out, _amount, _smooth, _fade))

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -53,7 +53,7 @@ cdef class Cloud:
self.wtsize = wtsize

if window is None:
window = 'hann'
window = 'sine'
self.window = to_window(window)

if position is None:
Oops, something went wrong.

0 comments on commit 036f835

Please sign in to comment.
You can’t perform that action at this time.