Spaces:
Running
Running
Commit
·
f455314
1
Parent(s):
4059958
feat: add dry/wet ratio slider to inference and update rendering logic
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import torch
|
|
|
|
| 5 |
import yaml
|
| 6 |
import json
|
| 7 |
import pyloudnorm as pyln
|
|
@@ -134,7 +135,7 @@ def x2z(x):
|
|
| 134 |
|
| 135 |
|
| 136 |
@torch.no_grad()
|
| 137 |
-
def inference(audio, fx):
|
| 138 |
sr, y = audio
|
| 139 |
if sr != 44100:
|
| 140 |
y = resample(y, sr, 44100)
|
|
@@ -153,13 +154,16 @@ def inference(audio, fx):
|
|
| 153 |
direct, wet = fx(y)
|
| 154 |
direct = direct.squeeze(0).T.numpy()
|
| 155 |
wet = wet.squeeze(0).T.numpy()
|
| 156 |
-
|
|
|
|
| 157 |
# rendered = fx(y).squeeze(0).T.numpy()
|
| 158 |
-
if np.max(np.abs(
|
| 159 |
-
scaler = np.max(np.abs(
|
| 160 |
-
rendered = rendered / scaler
|
| 161 |
direct = direct / scaler
|
| 162 |
wet = wet / scaler
|
|
|
|
|
|
|
| 163 |
return (
|
| 164 |
(44100, (rendered * 32768).astype(np.int16)),
|
| 165 |
(44100, (direct * 32768).astype(np.int16)),
|
|
@@ -420,6 +424,13 @@ with gr.Blocks() as demo:
|
|
| 420 |
|
| 421 |
with gr.Column():
|
| 422 |
audio_output = default_audio_block(label="Output Audio", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
direct_output = default_audio_block(label="Direct Audio", interactive=False)
|
| 424 |
wet_output = default_audio_block(label="Wet Audio", interactive=False)
|
| 425 |
|
|
@@ -782,11 +793,16 @@ with gr.Blocks() as demo:
|
|
| 782 |
|
| 783 |
render_button.click(
|
| 784 |
chain_functions(
|
| 785 |
-
lambda audio, x, *all_s: (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
inference,
|
| 787 |
),
|
| 788 |
inputs=[
|
| 789 |
audio_input,
|
|
|
|
| 790 |
fx_params,
|
| 791 |
]
|
| 792 |
+ all_effect_sliders,
|
|
@@ -946,4 +962,18 @@ with gr.Blocks() as demo:
|
|
| 946 |
outputs=[z, fx_params] + update_all_outputs,
|
| 947 |
)
|
| 948 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
demo.launch()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import torch
|
| 5 |
+
import math
|
| 6 |
import yaml
|
| 7 |
import json
|
| 8 |
import pyloudnorm as pyln
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
@torch.no_grad()
|
| 138 |
+
def inference(audio, ratio, fx):
|
| 139 |
sr, y = audio
|
| 140 |
if sr != 44100:
|
| 141 |
y = resample(y, sr, 44100)
|
|
|
|
| 154 |
direct, wet = fx(y)
|
| 155 |
direct = direct.squeeze(0).T.numpy()
|
| 156 |
wet = wet.squeeze(0).T.numpy()
|
| 157 |
+
angle = ratio * math.pi * 0.5
|
| 158 |
+
test_clipping = direct + wet
|
| 159 |
# rendered = fx(y).squeeze(0).T.numpy()
|
| 160 |
+
if np.max(np.abs(test_clipping)) > 1:
|
| 161 |
+
scaler = np.max(np.abs(test_clipping))
|
| 162 |
+
# rendered = rendered / scaler
|
| 163 |
direct = direct / scaler
|
| 164 |
wet = wet / scaler
|
| 165 |
+
|
| 166 |
+
rendered = math.sqrt(2) * (math.cos(angle) * direct + math.sin(angle) * wet)
|
| 167 |
return (
|
| 168 |
(44100, (rendered * 32768).astype(np.int16)),
|
| 169 |
(44100, (direct * 32768).astype(np.int16)),
|
|
|
|
| 424 |
|
| 425 |
with gr.Column():
|
| 426 |
audio_output = default_audio_block(label="Output Audio", interactive=False)
|
| 427 |
+
dry_wet_ratio = gr.Slider(
|
| 428 |
+
minimum=0,
|
| 429 |
+
maximum=1,
|
| 430 |
+
value=0.5,
|
| 431 |
+
label="Dry/Wet Ratio",
|
| 432 |
+
interactive=True,
|
| 433 |
+
)
|
| 434 |
direct_output = default_audio_block(label="Direct Audio", interactive=False)
|
| 435 |
wet_output = default_audio_block(label="Wet Audio", interactive=False)
|
| 436 |
|
|
|
|
| 793 |
|
| 794 |
render_button.click(
|
| 795 |
chain_functions(
|
| 796 |
+
lambda audio, ratio, x, *all_s: (
|
| 797 |
+
audio,
|
| 798 |
+
ratio,
|
| 799 |
+
assign_fx_params(vec2fx(x), *all_s),
|
| 800 |
+
),
|
| 801 |
inference,
|
| 802 |
),
|
| 803 |
inputs=[
|
| 804 |
audio_input,
|
| 805 |
+
dry_wet_ratio,
|
| 806 |
fx_params,
|
| 807 |
]
|
| 808 |
+ all_effect_sliders,
|
|
|
|
| 962 |
outputs=[z, fx_params] + update_all_outputs,
|
| 963 |
)
|
| 964 |
|
| 965 |
+
dry_wet_ratio.input(
|
| 966 |
+
chain_functions(
|
| 967 |
+
lambda _, *args: (_, *map(lambda x: x[1] / 32768, args)),
|
| 968 |
+
lambda ratio, d, w: math.sqrt(2)
|
| 969 |
+
* (
|
| 970 |
+
math.cos(ratio * math.pi * 0.5) * d
|
| 971 |
+
+ math.sin(ratio * math.pi * 0.5) * w
|
| 972 |
+
),
|
| 973 |
+
lambda x: (44100, (x * 32768).astype(np.int16)),
|
| 974 |
+
),
|
| 975 |
+
inputs=[dry_wet_ratio, direct_output, wet_output],
|
| 976 |
+
outputs=[audio_output],
|
| 977 |
+
)
|
| 978 |
+
|
| 979 |
demo.launch()
|