The Synth
class¶

class
audiomath.
Synth
(func=None, fs=44100, duration='inf', nChannels=1, dtype='float32')¶ Bases:
object
This class is a ducktyped substitute for the numpy array
s.y
at the heart of aSound
instances
, but instead of containing static data it allows onthefly functional computation of the sound signal.Example:
import numpy as np, audiomath as am TWO_PI = 2.0 * np.pi carrierFreq = 440 modFreq = 0.5 @am.Synth def wobble(fs, samples, channels): t = samples / fs return np.sin(TWO_PI * carrierFreq * t) * (0.5  0.5 * np.cos(TWO_PI * modFreq * t)) p = am.Player(wobble) # could also say am.Sound(wobble) print(p.sound) p.Play()
You can also use a preconfigured instance of
Synth
as the decorator, with the same effect:@am.Synth(fs=22050) def y(fs, samples, channels): t = samples / fs return np.sin(2 * np.pi * 440 * t) p = am.Player(y) # could also say am.Sound(y)
…or the
Use()
method of an instance:y = am.Synth() @y.Use def func(fs, samples, channels): # this way, `func` will be unchanged t = samples / fs return np.sin(2 * np.pi * 440 * t) p = am.Player(y) # could also say am.Sound(y)
Parameters:  func – A function that takes three arguments: a scalar
sampling frequency, an
m x 1
array of sample indices, and a1 x n
array of channel indices.func
should return anm x 1
orm x n
array of sample values.  fs (float) – Scalar numeric value specifying the sampling rate.
 duration (float) – The nominal duration of the sound in seconds. May be infinite.
 nChannels (int) – Nominal number of channels.
 dtype (str) – numpy data type for the generated sample data.
 func – A function that takes three arguments: a scalar
sampling frequency, an