-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some functions added #19
base: main
Are you sure you want to change the base?
Changes from all commits
c19a580
e0a8e89
1d7c63a
39b4789
f2f555b
1db66d3
c162fd6
4c3967e
b101c59
65c1410
60c7152
36e07c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this different from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not, it just saves the step of creating the coefficient between the two tempos. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, i get it now. Thanks. LGTM |
||
'''Multiply the frequencies inside an audio time series. | ||
The equivalent of the --tempo <X>:<Y> 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add unit tests for this new functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me take a look at how do they work! For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this parameter have a more descriptive name?
X
doesn't convey much here, maybefactor
orshift
would be more appropriate.The description of this parameter (and the function docstring itself) is also a bit confusing. I assume this means that energy at frequency
f
maps to frequencyf*factor
? I think it would be best to be explicit about what the exact calculation is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree,
factor
seems a better name.The
rubberband-cli
documentation just saysChange frequency by multiple X
. I was looking in therubberband
repository, and I guess by this line that this doesf*factor
. I think we could safely describe this parameter as you said.