From b786966a25a12ec74073e1eb9e0089056513c618 Mon Sep 17 00:00:00 2001 From: Scott Hawley Date: Sat, 28 Apr 2018 22:54:26 -0500 Subject: [PATCH 1/2] first attempt at adding ladspa method --- sox/transform.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/sox/transform.py b/sox/transform.py index 3dd9a1c..14e6678 100644 --- a/sox/transform.py +++ b/sox/transform.py @@ -1662,6 +1662,39 @@ def hilbert(self, num_taps=None): return self + + def ladspa(self, name=''; params='', ladspa_path='/usr/lib/ladspa/'): + '''Applies a LADSPA plugin. + + Parameters + ---------- + name : string, default = '' + The name of the LADSPA plugin file, e.g. 'mbeq_1197'. + This will get ladspa_path prepended to it, and '.so' appended. + params: string: default + String of parameters to send to the LADSPA plugin via sox. + + + ''' + if not is_str(name): + raise ValueError('name must be a string.') + + if not is_str(params): + raise ValueError('params must be a string') + + + effect_args = [ + 'ladspa', + name, + params + ] + self.effects.extend(effect_args) + self.effects_log.append('ladspa') + + return self + + + def loudness(self, gain_db=-10.0, reference_level=65.0): '''Loudness control. Similar to the gain effect, but provides equalisation for the human auditory system. @@ -1883,12 +1916,12 @@ def noiseprof(self, input_filepath, profile_path): ''' if os.path.isdir(profile_path): raise ValueError("profile_path {} is a directory, but filename should be specified.") - + if os.path.dirname(profile_path) == '' and profile_path != '': _abs_profile_path = os.path.join(os.getcwd(), profile_path) else: _abs_profile_path = profile_path - + if not os.access(os.path.dirname(_abs_profile_path), os.W_OK): raise IOError("profile_path {} is not writeable.".format(_abs_profile_path)) From 7ec95435c1d279fb7fd2fcda9d82da6365482e71 Mon Sep 17 00:00:00 2001 From: Scott Hawley Date: Sat, 28 Apr 2018 23:23:57 -0500 Subject: [PATCH 2/2] added basic LADSPA plugin support via param string --- sox/transform.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sox/transform.py b/sox/transform.py index 14e6678..04e5611 100644 --- a/sox/transform.py +++ b/sox/transform.py @@ -1663,8 +1663,10 @@ def hilbert(self, num_taps=None): return self - def ladspa(self, name=''; params='', ladspa_path='/usr/lib/ladspa/'): - '''Applies a LADSPA plugin. + def ladspa(self, name='', params='', ladspa_path='/usr/lib/ladspa/'): + '''Sox supports the Linux Audio Developer's Simple Plugin API (LADSPA) standard + and will call plugins via the sox -ladspa command-line option. This + module simply passess the string name of a module and a list of parameters as a string Parameters ---------- @@ -1674,18 +1676,24 @@ def ladspa(self, name=''; params='', ladspa_path='/usr/lib/ladspa/'): params: string: default String of parameters to send to the LADSPA plugin via sox. + Example: For one of Steve Harris' compressors (sudo apt-get install swh-plugins) + tfm.ladspa('mbeq_1197','mbeq -2 -3 -3 -6 -9 -9 -10 -8 -6 -5 -4 -3 -1 0 0 0') ''' - if not is_str(name): + if not isinstance(name, str): raise ValueError('name must be a string.') - if not is_str(params): + if not isinstance(params, str): raise ValueError('params must be a string') + full_name = ladspa_path + name + '.so' + + if not os.path.isfile(full_name): + raise IOError('LADSPA plugin file not found at '+full_name) effect_args = [ 'ladspa', - name, + ladspa_path + name + '.so', params ] self.effects.extend(effect_args)