Skip to content

Commit

Permalink
Fix bug in StereoWidth, and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Feb 2, 2024
1 parent 2f1d7da commit 72b8b64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 6 additions & 4 deletions source/src/node/processors/panning/stereo-width.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ void StereoWidth::process(Buffer &out, int num_frames)
sample left = this->input->out[0][frame];
sample right = this->input->out[1][frame];

left = width * left + (1 - width) * right;
right = width * right + (1 - width) * left;
// scale width from 0..1
width = (width / 2) + 0.5;
sample left_out = width * left + (1 - width) * right;
sample right_out = (1 - width) * left + width * right;

out[0][frame] = left;
out[1][frame] = right;
out[0][frame] = left_out;
out[1][frame] = right_out;
}
}

Expand Down
20 changes: 19 additions & 1 deletion tests/test_nodes_processors_multichannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ def test_nodes_multichannel_pan(graph):
b.set_input("pan", 0.0)
graph.render_subgraph(b, reset=True)
assert all(b.output_buffer[0] == 0.5 * math.sqrt(0.5))
assert all(b.output_buffer[1] == 0.5 * math.sqrt(0.5))
assert all(b.output_buffer[1] == 0.5 * math.sqrt(0.5))

def test_nodes_multichannel_width(graph):
a = 0.5
b = 1.0
c = sf.StereoWidth([a, b], 1.0)
graph.render_subgraph(c, reset=True)
assert all(c.output_buffer[0] == 0.5)
assert all(c.output_buffer[1] == 1.0)

c.set_input("stereo-width", 0.0)
graph.render_subgraph(c, reset=True)
assert all(c.output_buffer[0] == 0.75)
assert all(c.output_buffer[1] == 0.75)

c.set_input("stereo-width", -1.0)
graph.render_subgraph(c, reset=True)
assert all(c.output_buffer[0] == 1.0)
assert all(c.output_buffer[1] == 0.5)

0 comments on commit 72b8b64

Please sign in to comment.