Skip to content

Commit f262444

Browse files
Add simple 3 band equalizer node for audio. (Comfy-Org#12519)
1 parent 239ddd3 commit f262444

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

comfy_extras/nodes_audio.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,67 @@ def execute(cls, duration, sample_rate, channels) -> IO.NodeOutput:
698698
create_empty_audio = execute # TODO: remove
699699

700700

701+
class AudioEqualizer3Band(IO.ComfyNode):
702+
@classmethod
703+
def define_schema(cls):
704+
return IO.Schema(
705+
node_id="AudioEqualizer3Band",
706+
search_aliases=["eq", "bass boost", "treble boost", "equalizer"],
707+
display_name="Audio Equalizer (3-Band)",
708+
category="audio",
709+
is_experimental=True,
710+
inputs=[
711+
IO.Audio.Input("audio"),
712+
IO.Float.Input("low_gain_dB", default=0.0, min=-24.0, max=24.0, step=0.1, tooltip="Gain for Low frequencies (Bass)"),
713+
IO.Int.Input("low_freq", default=100, min=20, max=500, tooltip="Cutoff frequency for Low shelf"),
714+
IO.Float.Input("mid_gain_dB", default=0.0, min=-24.0, max=24.0, step=0.1, tooltip="Gain for Mid frequencies"),
715+
IO.Int.Input("mid_freq", default=1000, min=200, max=4000, tooltip="Center frequency for Mids"),
716+
IO.Float.Input("mid_q", default=0.707, min=0.1, max=10.0, step=0.1, tooltip="Q factor (bandwidth) for Mids"),
717+
IO.Float.Input("high_gain_dB", default=0.0, min=-24.0, max=24.0, step=0.1, tooltip="Gain for High frequencies (Treble)"),
718+
IO.Int.Input("high_freq", default=5000, min=1000, max=15000, tooltip="Cutoff frequency for High shelf"),
719+
],
720+
outputs=[IO.Audio.Output()],
721+
)
722+
723+
@classmethod
724+
def execute(cls, audio, low_gain_dB, low_freq, mid_gain_dB, mid_freq, mid_q, high_gain_dB, high_freq) -> IO.NodeOutput:
725+
waveform = audio["waveform"]
726+
sample_rate = audio["sample_rate"]
727+
eq_waveform = waveform.clone()
728+
729+
# 1. Apply Low Shelf (Bass)
730+
if low_gain_dB != 0:
731+
eq_waveform = torchaudio.functional.bass_biquad(
732+
eq_waveform,
733+
sample_rate,
734+
gain=low_gain_dB,
735+
central_freq=float(low_freq),
736+
Q=0.707
737+
)
738+
739+
# 2. Apply Peaking EQ (Mids)
740+
if mid_gain_dB != 0:
741+
eq_waveform = torchaudio.functional.equalizer_biquad(
742+
eq_waveform,
743+
sample_rate,
744+
center_freq=float(mid_freq),
745+
gain=mid_gain_dB,
746+
Q=mid_q
747+
)
748+
749+
# 3. Apply High Shelf (Treble)
750+
if high_gain_dB != 0:
751+
eq_waveform = torchaudio.functional.treble_biquad(
752+
eq_waveform,
753+
sample_rate,
754+
gain=high_gain_dB,
755+
central_freq=float(high_freq),
756+
Q=0.707
757+
)
758+
759+
return IO.NodeOutput({"waveform": eq_waveform, "sample_rate": sample_rate})
760+
761+
701762
class AudioExtension(ComfyExtension):
702763
@override
703764
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
@@ -720,6 +781,7 @@ async def get_node_list(self) -> list[type[IO.ComfyNode]]:
720781
AudioMerge,
721782
AudioAdjustVolume,
722783
EmptyAudio,
784+
AudioEqualizer3Band,
723785
]
724786

725787
async def comfy_entrypoint() -> AudioExtension:

0 commit comments

Comments
 (0)