

@cache
def clicks(times=None, frames=None, sr=22050, hop_length=512, click_freq=1000.0, click_duration=0.1, click=None, length=None):
    'Returns a signal with the signal `click` placed at each specified time\n\n    Parameters\n    ----------\n    times : np.ndarray or None\n        times to place clicks, in seconds\n\n    frames : np.ndarray or None\n        frame indices to place clicks\n\n    sr : number > 0\n        desired sampling rate of the output signal\n\n    hop_length : int > 0\n        if positions are specified by `frames`, the number of samples between frames.\n\n    click_freq : float > 0\n        frequency (in Hz) of the default click signal.  Default is 1KHz.\n\n    click_duration : float > 0\n        duration (in seconds) of the default click signal.  Default is 100ms.\n\n    click : np.ndarray or None\n        optional click signal sample to use instead of the default blip.\n\n    length : int > 0\n        desired number of samples in the output signal\n\n\n    Returns\n    -------\n    click_signal : np.ndarray\n        Synthesized click signal\n\n\n    Raises\n    ------\n    ParameterError\n        - If neither `times` nor `frames` are provided.\n        - If any of `click_freq`, `click_duration`, or `length` are out of range.\n\n\n    Examples\n    --------\n    >>> # Sonify detected beat events\n    >>> y, sr = librosa.load(librosa.util.example_audio_file())\n    >>> tempo, beats = librosa.beat.beat_track(y=y, sr=sr)\n    >>> y_beats = librosa.clicks(frames=beats, sr=sr)\n\n    >>> # Or generate a signal of the same length as y\n    >>> y_beats = librosa.clicks(frames=beats, sr=sr, length=len(y))\n\n    >>> # Or use timing instead of frame indices\n    >>> times = librosa.frames_to_time(beats, sr=sr)\n    >>> y_beat_times = librosa.clicks(times=times, sr=sr)\n\n    >>> # Or with a click frequency of 880Hz and a 500ms sample\n    >>> y_beat_times880 = librosa.clicks(times=times, sr=sr,\n    ...                                  click_freq=880, click_duration=0.5)\n    '
    if (times is None):
        if (frames is None):
            raise ParameterError('either "times" or "frames" must be provided')
        positions = frames_to_samples(frames, hop_length=hop_length)
    else:
        positions = time_to_samples(times, sr=sr)
    if (click is not None):
        util.valid_audio(click, mono=True)
    else:
        if (click_duration <= 0):
            raise ParameterError('click_duration must be strictly positive')
        if (click_freq <= 0):
            raise ParameterError('click_freq must be strictly positive')
        angular_freq = (((2 * np.pi) * click_freq) / float(sr))
        click = np.logspace(0, (- 10), num=int(np.round((sr * click_duration))), base=2.0)
        click *= np.sin((angular_freq * np.arange(len(click))))
    if (length is None):
        length = (positions.max() + sr.shape[0])
    else:
        if (length < 1):
            raise ParameterError('length must be a positive integer')
        positions = positions[(positions < length)]
    click_signal = np.zeros(length, dtype=np.float32)
    for start in positions:
        end = (start + click.shape[0])
        if (end >= length):
            click_signal[start:] += click[:(length - start)]
        else:
            click_signal[start:end] += click
    return click_signal

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py clicks/VarMisuse@251/1124 `click`->`sr`