yoyolicoris commited on
Commit
6e962e9
·
1 Parent(s): f2a0080

feat: add tone correction PEQ sliders

Browse files
Files changed (1) hide show
  1. app.py +115 -6
app.py CHANGED
@@ -10,6 +10,7 @@ import pyloudnorm as pyln
10
  from hydra.utils import instantiate
11
  from soxr import resample
12
  from functools import partial, reduce
 
13
  from torchcomp import coef2ms, ms2coef
14
  from copy import deepcopy
15
 
@@ -626,6 +627,7 @@ with gr.Blocks() as demo:
626
  plot_delay(fx), label="Delay Frequency Response", elem_id="delay-plot"
627
  )
628
 
 
629
  with gr.Row():
630
  reverb_plot = gr.Plot(
631
  plot_reverb(fx),
@@ -637,6 +639,54 @@ with gr.Blocks() as demo:
637
  plot_t60(fx), label="Reverb T60", elem_id="t60-plot", min_width=160
638
  )
639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
  with gr.Row():
641
  json_output = gr.JSON(
642
  model2json(fx), label="Effect Settings", max_height=800, open=True
@@ -705,14 +755,38 @@ with gr.Blocks() as demo:
705
  ]
706
  delay_update_plot_flag = [True] * 4 + [False] * 2
707
 
708
- all_effect_sliders = peq_sliders + cmp_sliders + delay_sliders + [reverb_send]
709
- split_sizes = [len(peq_sliders), len(cmp_sliders), len(delay_sliders), 1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
710
 
711
  def assign_fx_params(fx, *args):
712
- peq_sliders, cmp_sliders, delay_sliders = (
713
- args[: split_sizes[0]],
714
- args[split_sizes[0] : sum(split_sizes[:2])],
715
- args[sum(split_sizes[:2]) : -1],
716
  )
717
  reverb_send_slider = args[-1]
718
  for idx, s, attr_name in zip(peq_indices, peq_sliders, peq_attr_names):
@@ -725,6 +799,9 @@ with gr.Blocks() as demo:
725
  m, name = get_last_attribute(fx[7].effects[0], attr_name)
726
  f(m, name, s)
727
 
 
 
 
728
  update_param(fx[7].params, "sends_0", 10 ** (reverb_send_slider / 20))
729
 
730
  return fx
@@ -792,6 +869,18 @@ with gr.Blocks() as demo:
792
  outputs=[z, fx_params, json_output] + update_pc_outputs,
793
  )
794
 
 
 
 
 
 
 
 
 
 
 
 
 
