CLM Generators#
in pysndlib.clm
all_pass#
- make_all_pass(feedback, feedforward, size, initial_contents=None, initial_element=0.0, max_size=None, interp_type=Interp.NONE)#
return a new allpass filter (a delay line with a scalers on both the feedback and the feedforward). if length will be changing at run-time, max-size sets its maximum length.
- Parameters:
feedback – scaler on feedback
feedforward – scaler on input
size – length in samples of the delay line
initial_contents – delay line’s initial values
initial_element – delay line’s initial element
max_size – maximum delay size in case the delay changes
interp_type – interpolation type
- Returns:
a new allpass filter
- Return type:
- all_pass(gen, insig, pm=None)#
all-pass filter insig value, pm changes the delay length.
- Parameters:
gen – all_pass gen
insig – input value
pm – change in delay length size. can be + or -
- Return type:
float
- is_all_pass(gen)#
returns True if gen is a all_pass.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of delay |
mus_order |
same as mus-length |
mus_data |
delay line itself (not setable) |
mus_feedback |
feedback scaler |
mus_feedforward |
feedforward scaler |
mus_interp_type |
interpolation choice (not setable) |
Example usage
with Sound(play=True):
alp = make_all_pass(-0.4, 0.4, seconds2samples(0.4))
osc = make_oscil(440.0)
ampf = make_env([0.0, 0.0, 1.0, 1.0, 2.0, 1.0, 3.0, 0.0], length=4410)
for i in range(88200):
outa(i, 0.5 * (all_pass(alp, env(ampf) * oscil(osc))))
See also
all_pass_bank#
- make_all_pass_bank(all_passes)#
return a new all_pass-bank generator.
- Parameters:
all_passes (list) – list of all_pass gens
- Returns:
all_pass_bank gen
- Return type:
- all_pass_bank(gen, insig)#
sum an array of all_pass filters.
- Parameters:
gen – all_pass_bank gen
inputs – can be a list/array of inputs or a single input
- Return type:
float
- is_all_pass_bank(gen)#
returns True if gen is a all_pass_bank.
- Parameters:
gen – gen
- Return type:
bool
asymmetric_fm#
- make_asymmetric_fm(frequency, initial_phase=0.0, r=1.0, ratio=1.0)#
return a new asymmetric_fm generator.
- Parameters:
frequency – frequency of gen
initial_phase – starting phase of gen, in radians
r – amplitude ratio between successive sidebands
ratio – ratio between carrier and sideband spacing
- Returns:
asymmetric_fm gen
- Return type:
- asymmetric_fm(gen, index, fm=0.0)#
next sample from asymmetric fm generator.
- Parameters:
gen – asymmetric_fm gen
index – fm index
fm – fm input
- Return type:
float
- is_asymmetric_fm(gen)#
returns True if gen is a asymmetric_fm.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
“r” parameter; sideband scaler |
mus_offset |
“ratio” parameter |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
fm = make_asymmetric_fm(440.0, 0.0, 0.9, 0.5)
for i in range(44100):
outa(i, 0.5 * asymmetric_fm(fm, 1.0))
comb#
- make_comb(feedback=1.0, size=None, initial_contents=None, initial_element=None, max_size=None, interp_type=Interp.NONE)#
return a new comb filter (a delay line with a scaler on the feedback) of size elements. if the comb length will be changing at run-time, max-size sets its maximum length.
- Parameters:
feedback – scaler on feedback
size – delay length in samples
initial_contents – delay line’s initial values
initial_element – delay line’s initial element
max_size – maximum delay size in case the delay changes
type – interpolation type
- Returns:
comb gen
- Return type:
- comb(gen, insig, pm=None)#
comb filter val, pm changes the delay length.
- Parameters:
gen – comb gen
insig – input value
pm – change in delay length size. can be + or -
- Return type:
float
- is_comb(gen)#
returns True if gen is a comb.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of delay |
mus_order |
same as mus_length |
mus_data |
delay line itself (not setable) |
mus_feedback |
scaler (comb only) |
mus_feedforward |
scaler (notch only) |
mus_interp_type |
interpolation choice (not setable) |
Example usage
with Sound(play=True):
cmb = make_comb(0.4, seconds2samples(0.4))
osc = make_oscil(440.0)
ampf = make_env([0.0, 0.0, 1.0, 1.0, 2.0, 1.0, 3.0, 0.0], length=4410)
for i in range(88200):
outa(i, 0.5 * (comb(cmb, env(ampf) * oscil(osc))))
comb_bank#
- make_comb_bank(combs)#
return a new comb-bank generator.
- Parameters:
combs – list of comb gens
- Returns:
comb_bank gen
- Return type:
- comb_bank(gen, insig)#
sum an array of comb filters.
- Parameters:
gen – comb_bank gen
inputs – can be a list/array of inputs or a single input
- Return type:
float
- is_comb_bank(gen)#
returns True if gen is a comb_bank
- Parameters:
gen – gen
- Return type:
bool
convolve#
- make_convolve(inp, filt, fft_size=512, filter_size=None)#
return a new convolution generator which convolves its input with the impulse response ‘filter’.
- Parameters:
inp – gen or function to read from
filt – np.array of filter
fft_size – fft size used in the convolution
filter_size – how much of filter to use. if None use whole filter
- Returns:
convolve gen
- Return type:
- convolve(gen)#
next sample from convolution generator.
- Parameters:
gen – convolve gen
- Return type:
float
- is_convolve(gen)#
returns True if gen is a convolve.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
fft size used in the convolution |
Example usage
with Sound(play=True, statistics=True):
flt, _ = file2array('oboe.snd', channel=0, beg=0, dur=clm_length('pistol.snd'))
cnv = make_convolve(make_readin('pistol.snd'), flt)
for i in range(88200):
outa(i, .25 * convolve(cnv))
convolve_files#
delay#
- make_delay(size, initial_contents=None, initial_element=None, max_size=None, interp_type=Interp.NONE)#
return a new delay line of size elements. if the delay length will be changing at run-time, max-size sets its maximum length.
- Parameters:
size – delay length in samples
initial_contents – delay line’s initial values
initial_element – delay line’s initial element
max_size – maximum delay size in case the delay changes
type – interpolation type
- Returns:
delay gen
- Return type:
- delay(gen, insig, pm=0.0)#
delay val according to the delay line’s length and pm (‘phase-modulation’). if pm is greater than 0.0, the max-size argument used to create gen should have accommodated its maximum value.
- Parameters:
gen – delay gen
insig – input value
pm – change in delay length size. can be + or -
- Return type:
float
- is_delay(gen)#
returns True if gen is a delay.
- Parameters:
gen – gen
- Return type:
bool
- tap(gen, offset=0.0)#
tap the delay mus_any offset by pm
- Parameters:
gen – delay gen
offset – offset in samples from output point
- Return type:
float
- is_tap(gen)#
returns True if gen is a tap.
- Parameters:
gen – gen
- Return type:
bool
- delay_tick(gen, insig)#
delay val according to the delay line’s length. this merely ‘ticks’ the delay line forward. the argument ‘insi’ is returned.
- Parameters:
gen – delay gen
- Return type:
float
mus_length |
length of delay |
mus_order |
same as mus_length |
mus_data |
delay line itself (not setable) |
mus_interp_type |
interpolation choice (not setable) |
mus_scaler |
available for delay specializations |
mus_location |
current delay line write position |
Example usage
with Sound(play=True):
dly = make_delay(seconds2samples(0.5))
osc1 = make_oscil(440.0)
osc2 = make_oscil(660.0)
for i in range(44100):
outa(i, 0.5 * (oscil(osc1) + delay(dly, oscil(osc2))))
env#
- make_env(envelope, duration=1.0, scaler=1.0, offset=0.0, base=1.0, length=0)#
return a new envelope generator. ‘envelope’ is a list/array of break-point pairs. to create the envelope, these points are offset by ‘offset’, scaled by ‘scaler’, and mapped over the time interval defined by either ‘duration’ (seconds) or ‘length’ (samples). if ‘base’ is 1.0, the connecting segments are linear, if 0.0 you get a step function, and anything else produces an exponential connecting segment.
- Parameters:
envelope – list or np.ndarry of breakpoint pairs
scaler – scaler on every y value (before offset is added)
duration – duration in seconds
offset – value added to every y value
base – type of connecting line between break-points
length – duration in samples
- Result:
env gen
- Return type:
- env(gen)#
next sample from envelope generator.
- Parameters:
gen – env gen
- Return type:
float
- is_env(gen)#
returns True if gen is an env.
- Parameters:
gen – gen
- Return type:
bool
- env_interp(x, env)#
value of envelope env at x.
- Parameters:
x – location in envelope
env – env gen
- Return type:
float
- envelope_interp(x, env)#
value of envelope env at x.
- Parameters:
x – location in envelope
env – env gen
- Return type:
float
- env_any(gen, connection_function)#
generate env output using conncection_func to ‘connect the dots’.
the env-any connecting function takes one argument, the current envelope value treated as going between 0.0 and 1.0 between each two points. :param env: env gen :param connection_function: function used to connect points :rtype: float
mus_location |
number of calls so far on this env |
mus_increment |
base |
mus_data |
original breakpoint list |
mus_scaler |
scaler |
mus_offset |
offset |
mus_length |
duration in samples |
mus_channels |
current position in the break-point list |
Example usage
with Sound(play=True):
gen = make_oscil(440.0)
ampf = make_env([0., 0., 0.01, 1.0, 0.25, 0.1, 1, 0], scaler=.5, length=44100)
for i in range(44100):
outa(i, env(ampf)*oscil(gen))
See also
file2frample#
- make_file2frample(filename, buffer_size=None)#
return an input generator reading all channels of ‘filename’ (a sound file).
- Parameters:
filename – name of file to read
buffer_size – io buffer size
- Returns:
file2frample gen
- Return type:
- file2frample(gen, loc)#
frample of samples at frample ‘samp’ in sound file read by ‘obj’.
- Parameters:
gen – file2frample gen
loc – location in file to read
- Return type:
np.ndarray
- is_file2frample(gen)#
returns True if gen is a file2frample.
- Parameters:
gen – gen
- Return type:
bool
file2sample#
- make_file2sample(filename, buffer_size=None)#
return an input generator reading ‘filename’ (a sound file).
- Parameters:
filename – name of file to read
buffer_size – io buffer size
- Returns:
file2sample gen
- Return type:
- file2sample(gen, loc, chan=0)#
sample value in sound file read by ‘obj’ in channel chan at sample.
- Parameters:
gen – file2sample gen
loc – location in file to read
chan – channel to read
- Return type:
float
- is_file2sample(gen)#
returns True if gen is a file2sample.
- Parameters:
gen – gen
- Return type:
bool
filtered_comb#
- make_filtered_comb(feedback, size, filter, initial_contents=None, initial_element=0.0, max_size=None, interp_type=Interp.NONE)#
return a new filtered comb filter (a delay line with a scaler and a filter on the feedback) of size elements. if the comb length will be changing at run-time, max-size sets its maximum length.
- Parameters:
feedback – scaler on feedback
size – delay length in samples
filter – filter to apply
initial_contents – delay line’s initial values
initial_element – delay line’s initial element
max_size – maximum delay size in case the delay changes
type – interpolation type
- Returns:
filtered_comb gen
- Return type:
- filtered_comb(gen, insig, pm=0.0)#
filtered comb filter val, pm changes the delay length.
- Parameters:
gen – filtered_comb gen
insig – input value
pm – change in delay length size. can be + or -
- Return type:
float
- is_filtered_comb(gen)#
returns True if gen is a filtered_comb.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of delay |
mus_order |
same as mus_length |
mus_data |
delay line itself (not setable) |
mus_feedback |
scaler (comb only) |
mus_feedforward |
scaler (notch only) |
mus_interp_type |
interpolation choice (not setable) |
filtered_comb_bank#
- make_filtered_comb_bank(fcombs)#
return a new filtered_comb-bank generator.
- Parameters:
fcombs – list of filtered_comb gens
- Returns:
filtered_comb_bank gen
- Return type:
- filtered_comb_bank(gen, insig)#
sum an array of filtered_comb filters.
- Parameters:
gen – filtered_comb gen
inputs – can be a list/array of inputs or a single input
- Return type:
float
- is_filtered_comb_bank(gen)#
returns True if gen is a filtered_comb_bank.
- Parameters:
gen – gen
- Return type:
bool
firmant#
- make_firmant(frequency, radius)#
return a new firmant generator (a resonator). radius sets the pole radius (in terms of the ‘unit circle’). frequency sets the resonance center frequency (hz).
- Parameters:
frequency – resonance center frequency in Hz
radius – resonance width, refers to the unit circle, so it should be between 0.0 and (less than) 1.0.
- Returns:
formant gen
- Return type:
- firmant(gen, insig, radians=0.0)#
next sample from resonator generator.
next sample from firmant generator. :param gen: firmant gen :param insig: input value :param radians: frequency in radians :rtype: float
- is_firmant(gen)#
returns True if gen is a firmant.
- Parameters:
gen – gen
- Return type:
bool
mus_phase |
formant radius |
mus_frequency |
formant center frequency |
mus_order |
2 (not setable) |
Example usage
with Sound(play=True):
flt = make_firmant(1000.0, 0.999)
ran1 = make_rand(10000.0, 5.0)
for i in range(44100):
outa(i, 0.5 * firmant(flt, rand(ran1)))
See also
filter#
- make_filter(order, xcoeffs, ycoeffs)#
return a new direct form fir/iir filter, coeff args are list/ndarray.
- Parameters:
order – filter order
xcoeffs – x coeffs
ycoeffs – y coeffs
- Returns:
filter gen
- Return type:
- filter(gen, insig)#
next sample from filter.
- Parameters:
gen – filter gen
insig – input value
- Return type:
float
- is_filter(gen)#
returns True if gen is a filter.
- Parameters:
gen – gen
- Return type:
bool
mus_order |
filter order |
mus_xcoeff |
x (input) coeff |
mus_xcoeffs |
x (input) coeffs |
mus_ycoeff |
y (output) coeff |
mus_ycoeffs |
y (output) coeffs |
mus_data |
current state (input values) |
mus_length |
same as mus_order |
fir_filter#
- make_fir_filter(order, xcoeffs)#
return a new fir filter, xcoeffs a list/ndarray.
- Parameters:
order – filter order
xcoeffs – x coeffs
- Returns:
fir_filter gen
- Return type:
- fir_filter(gen, insig)#
next sample from fir filter.
- Parameters:
gen – fir_filter gen
insig – input value
- Return type:
float
- is_fir_filter(gen)#
returns True if gen is a fir_filter.
- Parameters:
gen – gen
- Return type:
bool
- make_fir_coeffs(order, envelope)#
translates a frequency response envelope (actually, evenly spaced points in a float-vector) into the corresponding FIR filter coefficients. The order of the filter determines how close you get to the envelope.
- Parameters:
order – order of the filter
envelope – response envelope
mus_order |
filter order |
mus_xcoeff |
x (input) coeff |
mus_xcoeffs |
x (input) coeffs |
mus_ycoeff |
y (output) coeff |
mus_ycoeffs |
y (output) coeffs |
mus_data |
current state (input values) |
mus_length |
same as mus_order |
formant#
- make_formant(frequency, radius)#
return a new formant generator (a resonator). radius sets the pole radius (in terms of the ‘unit circle’). frequency sets the resonance center frequency (hz).
- Parameters:
frequency – resonance center frequency in Hz
radius – resonance width, refers to the unit circle, so it should be between 0.0 and (less than) 1.0.
- Returns:
formant gen
- Return type:
- formant(gen, insig, radians=0.0)#
next sample from formant generator.
- Parameters:
gen – formant gen
insig – input value
radians – frequency in radians
- Return type:
float
- is_formant(gen)#
returns True if gen is a formant.
- Parameters:
gen – gen
- Return type:
bool
mus_phase |
formant radius |
mus_frequency |
formant center frequency |
mus_order |
2 (not setable) |
See also
formant_bank#
- make_formant_bank(filters, amps=None)#
return a new formant-bank generator.
- Parameters:
filters – list of filter gens
amps – list of amps to apply to filters
- Returns:
formant_bank gen
- Return type:
- formant_bank(gen, inputs)#
sum a bank of formant generators.
- Parameters:
gen – formant_bank gen
inputs – can be a list/array of inputs or a single input
- Return type:
float
- is_formant_bank(gen)#
returns True if gen is a formant_bank.
- Parameters:
gen – gen
- Return type:
bool
See also
frample2file#
- make_frample2file(filename, chans=1, sample_type=None, header_type=None, comment=None)#
return an output generator writing the sound file ‘filename’ which is set up to have ‘chans’ channels of ‘sample_type’ samples with a header of ‘header_type’. the latter should be sndlib identifiers.
- Parameters:
filename – name of file to write
chans – number of channels
frample2file – sample type of file
header_type – header type of file
- Returns:
sample2file gen
- Return type:
- frample2file(gen, samp, vals)#
add frample ‘val’ to the output stream handled by the output generator ‘obj’ at frample ‘samp’.
- Parameters:
gen – frample2file gem
samp – location in file to write
vals – sample value to write. list or np.ndarray
- Return type:
float
- is_frample2file(gen)#
returns True if gen is a frample2file.
- Parameters:
gen – gen
- Return type:
bool
granulate#
- make_granulate(inp, expansion=1.0, length=0.15, scaler=0.6, hop=0.05, ramp=0.4, jitter=0.0, max_size=0, edit=None)#
return a new granular synthesis generator. ‘length’ is the grain length (seconds), ‘expansion’ is the ratio in timing between the new and old (expansion > 1.0 slows things down), ‘scaler’ scales the grains to avoid overflows, ‘hop’ is the spacing (seconds) between successive grains upon output. ‘jitter’ controls the randomness in that spacing, ‘input’ can be a file pointer. ‘edit’ can be a function of one arg, the current granulate generator. it is called just before a grain is added into the output buffer. the current grain is accessible via mus_data. the edit function, if any, should return the length in samples of the grain, or 0.
- Parameters:
inp – gen or function to read from. if a callback, the function takes 1 input, the direction and should return read value
expansion (Optional[float]) – how much to lengthen or compress the file
length (Optional[float]) – length of file slices that are overlapped
scaler (Optional[float]) – amplitude scaler on slices (to avoid overflows)
hop (Optional[float]) – speed at which slices are repeated in output
ramp (Optional[float]) – amount of slice-time spent ramping up/down
jitter (Optional[float]) – affects spacing of successive grains
max_size (Optional[int]) – internal buffer size
edit – grain editing function. the function should take one argument, the granulate mus_any and return length of grain or 0
- granulate(gen)#
next sample from granular synthesis generator.
- Parameters:
gen – granulate gen
- Return type:
float
- is_granulate(e)#
returns True if gen is a granulate.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
time (seconds) between output grains (hop) |
mus_ramp |
length (samples) of grain envelope ramp segment |
mus_hop |
time (samples) between output grains (hop) |
mus_scaler |
grain amp (scaler) |
mus_increment |
expansion |
mus_length |
grain length (samples) |
mus_data |
grain samples (a float_vector) |
mus_location |
granulate’s local random number seed |
Example usage
with Sound(play=True):
osc = make_oscil(440.0)
sweep = make_env([0,0,1,1], scaler=hz2radians(440.0), length=44100)
grn = make_granulate(lambda d : .2 * oscil(osc, env(sweep)), expansion=2.0, length=.5)
for i in range(88200):
outa(i, granulate(grn))
iir_filter#
- make_iir_filter(order, ycoeffs)#
return a new iir filter, ycoeffs a list/ndarray.
- Parameters:
order – filter order
ycoeffs – y coeffs
- Returns:
iir_filter gen
- Return type:
- iir_filter(gen, insig)#
next sample from iir filter.
- Parameters:
gen – iir_filter gen
insig – input value
- Return type:
float
- is_iir_filter(gen)#
returns True if gen is a iir_filter :param gen: gen :rtype: bool
mus_order |
filter order |
mus_xcoeff |
x (input) coeff |
mus_xcoeffs |
x (input) coeffs |
mus_ycoeff |
y (output) coeff |
mus_ycoeffs |
y (output) coeffs |
mus_data |
current state (input values) |
mus_length |
same as mus_order |
Example usage
with Sound(play=True):
flt = make_iir_filter(3, [0.0, -1.978, 0.998])
ran1 = make_rand(10000.0, 0.002)
for i in range(44100):
outa(i, 0.5 * iir_filter(flt, rand(ran1)))
in_any, out_any, etc#
- out_any(loc, data, channel, output=None)#
add data to output.
- Parameters:
loc – location to write to in samples
data – sample value
channel – channel to write to
output – output to write to. can be an appropriately shaped np.ndarray or sample2file
- outa(loc, data, output=None)#
add data to output in channel 0.
- Parameters:
loc – location to write to in samples
data – sample value
channel – channel to write to
output – output to write to. can be an appropriately shaped np.ndarray or sample2file
- outb(loc, data, output=None)#
add data to output in channel 1.
- Parameters:
loc – location to write to in samples
data – sample value
channel – channel to write to
output – output to write to. can be an appropriately shaped np.ndarray or sample2fil
- outc(loc, data, output=None)#
add data to output in channel 2.
- Parameters:
loc – location to write to in samples
data – sample value
channel – channel to write to
output – output to write to. can be an appropriately shaped np.ndarray or sample2file
- outd(loc, data, output=None)#
add data to output in channel 3.
- Parameters:
loc – location to write to in samples
data – sample value
channel – channel to write to
output – output to write to. can be an appropriately shaped np.ndarray or sample2file
- out_bank(gens, loc, val)#
calls each generator in the gens list, passing it the argument val, then sends that output to the output channels in the list order (the first generator writes to outa, the second to outb, etc).”
- Parameters:
gens – gens to call
loca – location in samples to write to
- Returns:
data
- Return type:
float
- in_any(loc, channel, inp)#
input stream sample at loc in channel chan.
- Parameters:
loc – location to read from
channel – channel to read from
inp – input to read from. can be an appropriately shaped np.ndarray or file2sample
- Returns:
data
- Return type:
float
- ina(loc, inp)#
input stream sample at loc in channel 0.
- Parameters:
loc – location to read from
inp – input to read from. can be an appropriately shaped np.ndarray or file2sample
- Returns:
data
- Return type:
float
- inb(loc, inp)#
input stream sample at loc in channel 1.
- Parameters:
loc – location to read from
channel – channel to read from
inp – input to read from. can be an appropriately shaped np.ndarray or file2sample
- Returns:
data
- Return type:
float
locsig#
- make_locsig(degree=0.0, distance=1.0, reverb=0.0, output=None, revout=None, channels=None, reverb_channels=None, interp_type=Interp.LINEAR)#
return a new generator for signal placement in n channels. channel 0 corresponds to 0 degrees.
- Parameters:
degree – degree to place sound
distance – distance, 1.0 or greater
reverb – reverb amount
output – output to write ‘dry’ signal to. can be an appropriately shaped np.ndarray or sample2file
revout – output to write ‘wet’ signal to. can be an appropriately shaped np.ndarray or sample2file
channels – number of main channels
reverb_channels – number of channels for reverb
interp_type – interpolation of position. can be Interp.LINEAR, Interp.SINUSOIDAL
- locsig(gen, loc, val)#
locsig ‘gen’ channel ‘chan’ scaler.
- Parameters:
gen – locsig gen
loc – location to write to in samples
val – sample value
- Returns:
data
- Return type:
float
- is_locsig(gen)#
returns True if gen is a locsig.
- Parameters:
gen – gen
- Returns:
result
- Return type:
bool
mus_data |
output scalers (a float_vector) |
mus_xcoeff |
reverb scaler |
mus_xcoeffs |
reverb scalers (a float_vector) |
mus_channels |
output channels |
mus_length |
output channels |
Example usage
with Sound(channels=2, play=True):
loc = make_locsig(60.0)
osc = make_oscil(440.0)
for i in range(44100):
locsig(loc, i, .5 * oscil(osc))
- locsig_ref(gen, chan)#
get locsig ‘gen’ channel ‘chan’ scaler for main output.
- Parameters:
gen – locsig gen
chan – channel to get
- Returns:
scaler of chan
- Return type:
float
- locsig_set(gen, chan, val)#
set the locsig generator’s channel ‘chan’ scaler to ‘val’ for main output.
- Parameters:
gen – locsig gen
chan – channel to set
val – value to set to
- Returns:
scaler of chan
- Return type:
float
- locsig_reverb_ref(gen, chan)#
get locsig reverb channel ‘chan’ scaler.
- Parameters:
gen – locsig gen
chan – channel to get
- Returns:
scaler of chan
- Return type:
float
- locsig_reverb_set(gen, chan, val)#
set the locsig reverb channel ‘chan’ scaler to ‘val’.
- Parameters:
gen – locsig gen
chan – channel to set
val – value to set to
- Returns:
scaler of chan
- Return type:
float
- move_locsig(gen, degree, distance)#
move locsig gen to reflect degree and distance.
- Parameters:
gen – locsig gen
degree – new degree
distance – new distance
moving_average#
- make_moving_average(size, initial_contents=None, initial_element=0.0)#
return a new moving_average generator.
- Parameters:
size – averaging length in samples
initial_contents – initial values
initial_element – initial element
- Returns:
moving_average gen
- Return type:
- moving_average(gen, insig)#
moving window average.
- Parameters:
gen – moving_average gen
insig – input value
- Return type:
float
- is_moving_average(gen)#
returns True if gen is a moving_average.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of table |
mus_order |
same as mus_length |
mus_data |
table of last ‘size’ values |
Example usage
with Sound(play=True):
avg = make_moving_average(4410)
osc = make_oscil(440.0)
stop = 44100 - 4410
#avg.print_cache()
for i in range(stop):
val = oscil(osc)
outa(i, val * moving_average(avg, abs(val)))
for i in range(stop, 44100):
outa(i, oscil(osc) * moving_average(avg, 0.0))
moving_max#
- make_moving_max(size, initial_contents=None, initial_element=0.0)#
return a new moving-max generator.
- Parameters:
size – max window length in samples
initial_contents – initial values
initial_element – initial element
- Returns:
moving_max gen
- Return type:
- moving_max(gen, insig)#
moving window max.
- Parameters:
gen – moving_max gen
insig – input value
- Return type:
float
- is_moving_max(gen)#
returns True if gen is a moving_max.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of table |
mus_order |
same as mus_length |
mus_data |
table of last ‘size’ values |
moving_norm#
- make_moving_norm(size, initial_contents=None, scaler=1.0)#
return a new moving-norm generator.
- Parameters:
size – averaging length in samples
initial_contents – initial values
scaler – normalzing value
- Returns:
moving_norm gen
- Return type:
- moving_norm(gen, insig)#
moving window norm.
- Parameters:
gen – moving_norm gen
insig – input value
- Return type:
float
- is_moving_norm(gen)#
returns True if gen is a moving_norm.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of table |
mus_order |
same as mus_length |
mus_data |
table of last ‘size’ values |
ncos#
- make_ncos(frequency, n=1)#
return a new ncos generator, producing a sum of ‘n’ equal amplitude cosines.
- Parameters:
frequency – frequency of generator
n – number of cosines
- Returns:
ncos gen
- Return type:
- ncos(gen, fm=0.0)#
get the next sample from ‘gen’, an ncos generator.
- Parameters:
gen – ncos gen
fm – fm input
- Return type:
float
- is_ncos(gen)#
returns True if gen is a ncos.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
dependent on number of cosines |
mus_length |
n or cosines arg used in make_ncos |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_ncos(440.0, 10);
for i in range(44100):
outa(i, .5 * ncos(gen))
See also
notch#
- make_notch(feedforward=1.0, size=None, initial_contents=None, initial_element=0.0, max_size=None, interp_type=Interp.NONE)#
return a new notch filter (a delay line with a scaler on the feedforward) of size elements. if the notch length will be changing at run-time, max-size sets its maximum length.
- Parameters:
feedforward – scaler on input
size – delay length in samples
initial_contents – delay line’s initial values
initial_element – delay line’s initial element
max_size – maximum delay size in case the delay changes
type – interpolation type
- Returns:
comb gen
- Return type:
- notch(gen, insig, pm=0.0)#
notch filter val, pm changes the delay length.
- Parameters:
gen – notch gen
insig – input value
pm – change in delay length size. can be + or -
- Return type:
float
- is_notch(gen)#
returns True if gen is a notch.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of delay |
mus_order |
same as mus_length |
mus_data |
delay line itself (not setable) |
mus_feedback |
scaler (comb only) |
mus_feedforward |
scaler (notch only) |
mus_interp_type |
interpolation choice (not setable) |
nrxycos#
- make_nrxycos(frequency, ratio=1.0, n=1, r=0.5)#
return a new nrxycos generator.
- Parameters:
frequency – frequency of generator
ratio – ratio between frequency and the spacing between successive sidebands
n – number of sidebands
r – amplitude ratio between successive sidebands (-1.0 < r < 1.0)
- Returns:
nrxycos gen
- Return type:
- nrxycos(gen, fm=0.0)#
next sample of nrxycos generator.
- Parameters:
gen – ncos gen
fm – fm input
- Return type:
float
- is_nrxycos(gen)#
returns True if gen is a nrxycos.
- Parameters:
gen – gen
- Return type:
bool
# mus_frequency
frequency in Hz
mus_phase
phase in radians
mus_scaler
“r” parameter; sideband scaler
mus_length
“n” parameter
mus_increment
frequency in radians per sample
mus_offset
“ratio” parameter
Example usage
with Sound(play=True):
gen = make_nrxycos(440.0,n=10)
for i in range(44100):
outa(i, .5 * nrxycos(gen))
See also
nrxysin#
- make_nrxysin(frequency, ratio=1.0, n=1, r=0.5)#
return a new nrxysin generator.
- Parameters:
frequency – frequency of generator
ratio – ratio between frequency and the spacing between successive sidebands
n – number of sidebands
r – amplitude ratio between successive sidebands (-1.0 < r < 1.0)
- Returns:
nrxysin gen
- Return type:
- nrxysin(gen, fm=0.0)#
next sample of nrxysin generator.
- Parameters:
gen – ncos gen
fm – fm input
- Return type:
float
- is_nrxysin(gen)#
returns True if gen is a nrxysin.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
“r” parameter; sideband scaler |
mus_length |
“n” parameter |
mus_increment |
frequency in radians per sample |
mus_offset |
“ratio” parameter |
Example usage
with Sound(play=True):
gen = make_nrxysin(440.0,n=10)
for i in range(44100):
outa(i, .5 * nrxysin(gen))
See also
nsin#
- make_nsin(frequency, n=1)#
return a new nsin generator, producing a sum of ‘n’ equal amplitude sines.
- Parameters:
frequency – frequency of generator
n – number of sines
- Returns:
nsin gen
- Return type:
- nsin(gen, fm=0.0)#
get the next sample from ‘gen’, an nsin generator.
- Parameters:
gen – ncos gen
fm – fm input
- Return type:
float
- is_nsin(gen)#
returns True if gen is a nsin.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
dependent on number of sines |
mus_length |
n or sines arg used in make_nsin |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_nsin(440.0, 10);
for i in range(44100):
outa(i, .5 * ncos(gen))
See also
one_pole#
- make_one_pole(a0, b1)#
return a new one_pole filter: y(n) = a0 x(n) - b1 y(n-1) b1 < 0.0 gives lowpass, b1 > 0.0 gives highpass.
- Parameters:
a0 – coefficient
b1 – coefficient
- Returns:
one_pole gen
- Return type:
- one_pole(gen, insig)#
one pole filter of input.
- Parameters:
gen – one_pole gen
insig – input
- Return type:
float
- is_one_pole(gen)#
returns True if gen is a one_pole.
- Parameters:
gen – gen
- Return type:
bool
mus_xcoeff |
a0, a1, a2 in equations |
mus_ycoeff |
b1, b2 in equations |
mus_order |
1 or 2 (not setable) |
mus_scaler |
two_pole and two_zero radius |
mus_frequency |
two_pole and two_zero center frequency |
Example usage
with Sound(play=True):
r = make_rand(44100)
op = make_one_zero(.2, .3)
for i in range(44100):
#outa(i, one_pole(op, 0.0))
outa(i, one_zero(op, rand(r)))
See also
one_pole_all_pass#
- make_one_pole_all_pass(size, coeff)#
return a new one_pole all_pass filter size, coeff.
- Parameters:
size – length in samples of the delay line
coeff – coeff of one pole filter
- Returns:
one_pole_all_pass gen
- Return type:
- one_pole_all_pass(gen, insig)#
one pole all pass filter of input.
- Parameters:
gen – one_pole_all_pass gen
insig – input value
- Return type:
float
- is_one_pole_all_pass(gen)#
returns True if gen is a one_pole_all_pass.
- Parameters:
gen – gen
- Return type:
bool
mus_length |
length of delay |
mus_order |
same as mus-length |
mus_data |
delay line itself (not setable) |
mus_feedback |
feedback scaler |
mus_feedforward |
feedforward scaler |
mus_interp-type |
interpolation choice (not setable) |
one_zero#
- make_one_zero(a0, a1)#
return a new one_zero filter: y(n) = a0 x(n) + a1 x(n-1) a1 > 0.0 gives weak lowpass, a1 < 0.0 highpass.
- Parameters:
a0 – coefficient
a1 – coefficient
- Returns:
one_pole gen
- Return type:
- one_zero(gen, insig)#
one zero filter of input.
- Parameters:
gen – one_zero gen
insig – input
- Return type:
float
- is_one_zero(gen)#
returns True if gen is a one_zero.
- Parameters:
gen – gen
- Return type:
bool
mus_xcoeff |
a0, a1, a2 in equations |
mus_ycoeff |
b1, b2 in equations |
mus_order |
1 or 2 (not setable) |
mus_scaler |
two_pole and two_zero radius |
mus_frequency |
two_pole and two_zero center frequency |
See also
oscil#
- make_oscil(frequency=0.0, initial_phase=0.0)#
return a new oscil (sinewave) generator
- Parameters:
frequency – frequency in hz
initial_phase – initial phase in radians
- Returns:
oscil gen
- oscil(gen, fm=0.0, pm=0.0)#
return next sample from oscil gen: val = sin(phase + pm); phase += (freq + fm)
- Parameters:
gen – oscil gen
fm – fm input
pm – pm input
- Return type:
float
- is_oscil(gen)#
returns True if gen is an oscil
- Parameters:
gen – oscil gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_length |
1 (not setable) |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_oscil(440.0)
for i in range(44100):
outa(i, oscil(gen))
See also
oscil_bank#
- make_oscil_bank(freqs, phases, amps=None, stable=False)#
return a new oscil_bank generator. (freqs in radians)
- Parameters:
freqs – list or np.ndarray of frequencies in radians
phases – list or np.ndarray of initial phases in radians
stable – if it is true, oscil_bank can assume that the frequency. this is not operative
- Returns:
oscil_bank gen
- Return type:
- oscil_bank(gen)#
sum an array of oscils
- Parameters:
gen – oscil_bank gen
- Return type:
float
- is_oscil_bank(gen)#
returns True if gen is an oscil_bank
- Parameters:
gen – gen
- Return type:
bool
Example usage
with Sound(play=True):
ob = make_oscil_bank([hz2radians(i) for i in [400,430,490]], [.5, .2, math.pi+.1], [.5, .3, .2])
for i in range(44100*2):
outa(i, oscil_bank(ob))
See also
phase_vocoder#
- make_phase_vocoder(inp, fft_size=512, overlap=4, interp=128, pitch=1.0, analyze=None, edit=None, synthesize=None)#
return a new phase-vocoder generator; input is the input function (it can be set at run-time), analyze, edit, and synthesize are either None or functions that replace the default innards of the generator, fft_size, overlap and interp set the fft_size, the amount of overlap between ffts, and the time between new analysis calls. ‘analyze’, if given, takes 2 args, the generator and the input function; if it returns True, the default analysis code is also called. ‘edit’, if given, takes 1 arg, the generator; if it returns True, the default edit code is run. ‘synthesize’ is a function of 1 arg, the generator; it is called to get the current vocoder output.
- Parameters:
inp – gen or function to read from. if a callback, the function takes 1 input, the direction and should return read value
fft_size (Optional[int]) – fft size used
overlap (Optional[int]) – how many analysis stages overlap
interp (Optional[int]) – samples between fft
pitch (Optional[float]) – pitch scaling ratio
analyze – if used, overrides default. should be a function of two arguments, the generator and the input function.
edit – if used, overrides default. functions of one argument, the phase_vocoder mus_any. change amplitudes and phases
synthesize – if used, overrides default. unctions of one argument, the phase_vocoder mus_any.
- Returns:
phase_vocoder gen
- phase_vocoder(gen)#
next phase vocoder value.
- Parameters:
gen – phase_vocoder gen
- Return type:
float
- is_phase_vocoder(gen)#
returns True if gen is a phase_vocoder.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
pitch shift |
mus_length |
fft_size |
mus_increment |
interp |
mus_hop |
fft_size / overlap |
mus_location |
outctr (counter to next fft) |
Example usage
with Sound(play=True):
pv = make_phase_vocoder(make_readin("oboe.snd"), pitch=2.0)
for i in range(44100):
outa(i, phase_vocoder(pv))
- phase_vocoder_amp_increments(gen)#
returns a ndarray containing the current output sinusoid amplitude increments per sample.
- phase_vocoder_amps(gen)#
returns a ndarray containing the current output sinusoid amplitudes.
- phase_vocoder_freqs(gen)#
returns a ndarray containing the current output sinusoid frequencies.
- phase_vocoder_phases(gen)#
returns a ndarray containing the current output sinusoid phases.
- phase_vocoder_phase_increments(gen)#
returns a ndarray containing the current output sinusoid phase increments.
polyshape#
- make_polyshape(frequency, initial_phase=0.0, coeffs=None, partials=[1.0, 1.0], kind=Polynomial.FIRST_KIND)#
return a new polynomial-based waveshaping generator.
- Parameters:
frequency – frequency of gen in hz
initial_phase – initial phase of gen in radians
coeff – coefficients can be passed to polyshape
partials – a list of harmonic numbers and their associated amplitudes
kind – Chebyshev polynomial choice
- Returns:
polyshape gen
- Return type:
- polyshape(gen, index=1.0, fm=0.0)#
next sample of polynomial-based waveshaper.
- Parameters:
gen – polyshape gen
index – fm index
fm – fm input
- Return type:
float
- is_polyshape(gen)#
returns True if gen is a polyshape.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_scaler |
index |
mus_phase |
phase in radians |
mus_data |
polynomial coeffs |
mus_length |
number of partials |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
wav = make_polyshape(frequency=500, partials=[1, .5, 2, .3, 3, .2])
for i in range(40000):
outa(i, 1. * polyshape(wav))
See also
polywave pysndlib.clm.make_polywave()
partials2polynomial pysndlib.clm.partials2polynomial()
normalize_partials pysndlib.clm.normalize_partials()
normalize_partials pysndlib.clm.normalize_partials()
chebyshev_tu_sum pysndlib.clm.chebyshev_tu_sum()
chebyshev_t_sum pysndlib.clm.chebyshev_t_sum()
chebyshev_t_sum pysndlib.clm.chebyshev_t_sum()
polynomial pysndlib.clm.polynomial()
polywave#
- make_polywave(frequency, partials=[0.0, 1.0], kind=Polynomial.FIRST_KIND, xcoeffs=None, ycoeffs=None)#
return a new polynomial-based waveshaping generator. make_polywave(440.0, partials=[1.0,1.0]) is the same in effect as make_oscil.
- Parameters:
frequency – polywave frequency
partials – a list of harmonic numbers and their associated amplitudes
kind – Chebyshev polynomial choice
xcoeffs – tn for tu-sum case
ycoeffs – un for tu-sum case
- Returns:
polywave gen
- Return type:
- polywave(gen, fm=0.0)#
next sample of polywave waveshaper.
- Parameters:
gen – polywave gen
fm – fm input
- Return type:
float
- is_polywave(gen)#
returns True if gen is a polywave.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_data |
polynomial coeffs |
mus_length |
number of partials |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_polywave(440, partials=[1., .5, 2, .5])
for i in range(44100):
outa(i, .5 * polywave(gen))
See also
polyshape pysndlib.clm.make_polyshape()
partials2polynomial pysndlib.clm.partials2polynomial()
normalize_partials pysndlib.clm.normalize_partials()
normalize_partials pysndlib.clm.normalize_partials()
chebyshev_tu_sum pysndlib.clm.chebyshev_tu_sum()
chebyshev_t_sum pysndlib.clm.chebyshev_t_sum()
chebyshev_t_sum pysndlib.clm.chebyshev_t_sum()
polynomial pysndlib.clm.polynomial()
pulsed_env#
- make_pulsed_env(envelope, duration, frequency)#
produces a repeating envelope. env sticks at its last value, but pulsed-env repeats it over and over.
- Parameters:
env – env gen
duration – duration of envelope
frequency – repetition rate in hz
- Returns:
env output
- Return type:
float
- pulsed_env(gen, fm=0.0)#
next sample from envelope generator.
- Parameters:
gen – env gen
fm – change frequency of repetition
- Return type:
float
- is_pulsed_env(gen)#
returns True if gen is a pulsed_env.
- Parameters:
gen – gen
- Return type:
bool
mus_location |
number of calls so far on this env |
mus_increment |
base |
mus_data |
original breakpoint list |
mus_scaler |
scaler |
mus_offset |
offset |
mus_length |
duration in samples |
mus_channels |
current position in the break-point list |
Example usage
with Sound():
e = make_pulsed_env([0,0,1,1,2,0], .01, 1)
frq = make_env([0,0,1,1], duration=1.0, scaler=hz2radians(50))
for i in range(44100):
outa(i, .5 * pulsed_env(e, env(frq)))
See also
pulse_train#
- make_pulse_train(frequency=1.0, amplitude=1.0, phase=6.283185307179586)#
return a new pulse_train generator. this produces a sequence of impulses.
- Parameters:
frequency – frequency of generator
amplitude – amplitude of generator
phase – initial phase
- Returns:
pulse_train gen
- Return type:
- pulse_train(gen, fm=0.0)#
next pulse train sample from generator.
- Parameters:
gen – pulse_train gen
fm – fm input
- Return type:
float
- is_pulse_train(gen)#
returns True if gen is a pulse_train.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_pulse_train |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_pulse_train(100.0)
e = make_env([0.0, 0.0, .5, 1.0, 1.0, 0.0], scaler=400, length=44100*3)
for i in range(44100*3):
outa(i, pulse_train(gen, hz2radians(env(e))))
See also
rand#
- make_rand(frequency, amplitude=1.0, distribution=None)#
return a new rand generator, producing a sequence of random numbers (a step function). frequency is the rate at which new numbers are chosen.
- Parameters:
frequency – frequency at which new random numbers occur
amplitude – numbers are between -amplitude and amplitude
distribution – distribution envelope
- Returns:
rand gen
- Return type:
- rand(gen, sweep=0.0)#
gen’s current random number. sweep modulates the rate at which the current number is changed.
- Parameters:
gen – rand gen
sweep – fm
- Return type:
float
- is_rand(gen)#
returns True if gen is a rand.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_<gen> |
mus_length |
distribution table np.ndarray length |
mus_data |
distribution table np.ndarray, if any |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(channels=2, play=True):
ran1 = make_rand(5.0, hz2radians(220.0))
ran2 = make_rand_interp(5.0, hz2radians(220.0))
osc1 = make_oscil(440.0)
osc2 = make_oscil(1320.0)
for i in range(88200):
outa(i, 0.5 * oscil(osc1, rand(ran1)))
outb(i, 0.5 * oscil(osc2, rand_interp(ran2)))
See also
rand_interp#
- make_rand_interp(frequency, amplitude=1.0, distribution=None)#
return a new rand_interp generator, producing linearly interpolated random numbers. frequency is the rate at which new end-points are chosen.
- Parameters:
frequency – frequency at which new random numbers occur
amplitude – numbers are between -amplitude and amplitude
distribution – distribution envelope
- Returns:
rand_interp gen
- Return type:
- rand_interp(gen, sweep=0.0)#
gen’s current (interpolating) random number. fm modulates the rate at which new segment end-points are chosen.
- Parameters:
gen – rand_interp gen
sweep – fm
- Return type:
float
- is_rand_interp(gen)#
returns True if gen is a rand_interp. :param gen: gen :rtype: bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_<gen> |
mus_length |
distribution table np.ndarray length |
mus_data |
distribution table np.ndarray, if any |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(channels=2, play=True):
ran1 = make_rand(5.0, hz2radians(220.0))
ran2 = make_rand_interp(5.0, hz2radians(220.0))
osc1 = make_oscil(440.0)
osc2 = make_oscil(1320.0)
for i in range(88200):
outa(i, 0.5 * oscil(osc1, rand(ran1)))
outb(i, 0.5 * oscil(osc2, rand_interp(ran2)))
See also
readin#
- make_readin(filename, chan=0, start=0, direction=1, buffer_size=None)#
return a new readin (file input) generator reading the sound file ‘file’ starting at frample ‘start’ in channel ‘channel’ and reading forward if ‘direction’ is not -1.
- Parameters:
filename – name of file to read
chan – channel to read (0 based)
start – location in samples to start at
direction – forward (1) or backward (-1)
buffer_size – io buffer size
- readin(gen)#
next sample from readin generator (a sound file reader).
- Parameters:
gen – readin gen
- Return type:
float
- is_readin(gen)#
returns True if gen is a readin.
- Parameters:
gen – gen
- Return type:
bool
mus_channel |
channel arg to make_readin (not setable) |
mus_location |
current location in file |
mus_increment |
sample increment (direction arg to make_readin) |
mus_file_name |
name of file associated with gen |
mus_length |
number of framples in file associated with gen |
rxykcos#
- make_rxykcos(frequency, phase=0.0, r=0.5, ratio=1.0)#
return a new rxykcos generator.
- Parameters:
frequency – frequency of generator
ratio – ratio between frequency and the spacing between successive sidebands
r – amplitude ratio between successive sidebands (-1.0 < r < 1.0)
- Returns:
rxykcos gen
- Return type:
- rxykcos(gen, fm=0.0)#
next sample of rxykcos generator.
- Parameters:
gen – rxykcos gen
fm – fm input
- Return type:
float
- is_rxykcos(gen)#
returns True if gen is a rxykcos.
- Parameters:
gen (mus_any) – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
“r” parameter; sideband scaler |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_rxykcos(440.0, r=.5, ratio=1.2)
e = make_env([0.0, .5, 1.0, .0], length=44100*3, base=32)
for i in range(44100*3):
gen.mus_scaler = env(e)
outa(i, .5 * rxykcos(gen))
rxyksin#
- make_rxyksin(frequency, phase, r=0.5, ratio=1.0)#
return a new rxyksin generator.
- Parameters:
frequency – frequency of generator
ratio – ratio between frequency and the spacing between successive sidebands
r – amplitude ratio between successive sidebands (-1.0 < r < 1.0)
- Returns:
rxyksin gen
- Return type:
- rxyksin(gen, fm=0.0)#
next sample of rxyksin generator.
- Parameters:
gen – rxyksin gen
fm – fm input
- Return type:
float
- is_rxyksin(gen)#
returns True if gen is a rxyksin.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
“r” parameter; sideband scaler |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_rxykcos(440.0, r=.5, ratio=.1)
e = make_env([0.0, 1.2, 1.0, .1], length=44100*3)
for i in range(44100*3):
gen.mus_scaler = env(e)
outa(i, .5 * rxykcos(gen))
sample2file#
- make_sample2file(filename, chans=1, sample_type=None, header_type=None, comment=None)#
return an output generator writing the sound file ‘filename’ which is set up to have chans’ channels of ‘sample_type’ samples with a header of ‘header_type’. the latter should be sndlib identifiers.
- Parameters:
filename – name of file to write
chans – number of channels
sample_type – sample type of file
header_type – header type of file
- Returns:
sample2file gen
- Return type:
- sample2file(gen, samp, chan, val)#
add val to the output stream handled by the output generator ‘obj’, in channel ‘chan’ at frample ‘samp’.
- Parameters:
gen – sample2file gem
samp – location in file to write
chan – channel to write
val – sample value to write
- Return type:
float
- is_sample2file(gen)#
returns True if gen is a sample2file.
- Parameters:
gen – gen
- Return type:
bool
src#
- make_src(inp, srate=1.0, width=10)#
return a new sampling-rate conversion generator (using ‘warped sinc interpolation’). ‘srate’ is the ratio between the new rate and the old. ‘width’ is the sine width (effectively the steepness of the low-pass filter), normally between 10 and 100. ‘input’ if given is an open file stream.
- Parameters:
inp – gen or function to read from. if a callback, the function takes 1 input, the direction and should return read value
srate – ratio between the old sampling rate and the new
width – how many samples to convolve with sinc function
- Returns:
src gen
- Return type:
- src(gen, sr_change=0.0)#
next sampling rate conversion sample. ‘pm’ can be used to change the sampling rate on a sample-by-sample basis. ‘input-function’ is a function of one argument (the current input direction, normally ignored) that is called internally whenever a new sample of input data is needed. if the associated make_src included an ‘input’ argument, input-function is ignored.
- Parameters:
gen – src gen
sr_change – change in ratio
- Return type:
float
- is_src(gen)#
returns True if gen is a src.
- Parameters:
gen – gen
- Return type:
bool
mus_increment |
srate arg to make_src |
Example usage
with Sound(play=True, srate=22050):
rd = make_readin("oboe.snd");
length = 2 * mus_sound_framples("oboe.snd")
sr = make_src(rd, .5);
for i in range(length):
outa(i, src(sr))
ssb_am#
- make_ssb_am(frequency, order=40)#
return a new ssb_am generator.
- Parameters:
frequency – frequency of generator
order – embedded delay line size
- Returns:
ssb_am gen
- Return type:
- ssb_am(gen, insig, fm=0.0)#
get the next sample from ssb_am generator.
- Parameters:
gen – ssb_am gen
fm – fm input
- Return type:
float
- is_ssb_am(gen)#
returns True if gen is a ssb_am.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase (of embedded sin osc) in radians |
mus_order |
embedded delay line size |
mus_length |
same as mus_order |
mus_interp_type |
mus_interp_none |
mus_xcoeff |
FIR filter coeff |
mus_xcoeffs |
embedded Hilbert transform FIR filter coeffs |
mus_data |
embedded filter state |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen1 = make_ssb_am(750, 40)
gen2 = make_ssb_am(700, 40)
rd = make_readin('oboe.snd')
for i in range(44100):
outa(i, .5*(ssb_am(gen1, readin(rd)) + ssb_am(gen2, readin(rd))))
See also
table_lookup#
- make_table_lookup(frequency=0.0, initial_phase=0.0, wave=None, size=None, interp_type=Interp.LINEAR)#
return a new table_lookup generator. the default table size is 512; use size to set some other size, or pass your own list/array as the ‘wave’.
- Parameters:
frequency – frequency of gen in hz
initial_phase – initial phase of gen in radians
wave – np.ndarray if provided is waveform
size – if no wave provided, this will allocate a table of size
interp_type – type of interpolation used
- Returns:
table_lookup gen
- Return type:
- table_lookup(gen, fm=0.0)#
return next sample from table_lookup generator.
- Parameters:
gen – table_lookup gen
fm – fm input
- Return type:
float
- is_table_lookup(gen)#
returns True if gen is a table_lookup.
- Parameters:
gen – gen
- Return type:
bool
- make_table_lookup_with_env(frequency, envelope, size=None)#
return a new table_lookup generator with the envelope loaded in with size.
- Parameters:
frequency – frequency of gen in hz
env – envelope shape to load into generator
size – size of table derived from envelope
- Returns:
table_lookup gen
- Return type:
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_data |
wave float-vector |
mus_length |
wave size (not setable) |
mus_interp-type |
interpolation choice (not setable) |
mus_increment |
table increment per sample |
Example usage
with Sound(play=True):
gen = make_table_lookup(440.0, wave=partials2wave([1., .5, 2, .5]))
for i in range(44100):
outa(i, .5 * table_lookup(gen))
sawtooth_wave#
- make_sawtooth_wave(frequency, amplitude=1.0, phase=3.141592653589793)#
return a new sawtooth_wave generator.
- Parameters:
frequency – frequency of generator
amplitude – amplitude of generator
phase – initial phase
- Returns:
sawtooth_wave gen
- Return type:
- sawtooth_wave(gen, fm=0.0)#
next sawtooth wave sample from generator.
- Parameters:
gen – polyshape gen
fm – fm input
- Return type:
float
- is_sawtooth_wave(gen)#
returns True if gen is a sawtooth_wave.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_sawtooth_wave |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_sawtooth_wave(261.0)
lfo = make_oscil(.5)
for i in range(44100*3):
outa(i, .5 * sawtooth_wave(gen, oscil(lfo) * hz2radians(20)))
See also
square_wave#
- make_square_wave(frequency, amplitude=1.0, phase=0.0)#
return a new square_wave generator.
- Parameters:
frequency – frequency of generator
amplitude – amplitude of generator
phase – initial phase
- Returns:
square_wave gen
- Return type:
- square_wave(gen, fm=0.0)#
next square wave sample from generator.
- Parameters:
gen – polyshape gen
fm – fm input
- Return type:
float
- is_square_wave(gen)#
returns True if gen is a square_wave.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_square_wave |
mus_width |
width of square-wave pulse (0.0 to 1.0) |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_square_wave(261.0)
e = make_env([0.0, .5, .5, .1, 1.0, .8], length=44100*2)
for i in range(44100*2):
gen.mus_width = env(e)
outa(i, .5 * square_wave(gen))
See also
triangle_wave#
- make_triangle_wave(frequency, amplitude=1.0, phase=3.141592653589793)#
return a new triangle_wave generator.
- Parameters:
frequency – frequency of generator
amplitude – amplitude of generator
phase – initial phase
- Returns:
triangle_wave gen
- Return type:
- triangle_wave(gen, fm=0.0)#
next triangle wave sample from generator.
- Parameters:
gen – polyshape gen
fm – fm input
- Return type:
float
- is_triangle_wave(gen)#
returns True if gen is a triangle_wave.
- Parameters:
gen – gen
- Return type:
bool
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_scaler |
amplitude arg used in make_triangle_wave |
mus_increment |
frequency in radians per sample |
Example usage
with Sound(play=True):
gen = make_triangle_wave(440.0)
for i in range(44100):
outa(i, .5 * triangle_wave(gen))
See also
two_pole#
- make_two_pole(frequency=None, radius=None, a0=None, b1=None, b2=None)#
return a new two_pole filter: y(n) = a0 x(n) - b1 y(n-1) - b2 y(n-2).
- Parameters:
frequency – Center frequency in Hz
radius – Radius of filter. Refers to the unit circle, so it should be between 0.0 and (less than) 1.0.
kwargs – If frequency and radius not provided, these should be keyword arguments ‘a0’, ‘b1’, ‘b2’
- Returns:
two_pole gen
- Return type:
- two_pole(gen, insig)#
two pole filter of input.
- Parameters:
gen – two_pole gen
insig – input
- Return type:
float
- is_two_pole(gen)#
returns True if gen is a two_pole.
- Parameters:
gen – gen
- Return type:
bool
mus_xcoeff |
a0, a1, a2 in equations |
mus_ycoeff |
b1, b2 in equations |
mus_order |
1 or 2 (not setable) |
mus_scaler |
two_pole and two_zero radius |
mus_frequency |
two_pole and two_zero center frequency |
Example usage
with Sound("out1.aif", 1):
flt = make_two_pole(1000.0, 0.999)
ran1 = make_rand(10000.0, 0.002)
for i in range(44100):
outa(i, 0.5 * two_pole(flt, rand(ran1)))
See also
two_zero#
- make_two_zero(frequency=None, radius=None, a0=None, a1=None, a2=None)#
return a new two_zero filter: y(n) = a0 x(n) + a1 x(n-1) + a2 x(n-2).
- Parameters:
frequency – Center frequency in Hz
radius – Radius of filter. Refers to the unit circle, so it should be between 0.0 and (less than) 1.0.
kwargs – If frequency and radius not provided, these should be keyword arguments ‘a0’, ‘a1’, ‘a2’
- Returns:
two_zero gen
- Return type:
- two_zero(gen, insig)#
two zero filter of input.
- Parameters:
gen – two_zero gen
insig – input
- Return type:
float
- is_two_zero(gen)#
returns True if gen is a two_zero.
- Parameters:
gen – gen
- Return type:
bool
mus_xcoeff |
a0, a1, a2 in equations |
mus_ycoeff |
b1, b2 in equations |
mus_order |
1 or 2 (not setable) |
mus_scaler |
two_pole and two_zero radius |
mus_frequency |
two_pole and two_zero center frequency |
See also
wave_train#
- make_wave_train(frequency, wave=None, initial_phase=0.0, interp_type=Interp.LINEAR)#
return a new wave-train generator (an extension of pulse-train). frequency is the repetition rate of the wave found in wave. successive waves can overlap.
- Parameters:
frequency – frequency of gen in hz
wave – np.ndarray if provided is waveform
initial_phase – initial phase of gen in radians
interp_type – type of interpolation used
- Returns:
wave_train gen
- Return type:
- wave_train(gen, fm=0.0)#
next sample of wave_train.
- Parameters:
gen – wave_train gen
fm – fm input
- Return type:
float
- is_wave_train(gen)#
returns True if gen is a wave_train.
- Parameters:
gen – gen
- Return type:
bool
- make_wave_train_with_env(frequency, envelope, size=None)#
return a new wave-train generator with the envelope loaded in with size.
- Parameters:
frequency – frequency of gen in hz
env – envelope shape to load into generator
size – size of wave derived from envelope
- Returns:
wave_train gen
- Return type:
mus_frequency |
frequency in Hz |
mus_phase |
phase in radians |
mus_data |
wave array (not setable) |
mus_length |
length of wave array (not setable) |
mus_interp_type |
interpolation choice (not setable) |
Example usage
with Sound(play=True):
v = np.zeros(64, dtype=np.double)
g = make_ncos(400,10)
g.mus_phase = -.5 * math.pi
for i in range(64):
v[i] = ncos(g)
gen = make_wave_train(440, wave=v)
for i in range(44100):
outa(i, .5 * wave_train(gen))
See also