Skip to content
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

Issue #316 #463

Closed
wants to merge 14 commits into from
51 changes: 51 additions & 0 deletions pydub/scipy_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,54 @@ 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):
"""
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)
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
17 changes: 17 additions & 0 deletions pydub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,20 @@ def get_supported_decoders():

def get_supported_encoders():
return get_supported_codecs()[1]

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])
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])
pass