This page was generated from examples/helper-examples.ipynb.

Helper functions

[ ]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
[ ]:
import sc3nb as scn
  • SuperCollider coders are familiar and frequently use a number of useful converter functions

  • the helper functions provide pythonic pendants namely currently for (to be extended):

linlin(x, x1, x2, y1, y2, clip)

  • to linearly map x from between [x1, x2] to [y1, y2]

  • no range check is done, clipping as specified (None, “min”, “max” or anything for “minmax”)

[ ]:
xs = np.linspace(1, 9, 100)
plt.figure(figsize=(15,2))
for i, clip in enumerate([None, "min", "max", "minmax"]):
    plt.subplot(1, 4, i+1);
    plt.plot(xs, scn.linlin(xs, 3, 7, 500, 300, clip))

midicps and cpsmidi

[ ]:
scn.midicps(69.2)  # convert MIDI note to cycles per second (cps) in [Hz]
[ ]:
scn.cpsmidi(440)   # and back to MIDI note (in float resolution)

clip(value, minimim, maximum)

[ ]:
xs = np.linspace(1,9,100)
plt.plot([scn.clip(x, 5, 7) for x in xs]);

ampdb and dbamp

[ ]:
# dbamp(db) converts dB value in amplitude, 0 dB = 1, '*2' \approx +6dB
dbs = np.linspace(-20, 20)
plt.plot(dbs, [scn.dbamp(d) for d in dbs]);
# plt.semilogy()
[ ]:
# ampdb(amp) converts an amplitude to dB, assuming 0dB=1
scn.ampdb(0.2)
[ ]: