diff --git a/pyrubberband/pyrb.py b/pyrubberband/pyrb.py index 57597fb..b7879d3 100644 --- a/pyrubberband/pyrb.py +++ b/pyrubberband/pyrb.py @@ -19,7 +19,7 @@ import soundfile as sf -__all__ = ['time_stretch', 'pitch_shift', 'timemap_stretch'] +__all__ = ['time_stretch', 'pitch_shift', 'timemap_stretch', 'frequency_multiply', 'change_tempo'] __RUBBERBAND_UTIL = 'rubberband' @@ -255,3 +255,78 @@ def pitch_shift(y, sr, n_steps, rbargs=None): rbargs.setdefault('--pitch', n_steps) return __rubberband(y, sr, **rbargs) + + +def frequency_multiply(y, sr, X, rbargs=None): + '''Multiply the frequencies inside an audio time series. + The equivalent of the -f option. + Parameters + ---------- + y : np.ndarray [shape=(n,) or (n, c)] + Audio time series, either single or multichannel + + sr : int > 0 + Sampling rate of `y` + + X : float + Shift magnitudes in spectrum by X + + rbargs + Additional keyword parameters for rubberband + + See `rubberband -h` for details. + + Returns + ------- + y_shift : np.ndarray + frequency-multiplied audio + ''' + + if X == 0: + return y + + if rbargs is None: + rbargs = dict() + + rbargs.setdefault('--frequency', X) + + return __rubberband(y, sr, **rbargs) + + +def change_tempo(y, sr, X, Y, rbargs=None): + '''Multiply the frequencies inside an audio time series. + The equivalent of the --tempo : option. + Parameters + ---------- + y : np.ndarray [shape=(n,) or (n, c)] + Audio time series, either single or multichannel + + sr : int > 0 + Sampling rate of `y` + + X : float + Base tempo + + Y : float + Final tempo + + rbargs + Additional keyword parameters for rubberband + + See `rubberband -h` for details. + + Returns + ------- + y_shift : np.ndarray + tempo-shifted audio + ''' + + if X == 0: + return y + + if rbargs is None: + rbargs = dict() + + rbargs.setdefault('--tempo', '%s:%s' % (X, Y)) + + return __rubberband(y, sr, **rbargs)