librosa.shepard_scale#

librosa.shepard_scale(frequency, *, sr=22050, length=None, duration=None, intervals='equal', n_steps=12, bins_per_octave=12, tuning=0.0, weighting='A')[source]#

Construct a discrete Shepard scale signal.

A Shepard scale is a sequence of discrete Shepard tones starting from frequency over the allotted duration.

Parameters:
frequencyfloat > 0 or str

Starting frequency of the scale (in Hz) or note name in SPN format (e.g., ‘C4’).

srnumber > 0

Desired sampling rate of the output signal.

lengthint > 0 or None

Desired number of samples in the output signal. When both duration and length are defined, length takes priority.

durationfloat > 0 or None

Desired duration in seconds. When both duration and length are defined, length takes priority.

intervalsstr or collection of floats

Interval specification or explicit ratio set. If a string is provided, it must be one supported by interval_frequencies (e.g. 'equal', 'pythagorean', 'ji3', 'ji5', 'ji7'). Default is 'equal'.

n_stepsint

The number of discrete pitch steps to generate over the duration. If negative, the scale is generated in descending order.

bins_per_octaveint > 0

Number of steps per octave when intervals is specified as a string.

tuningfloat

Deviation from A440 tuning in fractional bins. Only used when intervals='equal'.

weightingstr or None

Type of perceptual weighting to apply (e.g., 'A', 'B', 'C', 'D', 'Z'). If None, no weighting is applied.

Returns:
scale_signalnp.ndarray [shape=(length,), dtype=float64]

Synthesized discrete Shepard scale signal.

Examples

Generate a 12-step ascending Shepard scale starting at 110 Hz:

>>> y = librosa.shepard_scale(110.0, duration=2.0, n_steps=12)

Or starting from note C4:

>>> y_c4 = librosa.shepard_scale("C4", duration=2.0, n_steps=12)

Generate a 12-step descending Shepard scale starting at 110 Hz:

>>> y_desc = librosa.shepard_scale(110.0, duration=2.0, n_steps=-12)