From 406c20d227864f9009c5edea6ca111d0cba01edb Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Thu, 26 Mar 2020 10:42:38 +0530 Subject: [PATCH 01/15] Issue #316 Added a Equaliser Function --- pydub/effects.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pydub/effects.py b/pydub/effects.py index 0210521a..32d00fbf 100644 --- a/pydub/effects.py +++ b/pydub/effects.py @@ -339,3 +339,49 @@ def apply_gain_stereo(seg, left_gain=0.0, right_gain=0.0): return seg._spawn(data=output, overrides={'channels': 2, 'frame_width': 2 * seg.sample_width}) + +@register_pydub_effect +def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): + ''' + focus_freq - middle frequency or known frequency of band (in Hz) + bandwidth - range of the equalizer band + mode - Mode of Equalization(Peak/Notch,High Shelf, Low Shelf) + order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) + ''' + if gain_dB>=0: + if mode=="peak": + sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + if mode=="low_shelf": + sec=low_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + if mode=="high_shelf": + sec=high_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + pass + if gain_dB<0: + if mode=="peak": + sec=high_pass_filter(seg,focus_freq-bandwidth/2,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + sec=low_pass_filter(seg,focus_freq+bandwidth/2,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + if mode=="low_shelf": + sec=high_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + if mode=="high_shelf": + sec=low_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + pass + pass From fb1c94316c4f74ce4b2b7f4475a70a804c715f00 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 12:44:25 +0530 Subject: [PATCH 02/15] Update effects.py --- pydub/effects.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/pydub/effects.py b/pydub/effects.py index 32d00fbf..0210521a 100644 --- a/pydub/effects.py +++ b/pydub/effects.py @@ -339,49 +339,3 @@ def apply_gain_stereo(seg, left_gain=0.0, right_gain=0.0): return seg._spawn(data=output, overrides={'channels': 2, 'frame_width': 2 * seg.sample_width}) - -@register_pydub_effect -def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): - ''' - focus_freq - middle frequency or known frequency of band (in Hz) - bandwidth - range of the equalizer band - mode - Mode of Equalization(Peak/Notch,High Shelf, Low Shelf) - order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) - ''' - if gain_dB>=0: - if mode=="peak": - sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) - seg=seg.overlay(sec-(3-gain_dB)) - return seg - pass - if mode=="low_shelf": - sec=low_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3-gain_dB)) - return seg - pass - if mode=="high_shelf": - sec=high_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3-gain_dB)) - return seg - pass - pass - if gain_dB<0: - if mode=="peak": - sec=high_pass_filter(seg,focus_freq-bandwidth/2,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB - sec=low_pass_filter(seg,focus_freq+bandwidth/2,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB - return seg - pass - if mode=="low_shelf": - sec=high_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB - return seg - pass - if mode=="high_shelf": - sec=low_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB - return seg - pass - pass - pass From 697168923bfc2c75150be9e9c613988a11af8c24 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 12:47:17 +0530 Subject: [PATCH 03/15] Update scipy_effects.py Corrected the Exampled --- pydub/scipy_effects.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index 15975042..d5718a6c 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -62,3 +62,50 @@ def high_pass_filter(seg, cutoff_freq, order=5): def low_pass_filter(seg, cutoff_freq, order=5): filter_fn = _mk_butter_filter(cutoff_freq, 'lowpass', order=order) return seg.apply_mono_filter_to_each_channel(filter_fn) + + +@register_pydub_effect +def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): + ''' + focus_freq - middle frequency or known frequency of band (in Hz) + bandwidth - range of the equalizer band + mode - Mode of Equalization(Peak/Notch,High Shelf, Low Shelf) + order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) + ''' + if gain_dB>=0: + if mode=="peak": + sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + if mode=="low_shelf": + sec=low_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + if mode=="high_shelf": + sec=high_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3-gain_dB)) + return seg + pass + pass + if gain_dB<0: + if mode=="peak": + sec=high_pass_filter(seg,focus_freq-bandwidth/2,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + sec=low_pass_filter(seg,focus_freq+bandwidth/2,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + if mode=="low_shelf": + sec=high_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + if mode=="high_shelf": + sec=low_pass_filter(seg,focus_freq,order=order) + seg=seg.overlay(sec-(3+gain_dB))+gain_dB + return seg + pass + pass + pass From eea265d6885877a08e36beb92cf720f8655110ee Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 15:49:49 +0530 Subject: [PATCH 04/15] Added Mid-Side and Reverse Conversion --- pydub/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pydub/utils.py b/pydub/utils.py index 448d65fd..295aa9ab 100644 --- a/pydub/utils.py +++ b/pydub/utils.py @@ -415,3 +415,20 @@ def get_supported_decoders(): def get_supported_encoders(): return get_supported_codecs()[1] + +def stereo_to_ms(seg): + ''' + Left-Right -> Mid-Side + ''' + channel = seg.split_to_mono() + channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] + return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + pass +def ms_to_stereo(seg): + ''' + Mid-Side -> Left-Right + ''' + channel = seg.split_to_mono() + channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] + return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + pass From 68d1f7c5afef0cc3d158dfebae14fb56390606ca Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 15:57:10 +0530 Subject: [PATCH 05/15] Update README.markdown --- README.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.markdown b/README.markdown index cd7584dd..e70de11b 100644 --- a/README.markdown +++ b/README.markdown @@ -65,6 +65,15 @@ Concatenate audio (add one file to the end of another) without_the_middle = beginning + end ``` +Convert it Mid-Side form +```python +song=stereo_to_ms(song) +``` +Or get it back to normal +```python +song=ms_to_stereo(song) +``` + How long is it? ```python From 0d138666f4c40aca8a7a2ec1dd5a09f18b909251 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 21:24:22 +0530 Subject: [PATCH 06/15] Update README.markdown --- README.markdown | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.markdown b/README.markdown index e70de11b..cd7584dd 100644 --- a/README.markdown +++ b/README.markdown @@ -65,15 +65,6 @@ Concatenate audio (add one file to the end of another) without_the_middle = beginning + end ``` -Convert it Mid-Side form -```python -song=stereo_to_ms(song) -``` -Or get it back to normal -```python -song=ms_to_stereo(song) -``` - How long is it? ```python From bb5faf5c75134646d72f8a28f1c626a310662073 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 21:26:20 +0530 Subject: [PATCH 07/15] Update utils.py --- pydub/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pydub/utils.py b/pydub/utils.py index 295aa9ab..10949390 100644 --- a/pydub/utils.py +++ b/pydub/utils.py @@ -416,19 +416,19 @@ def get_supported_decoders(): def get_supported_encoders(): return get_supported_codecs()[1] -def stereo_to_ms(seg): +def stereo_to_ms(audio_segment): ''' Left-Right -> Mid-Side ''' - channel = seg.split_to_mono() + channel = audio_segment.split_to_mono() channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) pass -def ms_to_stereo(seg): +def ms_to_stereo(audio_segment): ''' Mid-Side -> Left-Right ''' - channel = seg.split_to_mono() + channel = audio_segment.split_to_mono() channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) pass From 8909412f0c5b5b4ca0042d715e32ab3200fea343 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Fri, 27 Mar 2020 21:42:37 +0530 Subject: [PATCH 08/15] Update utils.py Breathe in Bug out --- pydub/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pydub/utils.py b/pydub/utils.py index 10949390..4f904203 100644 --- a/pydub/utils.py +++ b/pydub/utils.py @@ -420,15 +420,15 @@ def stereo_to_ms(audio_segment): ''' Left-Right -> Mid-Side ''' - channel = audio_segment.split_to_mono() - channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] - return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + channel = audio_segment.split_to_mono() + channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] + return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) pass def ms_to_stereo(audio_segment): ''' Mid-Side -> Left-Right ''' - channel = audio_segment.split_to_mono() - channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] - return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + channel = audio_segment.split_to_mono() + channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] + return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) pass From fe1dbeaf372387df194a51b1a3cdb18c1580e223 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Wed, 20 May 2020 12:24:24 +0530 Subject: [PATCH 09/15] Update Documentation for eq() --- pydub/scipy_effects.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index d5718a6c..f10ce34d 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -66,12 +66,16 @@ def low_pass_filter(seg, cutoff_freq, order=5): @register_pydub_effect def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): - ''' - focus_freq - middle frequency or known frequency of band (in Hz) - bandwidth - range of the equalizer band - mode - Mode of Equalization(Peak/Notch,High Shelf, Low Shelf) - order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) - ''' + """ + Args: + focus_freq - middle frequency or known frequency of band (in Hz) + bandwidth - range of the equalizer band + mode - Mode of Equalization(Peak/Notch(Bell Curve),High Shelf, Low Shelf) + order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) + + Returns: + Equalized/Filtered AudioSegment + """ if gain_dB>=0: if mode=="peak": sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) From 1b98b784c52d3fd5996542e398dccb27fe52f8e5 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Mon, 15 Jun 2020 09:20:10 +0530 Subject: [PATCH 10/15] New eq function Updated eq function with channel independent mode and some error handling. Not Tested Thoroughly. --- pydub/scipy_effects.py | 59 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index f10ce34d..834af26f 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -10,7 +10,7 @@ provided by pydub.effects. """ from scipy.signal import butter, sosfilt -from .utils import register_pydub_effect +from .utils import (register_pydub_effect,stereo_to_ms,ms_to_stereo) def _mk_butter_filter(freq, type, order): @@ -65,7 +65,7 @@ def low_pass_filter(seg, cutoff_freq, order=5): @register_pydub_effect -def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): +def _eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): """ Args: focus_freq - middle frequency or known frequency of band (in Hz) @@ -76,6 +76,10 @@ def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): Returns: Equalized/Filtered AudioSegment """ + filt_mode=["peak","low_shelf","high_shelf"] + if mode not in filt_mode: + raise ValueError("Incorrect Mode Selection") + pass if gain_dB>=0: if mode=="peak": sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) @@ -113,3 +117,54 @@ def eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): pass pass pass + +@register_pydub_effect +def eq(seg,focus_freq,bandwidth=100,channel_mode="L+R",filter_mode="peak",gain_dB=0,order=2): + """ + Args: + focus_freq - middle frequency or known frequency of band (in Hz) + bandwidth - range of the equalizer band + filter_mode - Mode of Equalization(Peak/Notch(Bell Curve),High Shelf, Low Shelf) + order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) + + Returns: + Equalized/Filtered AudioSegment + """ + filt_mode=["L+R","M+S","L","R","M","S"] + if mode not in filt_mode: + raise ValueError("Incorrect Channel Mode Selection") + pass + if seg.channels==1: + return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + pass + if channel_mode=="L+R": + return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + pass + if channel_mode=="L": + seg=seg.split_to_mono() + seg=[_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] + return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + pass + if channel_mode=="R": + seg=seg.split_to_mono() + seg=[seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] + return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + pass + if channel_mode=="M+S": + seg=stereo_to_ms(seg) + seg=_eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + return ms_to_stereo(seg) + pass + if channel_mode=="M": + seg=stereo_to_ms(seg) + seg=[_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] + seg=AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + return ms_to_stereo(seg) + pass + if channel_mode=="S": + seg=stereo_to_ms(seg) + seg=[seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] + seg=AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + return ms_to_stereo(seg) + pass + pass From 94696759b1830c090d3fedf4af3041c3eabea55b Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Tue, 16 Jun 2020 20:15:30 +0530 Subject: [PATCH 11/15] Cleaning --- pydub/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydub/utils.py b/pydub/utils.py index 4f904203..15d06bba 100644 --- a/pydub/utils.py +++ b/pydub/utils.py @@ -423,7 +423,7 @@ def stereo_to_ms(audio_segment): channel = audio_segment.split_to_mono() channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) - pass + def ms_to_stereo(audio_segment): ''' Mid-Side -> Left-Right @@ -431,4 +431,4 @@ def ms_to_stereo(audio_segment): channel = audio_segment.split_to_mono() channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) - pass + From c92a2c460689670c39b6e95226392adf381d6b93 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Tue, 16 Jun 2020 20:31:51 +0530 Subject: [PATCH 12/15] Cleaned --- pydub/scipy_effects.py | 127 +++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index 834af26f..7ba4a6da 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -65,7 +65,7 @@ def low_pass_filter(seg, cutoff_freq, order=5): @register_pydub_effect -def _eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): +def _eq(seg, focus_freq, bandwidth=100, mode="peak", gain_dB=0, order=2): """ Args: focus_freq - middle frequency or known frequency of band (in Hz) @@ -76,95 +76,100 @@ def _eq(seg,focus_freq,bandwidth=100,mode="peak",gain_dB=0,order=2): Returns: Equalized/Filtered AudioSegment """ - filt_mode=["peak","low_shelf","high_shelf"] + filt_mode = ["peak","low_shelf","high_shelf"] if mode not in filt_mode: raise ValueError("Incorrect Mode Selection") - pass - if gain_dB>=0: - if mode=="peak": - sec=band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) - seg=seg.overlay(sec-(3-gain_dB)) + + if gain_dB >= 0: + if mode == "peak": + sec = band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) + seg = seg.overlay(sec-(3-gain_dB)) return seg - pass - if mode=="low_shelf": - sec=low_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3-gain_dB)) + + if mode == "low_shelf": + sec = low_pass_filter(seg,focus_freq,order=order) + seg = seg.overlay(sec-(3-gain_dB)) return seg - pass - if mode=="high_shelf": - sec=high_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3-gain_dB)) + + if mode == "high_shelf": + sec = high_pass_filter(seg,focus_freq,order=order) + seg = seg.overlay(sec-(3-gain_dB)) return seg - pass - pass - if gain_dB<0: - if mode=="peak": - sec=high_pass_filter(seg,focus_freq-bandwidth/2,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB - sec=low_pass_filter(seg,focus_freq+bandwidth/2,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB + + if gain_dB < 0: + if mode == "peak": + sec = high_pass_filter(seg,focus_freq-bandwidth/2,order=order) + seg = seg.overlay(sec-(3+gain_dB))+gain_dB + sec = low_pass_filter(seg,focus_freq+bandwidth/2,order=order) + seg = seg.overlay(sec-(3+gain_dB))+gain_dB return seg - pass - if mode=="low_shelf": - sec=high_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB + + if mode == "low_shelf": + sec = high_pass_filter(seg,focus_freq,order=order) + seg = seg.overlay(sec-(3+gain_dB))+gain_dB return seg - pass + if mode=="high_shelf": sec=low_pass_filter(seg,focus_freq,order=order) seg=seg.overlay(sec-(3+gain_dB))+gain_dB return seg - pass - pass - pass + @register_pydub_effect -def eq(seg,focus_freq,bandwidth=100,channel_mode="L+R",filter_mode="peak",gain_dB=0,order=2): +def eq(seg, focus_freq, bandwidth=100, channel_mode="L+R", filter_mode="peak", gain_dB=0, order=2): """ Args: focus_freq - middle frequency or known frequency of band (in Hz) bandwidth - range of the equalizer band + channel_mode - Select Channels to be affected by the filter. + L+R - Standard Stereo Filter + L - Only Left Channel is Filtered + R - Only Right Channel is Filtered + M+S - Blumlien Stereo Filter(Mid-Side) + M - Only Mid Channel is Filtered + S - Only Side Channel is Filtered + Mono Audio Segments are completely Filtered. filter_mode - Mode of Equalization(Peak/Notch(Bell Curve),High Shelf, Low Shelf) order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) Returns: Equalized/Filtered AudioSegment """ - filt_mode=["L+R","M+S","L","R","M","S"] + filt_mode = ["L+R","M+S","L","R","M","S"] if mode not in filt_mode: raise ValueError("Incorrect Channel Mode Selection") - pass - if seg.channels==1: + + if seg.channels == 1: return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) - pass - if channel_mode=="L+R": + + if channel_mode == "L+R": return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) - pass - if channel_mode=="L": - seg=seg.split_to_mono() - seg=[_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] + + if channel_mode == "L": + seg = seg.split_to_mono() + seg = [_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) - pass - if channel_mode=="R": - seg=seg.split_to_mono() - seg=[seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] + + if channel_mode == "R": + seg = seg.split_to_mono() + seg = [seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) - pass - if channel_mode=="M+S": - seg=stereo_to_ms(seg) - seg=_eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + + if channel_mode == "M+S": + seg = stereo_to_ms(seg) + seg = _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) return ms_to_stereo(seg) - pass - if channel_mode=="M": - seg=stereo_to_ms(seg) - seg=[_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] - seg=AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + + if channel_mode == "M": + seg = stereo_to_ms(seg).split_to_mono() + seg = [_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] + seg = AudioSegment.from_mono_audio_segements(seg[0],seg[1]) return ms_to_stereo(seg) - pass - if channel_mode=="S": - seg=stereo_to_ms(seg) - seg=[seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] - seg=AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + + if channel_mode == "S": + seg = stereo_to_ms(seg).split_to_mono() + seg = [seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] + seg = AudioSegment.from_mono_audio_segements(seg[0],seg[1]) return ms_to_stereo(seg) - pass - pass + + From cf8438bb6ea2184b71e57390015165a2017ac5f5 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Tue, 16 Jun 2020 20:35:38 +0530 Subject: [PATCH 13/15] Update scipy_effects.py --- pydub/scipy_effects.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index 7ba4a6da..ce7248dd 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -76,7 +76,7 @@ def _eq(seg, focus_freq, bandwidth=100, mode="peak", gain_dB=0, order=2): Returns: Equalized/Filtered AudioSegment """ - filt_mode = ["peak","low_shelf","high_shelf"] + filt_mode = ["peak", "low_shelf", "high_shelf"] if mode not in filt_mode: raise ValueError("Incorrect Mode Selection") @@ -128,14 +128,14 @@ def eq(seg, focus_freq, bandwidth=100, channel_mode="L+R", filter_mode="peak", g M+S - Blumlien Stereo Filter(Mid-Side) M - Only Mid Channel is Filtered S - Only Side Channel is Filtered - Mono Audio Segments are completely Filtered. + Mono Audio Segments are completely filtered. filter_mode - Mode of Equalization(Peak/Notch(Bell Curve),High Shelf, Low Shelf) order - Rolloff factor(1 - 6dB/Octave 2 - 12dB/Octave) Returns: Equalized/Filtered AudioSegment """ - filt_mode = ["L+R","M+S","L","R","M","S"] + filt_mode = ["L+R", "M+S", "L", "R", "M", "S"] if mode not in filt_mode: raise ValueError("Incorrect Channel Mode Selection") From 28a04c01093840c93dda879b06cab1c89e95f1d8 Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Tue, 16 Jun 2020 20:41:45 +0530 Subject: [PATCH 14/15] Update utils.py --- pydub/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pydub/utils.py b/pydub/utils.py index 15d06bba..740c5002 100644 --- a/pydub/utils.py +++ b/pydub/utils.py @@ -421,14 +421,14 @@ def stereo_to_ms(audio_segment): Left-Right -> Mid-Side ''' channel = audio_segment.split_to_mono() - channel = [channel[0].overlay(channel[1]),channel[0].overlay(channel[1].invert_phase())] - return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + channel = [channel[0].overlay(channel[1]), channel[0].overlay(channel[1].invert_phase())] + return AudioSegment.from_mono_audiosegments(channel[0], channel[1]) def ms_to_stereo(audio_segment): ''' Mid-Side -> Left-Right ''' channel = audio_segment.split_to_mono() - channel = [channel[0].overlay(channel[1])-3,channel[0].overlay(channel[1].invert_phase())-3] - return AudioSegment.from_mono_audiosegments(channel[0],channel[1]) + channel = [channel[0].overlay(channel[1]) - 3, channel[0].overlay(channel[1].invert_phase()) - 3] + return AudioSegment.from_mono_audiosegments(channel[0], channel[1]) From 682b20ea5daf4d0474c3531f6c4dcb8a364317bc Mon Sep 17 00:00:00 2001 From: Anubhav Mattoo <52947138+anubhav-narayan@users.noreply.github.com> Date: Tue, 16 Jun 2020 20:48:34 +0530 Subject: [PATCH 15/15] Cleaning MS Filter Bug Removed --- pydub/scipy_effects.py | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/pydub/scipy_effects.py b/pydub/scipy_effects.py index ce7248dd..177c4ff1 100644 --- a/pydub/scipy_effects.py +++ b/pydub/scipy_effects.py @@ -82,36 +82,36 @@ def _eq(seg, focus_freq, bandwidth=100, mode="peak", gain_dB=0, order=2): if gain_dB >= 0: if mode == "peak": - sec = band_pass_filter(seg,focus_freq-bandwidth/2,focus_freq+bandwidth/2,order=order) - seg = seg.overlay(sec-(3-gain_dB)) + sec = band_pass_filter(seg, focus_freq - bandwidth/2, focus_freq + bandwidth/2, order = order) + seg = seg.overlay(sec - (3 - gain_dB)) return seg if mode == "low_shelf": - sec = low_pass_filter(seg,focus_freq,order=order) - seg = seg.overlay(sec-(3-gain_dB)) + sec = low_pass_filter(seg, focus_freq, order=order) + seg = seg.overlay(sec - (3 - gain_dB)) return seg if mode == "high_shelf": - sec = high_pass_filter(seg,focus_freq,order=order) - seg = seg.overlay(sec-(3-gain_dB)) + sec = high_pass_filter(seg, focus_freq, order=order) + seg = seg.overlay(sec - (3 - gain_dB)) return seg if gain_dB < 0: if mode == "peak": - sec = high_pass_filter(seg,focus_freq-bandwidth/2,order=order) - seg = seg.overlay(sec-(3+gain_dB))+gain_dB - sec = low_pass_filter(seg,focus_freq+bandwidth/2,order=order) - seg = seg.overlay(sec-(3+gain_dB))+gain_dB + sec = high_pass_filter(seg, focus_freq - bandwidth/2, order=order) + seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB + sec = low_pass_filter(seg, focus_freq + bandwidth/2, order=order) + seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB return seg if mode == "low_shelf": - sec = high_pass_filter(seg,focus_freq,order=order) - seg = seg.overlay(sec-(3+gain_dB))+gain_dB + sec = high_pass_filter(seg, focus_freq, order=order) + seg = seg.overlay(sec - (3 + gain_dB)) + gain_dB return seg if mode=="high_shelf": - sec=low_pass_filter(seg,focus_freq,order=order) - seg=seg.overlay(sec-(3+gain_dB))+gain_dB + sec=low_pass_filter(seg, focus_freq, order=order) + seg=seg.overlay(sec - (3 + gain_dB)) +gain_dB return seg @@ -140,36 +140,36 @@ def eq(seg, focus_freq, bandwidth=100, channel_mode="L+R", filter_mode="peak", g raise ValueError("Incorrect Channel Mode Selection") if seg.channels == 1: - return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + return _eq(seg, focus_freq, bandwidth, filter_mode, gain_dB, order) if channel_mode == "L+R": - return _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + return _eq(seg, focus_freq, bandwidth, filter_mode, gain_dB, order) if channel_mode == "L": seg = seg.split_to_mono() - seg = [_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] - return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + seg = [_eq(seg[0], focus_freq, bandwidth, filter_mode, gain_dB, order), seg[1]] + return AudioSegment.from_mono_audio_segements(seg[0], seg[1]) if channel_mode == "R": seg = seg.split_to_mono() - seg = [seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] - return AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + seg = [seg[0], _eq(seg[1], focus_freq, bandwidth, filter_mode, gain_dB, order)] + return AudioSegment.from_mono_audio_segements(seg[0], seg[1]) if channel_mode == "M+S": seg = stereo_to_ms(seg) - seg = _eq(seg,focus_freq,bandwidth,filter_mode,gain_dB,order) + seg = _eq(seg, focus_freq, bandwidth, filter_mode, gain_dB, order) return ms_to_stereo(seg) if channel_mode == "M": seg = stereo_to_ms(seg).split_to_mono() - seg = [_eq(seg[0],focus_freq,bandwidth,filter_mode,gain_dB,order),seg[1]] - seg = AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + seg = [_eq(seg[0], focus_freq, bandwidth, filter_mode, gain_dB, order), seg[1]] + seg = AudioSegment.from_mono_audio_segements(seg[0], seg[1]) return ms_to_stereo(seg) if channel_mode == "S": seg = stereo_to_ms(seg).split_to_mono() - seg = [seg[0],_eq(seg[1],focus_freq,bandwidth,filter_mode,gain_dB,order)] - seg = AudioSegment.from_mono_audio_segements(seg[0],seg[1]) + seg = [seg[0], _eq(seg[1], focus_freq, bandwidth, filter_mode, gain_dB, order)] + seg = AudioSegment.from_mono_audio_segements(seg[0], seg[1]) return ms_to_stereo(seg)