795
  render_button.click(
796
  chain_functions(
797
  lambda audio, ratio, x, *all_s: (
@@ -843,6 +932,16 @@ with gr.Blocks() as demo:
843
  fx[7].effects[0].odd_pan.params.pan.item() * 200 - 100,
844
  fx[7].effects[0].even_pan.params.pan.item() * 200 - 100,
845
  fx[7].params.sends_0.log10().item() * 20,
 
 
 
 
 
 
 
 
 
 
846
  ]
847
  update_fx_outputs = [
848
  pk1_freq,
@@ -873,6 +972,16 @@ with gr.Blocks() as demo:
873
  odd_pan,
874
  even_pan,
875
  reverb_send,
 
 
 
 
 
 
 
 
 
 
876
  ]
877
  update_plots = lambda fx: [
878
  plot_eq(fx),
 
10
  from hydra.utils import instantiate
11
  from soxr import resample
12
  from functools import partial, reduce
13
+ from itertools import accumulate
14
  from torchcomp import coef2ms, ms2coef
15
  from copy import deepcopy
16
 
 
627
  plot_delay(fx), label="Delay Frequency Response", elem_id="delay-plot"
628
  )
629
 
630
+ _ = gr.Markdown("## FDN Reverb")
631
  with gr.Row():
632
  reverb_plot = gr.Plot(
633
  plot_reverb(fx),
 
639
  plot_t60(fx), label="Reverb T60", elem_id="t60-plot", min_width=160
640
  )
641
 
642
+ with gr.Row():
643
+ fdn = fx[7].effects[1]
644
+ tone_correct_peq = fdn.eq
645
+ with gr.Column(min_width=160):
646
+ _ = gr.Markdown("Low Shelf")
647
+ tc_ls = tone_correct_peq[2]
648
+ tc_ls_freq = default_freq_slider(
649
+ minimum=30, maximum=450, value=tc_ls.params.freq.item()
650
+ )
651
+ tc_ls_gain = default_gain_slider(
652
+ minimum=-12, maximum=12, value=tc_ls.params.gain.item()
653
+ )
654
+
655
+ with gr.Column(min_width=160):
656
+ _ = gr.Markdown("Peak filter 1")
657
+ tc_pk1 = tone_correct_peq[0]
658
+ tc_pk1_freq = default_freq_slider(
659
+ minimum=200, maximum=2500, value=tc_pk1.params.freq.item()
660
+ )
661
+ tc_pk1_gain = default_gain_slider(
662
+ minimum=-12, maximum=12, value=tc_pk1.params.gain.item()
663
+ )
664
+ tc_pk1_q = default_q_slider(
665
+ minimum=0.1, maximum=3, value=tc_pk1.params.Q.item()
666
+ )
667
+ with gr.Column(min_width=160):
668
+ _ = gr.Markdown("Peak filter 2")
669
+ tc_pk2 = tone_correct_peq[1]
670
+ tc_pk2_freq = default_freq_slider(
671
+ minimum=600, maximum=7000, value=tc_pk2.params.freq.item()
672
+ )
673
+ tc_pk2_gain = default_gain_slider(
674
+ minimum=-12, maximum=12, value=tc_pk2.params.gain.item()
675
+ )
676
+ tc_pk2_q = default_q_slider(
677
+ minimum=0.1, maximum=3, value=tc_pk2.params.Q.item()
678
+ )
679
+
680
+ with gr.Column(min_width=160):
681
+ _ = gr.Markdown("High Shelf")
682
+ tc_hs = tone_correct_peq[3]
683
+ tc_hs_freq = default_freq_slider(
684
+ minimum=1500, maximum=16000, value=tc_hs.params.freq.item()
685
+ )
686
+ tc_hs_gain = default_gain_slider(
687
+ minimum=-12, maximum=12, value=tc_hs.params.gain.item()
688
+ )
689
+
690
  with gr.Row():
691
  json_output = gr.JSON(
692
  model2json(fx), label="Effect Settings", max_height=800, open=True
 
755
  ]
756
  delay_update_plot_flag = [True] * 4 + [False] * 2
757
 
758
+ tc_peq_sliders = [
759
+ tc_pk1_freq,
760
+ tc_pk1_gain,
761
+ tc_pk1_q,
762
+ tc_pk2_freq,
763
+ tc_pk2_gain,
764
+ tc_pk2_q,
765
+ tc_ls_freq,
766
+ tc_ls_gain,
767
+ tc_hs_freq,
768
+ tc_hs_gain,
769
+ ]
770
+ tc_peq_attr_names = ["freq", "gain", "Q"] * 2 + ["freq", "gain"] * 2
771
+ tc_peq_indices = [0] * 3 + [1] * 3 + [2] * 2 + [3] * 2
772
+
773
+ all_effect_sliders = (
774
+ peq_sliders + cmp_sliders + delay_sliders + tc_peq_sliders + [reverb_send]
775
+ )
776
+ split_sizes = [
777
+ len(peq_sliders),
778
+ len(cmp_sliders),
779
+ len(delay_sliders),
780
+ len(tc_peq_sliders),
781
+ 1,
782
+ ]
783
+ split_indexes = list(
784
+ accumulate(split_sizes, initial=0)
785
+ ) # [0, len(peq_sliders), len(peq_sliders) + len(cmp_sliders), ...]
786
 
787
  def assign_fx_params(fx, *args):
788
+ peq_sliders, cmp_sliders, delay_sliders, tc_peq_sliders = map(
789
+ lambda i, j: args[i:j], split_indexes[:-2], split_indexes[1:-1]
 
 
790
  )
791
  reverb_send_slider = args[-1]
792
  for idx, s, attr_name in zip(peq_indices, peq_sliders, peq_attr_names):
 
799
  m, name = get_last_attribute(fx[7].effects[0], attr_name)
800
  f(m, name, s)
801
 
802
+ for idx, s, attr_name in zip(tc_peq_indices, tc_peq_sliders, tc_peq_attr_names):
803
+ update_param(fx[7].effects[1].eq[idx].params, attr_name, s)
804
+
805
  update_param(fx[7].params, "sends_0", 10 ** (reverb_send_slider / 20))
806
 
807
  return fx
 
869
  outputs=[z, fx_params, json_output] + update_pc_outputs,
870
  )
871
 
872
+ for s in tc_peq_sliders:
873
+ s.input(
874
+ chain_functions(
875
+ lambda x, i, *args: x2z_common_steps(x, *args) + (i,),
876
+ lambda z, x, fx, e_pc_i: [z, x]
877
+ + [model2json(fx), plot_reverb(fx)]
878
+ + update_pc(z, e_pc_i),
879
+ ),
880
+ inputs=[fx_params, extra_pc_dropdown] + all_effect_sliders,
881
+ outputs=[z, fx_params, json_output, reverb_plot] + update_pc_outputs,
882
+ )
883
+
884
  render_button.click(
885
  chain_functions(
886
  lambda audio, ratio, x, *all_s: (
 
932
  fx[7].effects[0].odd_pan.params.pan.item() * 200 - 100,
933
  fx[7].effects[0].even_pan.params.pan.item() * 200 - 100,
934
  fx[7].params.sends_0.log10().item() * 20,
935
+ fx[7].effects[1].eq[0].params.freq.item(),
936
+ fx[7].effects[1].eq[0].params.gain.item(),
937
+ fx[7].effects[1].eq[0].params.Q.item(),
938
+ fx[7].effects[1].eq[1].params.freq.item(),
939
+ fx[7].effects[1].eq[1].params.gain.item(),
940
+ fx[7].effects[1].eq[1].params.Q.item(),
941
+ fx[7].effects[1].eq[2].params.freq.item(),
942
+ fx[7].effects[1].eq[2].params.gain.item(),
943
+ fx[7].effects[1].eq[3].params.freq.item(),
944
+ fx[7].effects[1].eq[3].params.gain.item(),
945
  ]
946
  update_fx_outputs = [
947
  pk1_freq,
 
972
  odd_pan,
973
  even_pan,
974
  reverb_send,
975
+ tc_pk1_freq,
976
+ tc_pk1_gain,
977
+ tc_pk1_q,
978
+ tc_pk2_freq,
979
+ tc_pk2_gain,
980
+ tc_pk2_q,
981
+ tc_ls_freq,
982
+ tc_ls_gain,
983
+ tc_hs_freq,
984
+ tc_hs_gain,
985
  ]
986
  update_plots = lambda fx: [
987
  plot_eq(fx),