Permalink
Browse files

Wrap clib rand

  • Loading branch information...
hecanjog committed Nov 24, 2018
1 parent ccfdba7 commit 8a8f2b27b79e1cec784b817e2d202181786faf07
Showing with 993 additions and 704 deletions.
  1. +907 −695 pippi/dsp.c
  2. +4 −0 pippi/dsp.pxd
  3. +7 −6 pippi/dsp.pyx
  4. +30 −3 pippi/fx.c
  5. +4 −0 pippi/rand.pxd
  6. +13 −0 pippi/rand.pyx
  7. +27 −0 pippi/soundbuffer.c
  8. +1 −0 setup.py
1,602 pippi/dsp.c

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1 +1,5 @@
cdef double _mag(double[:,:] snd)
cpdef double rand(double low=*, double high=*)
cpdef int randint(int low=*, int high=*)
cpdef object choice(list choices)
@@ -9,6 +9,7 @@ cimport cython
from pippi.soundbuffer import SoundBuffer
from pippi.soundbuffer cimport SoundBuffer
from pippi cimport wavetables as wts
from pippi cimport rand as _rand
# Expose some C flags / constants to python
# FIXME might be faster to use newish cpdef enum defs? donno
@@ -152,14 +153,14 @@ def read(frames, channels=2, samplerate=44100):
return SoundBuffer(frames, channels=channels, samplerate=samplerate)
cpdef double rand(object lowvalue, object highvalue):
if isinstance(lowvalue, tuple):
lowvalue = rand(lowvalue[0], lowvalue[1])
cpdef double rand(double low=0, double high=1):
return _rand.rand(low, high)
if isinstance(highvalue, tuple):
highvalue = rand(highvalue[0], highvalue[1])
cpdef int randint(int low=0, int high=1):
return _rand.randint(low, high)
return <double>random.triangular(lowvalue, highvalue)
cpdef object choice(list choices):
return _rand.choice(choices)
def find(pattern, channels=2, samplerate=44100):
""" Glob for files matching a given pattern and return a generator

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

Oops, something went wrong.
@@ -0,0 +1,4 @@
cpdef double rand(double low=*, double high=*)
cpdef int randint(int low=*, int high=*)
cpdef object choice(list choices)
@@ -0,0 +1,13 @@
from libc.stdlib cimport rand as _rand
from libc.stdlib cimport RAND_MAX
cpdef double rand(double low=0, double high=1):
return (_rand()/<double>RAND_MAX) * (high-low) + low
cpdef int randint(int low=0, int high=1):
return <int>rand(low, high)
cpdef object choice(list choices):
cdef int numchoices = <int>len(choices)
cdef int choice_index = randint(0, numchoices-1)
return choices[choice_index]

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

Oops, something went wrong.
@@ -25,6 +25,7 @@
Extension('pippi.graph', ['pippi/graph.pyx']),
Extension('pippi.interpolation', ['pippi/interpolation.pyx']),
Extension('pippi.oscs', ['pippi/oscs.pyx']),
Extension('pippi.rand', ['pippi/rand.pyx']),
Extension('pippi.soundbuffer', ['pippi/soundbuffer.pyx']),
Extension('pippi.soundpipe', ['pippi/soundpipe.pyx'],
libraries=['soundpipe'],

0 comments on commit 8a8f2b2

Please sign in to comment.