python_utils¶
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
|
The clipped value. |
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 |
exprand(min_val, max_val)
¶
Generate a random float from an exponential distribution with given lambda.
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 curve = 0: linear curve > 0: exponential-like (steep at end) curve < 0: logarithmic-like (steep at start) |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Curved output value |
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 |
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) |
rrand(min_val, max_val)
¶
Generate a random float between min_val and max_val.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
float
|
Minimum value. |
required |
max_val
|
float
|
Maximum value. |
required |
Returns: Random float between min_val and max_val.