functions¶
ampdb(amp)
¶
Convert amplitude to decibels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amp
|
float
|
Amplitude value. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Decibel value. |
clip(val, min_val, max_val)
¶
Clip a value to be within a specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
float
|
The value to clip. |
required |
min_val
|
float
|
The minimum allowable value. |
required |
max_val
|
float
|
The maximum allowable value. |
required |
Returns:
| Type | Description |
|---|---|
float | int
|
The clipped value. |
coin(p)
¶
Return True with probability p, False otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of returning True (between 0 and 1). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True with probability p, False otherwise. |
cpsmidi(frequency)
¶
Convert frequency in Hz to MIDI note number
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
float
|
Frequency in Hz |
required |
Returns:
| Type | Description |
|---|---|
float
|
MIDI note number |
curvelin(value, in_min, in_max, out_min, out_max, curve=0)
¶
Curve-to-linear transform (inverse of lincurve).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform (from curved space) |
required |
in_min
|
float
|
Minimum of input range (curved) |
required |
in_max
|
float
|
Maximum of input range (curved) |
required |
out_min
|
float
|
Minimum of output range (linear) |
required |
out_max
|
float
|
Maximum of output range (linear) |
required |
curve
|
float
|
Curve parameter (-10 to 10 typical range) curve = 0: linear curve > 0: undoes exponential curve curve < 0: undoes logarithmic curve |
0
|
clip
|
If True, clamp input to [in_min, in_max] |
required |
Returns:
| Type | Description |
|---|---|
float
|
Linearized output value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If in_min equals in_max |
dbamp(db)
¶
Converts decibel values to amplitude.
amplitude = 10^(dB/20).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
Size of the SIMD vector. This parameter is inferred by the values passed to the function. |
required |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
float
|
The decibel values to convert. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The corresponding amplitude values. |
expexp(value, in_min, in_max, out_min, out_max)
¶
Exponential-to-exponential transform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform (exponential scale) |
required |
in_min
|
float
|
Minimum of input range (exponential) |
required |
in_max
|
float
|
Maximum of input range (exponential) |
required |
out_min
|
float
|
Minimum of output range (exponential) |
required |
out_max
|
float
|
Maximum of output range (exponential) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Exponentially scaled output value |
explin(value, in_min, in_max, out_min, out_max)
¶
Exponential-to-linear transform (inverse of linexp)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform (exponential scale) |
required |
in_min
|
float
|
Minimum of input range (exponential) |
required |
in_max
|
float
|
Maximum of input range (exponential) |
required |
out_min
|
float
|
Minimum of output range (linear) |
required |
out_max
|
float
|
Maximum of output range (linear) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Linearly scaled output value |
exprand(min_val, max_val)
¶
Generate a random value from an exponential distribution with given range. Will return an int if both min_val and max_val are ints, otherwise returns a float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
float
|
Minimum value. |
required |
max_val
|
float
|
Maximum value. |
required |
lincurve(value, in_min, in_max, out_min, out_max, curve=0)
¶
Linear-to-curve transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform |
required |
in_min
|
float
|
Minimum of input range (linear) |
required |
in_max
|
float
|
Maximum of input range (linear) |
required |
out_min
|
float
|
Minimum of output range |
required |
out_max
|
float
|
Maximum of output range |
required |
curve
|
float
|
Curve parameter (-10 to 10 typical range) curve = 0: linear curve > 0: exponential-like (slow start, steep end) curve < 0: logarithmic-like (steep start, slow end) |
0
|
clip
|
If True, clamp input to [in_min, in_max] |
required |
Returns:
| Type | Description |
|---|---|
float
|
Curved output value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If in_min equals in_max |
linexp(value, in_min, in_max, out_min, out_max)
¶
Linear-to-exponential transform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform |
required |
in_min
|
float
|
Minimum of input range (linear) |
required |
in_max
|
float
|
Maximum of input range (linear) |
required |
out_min
|
float
|
Minimum of output range (exponential) |
required |
out_max
|
float
|
Maximum of output range (exponential) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Exponentially scaled output value |
linlin(value, in_min, in_max, out_min, out_max)
¶
Linear-linear transform: map value from input range to output range
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Input value to transform |
required |
in_min
|
float
|
Minimum of input range |
required |
in_max
|
float
|
Maximum of input range |
required |
out_min
|
float
|
Minimum of output range |
required |
out_max
|
float
|
Maximum of output range |
required |
Returns:
| Type | Description |
|---|---|
float
|
Transformed value in output range |
midicps(midi_note)
¶
Convert MIDI note number to frequency in Hz
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
midi_note
|
float
|
MIDI note number |
required |
Returns:
| Type | Description |
|---|---|
float
|
Frequency in Hz |
mprint(*values, sep=' ', end='\n')
¶
print and return the valus(s) passed to the function.
polar_to_complex(mags, phases)
¶
Convert polar coordinates (magnitude and phase) to complex numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mags
|
ndarray
|
Magnitude spectrum (numpy array) |
required |
phases
|
ndarray
|
Phase spectrum (numpy array) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex_signal |
ndarray
|
Complex representation (numpy array) |
power_to_db(value, zero_db_ref=1.0, amin=1e-10)
¶
Convert a power value to decibels.
This mirrors librosa's power_to_db behavior for a single scalar: 10 * log10(max(amin, value) / zero_db_ref).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Power value to convert. |
required |
zero_db_ref
|
float
|
Reference power for 0 dB. |
1.0
|
amin
|
float
|
Minimum value to avoid log of zero. |
1e-10
|
Returns:
| Type | Description |
|---|---|
float
|
The value in decibels. |
rrand(min_val, max_val)
¶
Generate a random value between min_val and max_val. Will return an int if both min_val and max_val are ints, otherwise returns a float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
float
|
Minimum value. |
required |
max_val
|
float
|
Maximum value. |
required |
Returns: Random value between min_val and max_val.
swap(a, b)
¶
Swap the values of a and b, returning them in a tuple.