Filter function __str__ added
MODIFY
.coveragerc
.coveragerc
@@ -8,3 +8,4 @@ exclude_lines =
except Exception:
vamp_imported = False
import sox
+ pass
\ No newline at end of file

MODIFY
nussl/core/effects.py
nussl/core/effects.py
@@ -35,8 +35,17 @@ from .utils import _close_temp_files
class FilterFunction:
"""
The FilterFunction class is an abstract class for functions that take
- audio processing streams, such as ffmpeg-python and pysndfx
+ audio processing streams, such as ffmpeg-python and pysox.
+
+ Don't call this class. It will not do anything.
"""
+ def __init__(self, _filter, **kwargs):
+ self.filter = _filter
+ self.params = kwargs
+
+ def __str__(self):
+ params = ",".join(f"{p}={v}" for p, v in self.params.items())
+ return f"{self.filter} with params {params}"
def __call__(self, stream):
return self.func(stream)
@@ -52,7 +61,7 @@ class FFmpegFilter(FilterFunction):
AudioSignal object.
"""
def __init__(self, _filter, **filter_kwargs):
- self.filter = _filter
+ super().__init__(_filter, **filter_kwargs)
self.func = lambda stream: stream.filter(_filter, **filter_kwargs)
@@ -98,8 +107,8 @@ def apply_effects_ffmpeg(audio_signal, filters, silent=False):
augmented_signal = AudioSignal(path_to_input_file=out_tempfile.name)
augmented_signal.label = audio_signal.label
- augmented_signal.effects_applied = (augmented_signal.effects_applied
- + [f.filter for f in filters])
+ augmented_signal.effects_applied = (audio_signal.effects_applied
+ + [str(f) for f in filters])
return augmented_signal
@@ -110,7 +119,7 @@ class SoXFilter(FilterFunction):
AudioSignal object.
"""
def __init__(self, _filter, **filter_kwargs):
- self.filter = _filter
+ super().__init__(_filter, **filter_kwargs)
if _filter == "time_stretch":
self.func = lambda tfm: tfm.tempo(**filter_kwargs)
elif _filter == "pitch_shift":
@@ -145,8 +154,8 @@ def apply_effects_sox(audio_signal, filters):
augmented_signal = AudioSignal(audio_data_array=np.transpose(augmented_data))
augmented_signal.label = audio_signal.label
- augmented_signal.effects_applied = (augmented_signal.effects_applied
- + [f.filter for f in filters])
+ augmented_signal.effects_applied = (audio_signal.effects_applied
+ + [str(f) for f in filters])
return augmented_signal

MODIFY
tests/core/test_effects.py
tests/core/test_effects.py
@@ -414,8 +414,3 @@ def test_make_effect(mix_and_sources, check_against_regression_data):
with pytest.raises(AudioSignalException):
signal.make_effect("fail")
-def test_filter_function_pass():
- # this test is for 100% coverage
- function = effects.FilterFunction()
- dummy_item = None
- function.func(dummy_item)

Filter function __str__ added