fix&feat: hiển thị tools chỉnh sửa audioclip
This commit is contained in:
@@ -42,3 +42,39 @@ def test_merge_back_to_parent():
|
||||
assert np.allclose(res[:900], 1.0)
|
||||
# Inside the edited range should be zero (except crossfades)
|
||||
assert np.allclose(res[1100:2900], 0.0)
|
||||
|
||||
def test_apply_volume_automation_envelope():
|
||||
sr = 44100
|
||||
duration = 2.0
|
||||
y = np.ones(int(sr * duration), dtype=np.float32) * 0.5 # Constant signal at -6dB
|
||||
|
||||
# Simple fade in from -inf to 0dB over 1 second
|
||||
nodes = [
|
||||
{"time": 0.0, "db": -60.0}, # Effectively -inf
|
||||
{"time": 1.0, "db": 0.0},
|
||||
{"time": 2.0, "db": 0.0},
|
||||
]
|
||||
|
||||
y_automated = SubTabDSPEngine.apply_volume_automation_envelope(y, sr, nodes)
|
||||
|
||||
y_automated = SubTabDSPEngine.apply_volume_automation_envelope(y, sr, nodes)
|
||||
|
||||
# Check start: should be 0.5 * 10**(-30/20) due to clipping
|
||||
expected_start_val = 0.5 * (10**(-30/20.0))
|
||||
assert np.isclose(y_automated[0], expected_start_val, atol=1e-5)
|
||||
|
||||
# Check at 0.5 seconds: interpolated to -15dB (halfway between -30dB and 0dB)
|
||||
# y * (10 ** (-15 / 20))
|
||||
expected_mid_val = 0.5 * (10**(-15/20.0))
|
||||
assert np.isclose(y_automated[int(0.5 * sr)], expected_mid_val, atol=1e-5)
|
||||
|
||||
# Check at 1.0 seconds: should be 0.5 * (10**(0/20)) = 0.5
|
||||
assert np.isclose(y_automated[int(1.0 * sr)], 0.5, atol=1e-5)
|
||||
|
||||
# Check at end: should be 0.5
|
||||
assert np.isclose(y_automated[-1], 0.5, atol=1e-5)
|
||||
|
||||
# Test with empty nodes
|
||||
y_no_nodes = SubTabDSPEngine.apply_volume_automation_envelope(y, sr, [])
|
||||
assert np.array_equal(y_no_nodes, y)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user