Skip to content

Commit

Permalink
Call resize_output_buffers() from set_channels(), fixing crash in Cha…
Browse files Browse the repository at this point in the history
…nnelPanner; update SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS
  • Loading branch information
ideoforms committed Aug 5, 2024
1 parent 72ee87a commit fa4f0be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions tests/test_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from signalflow import SineOscillator, AudioGraph, Line, SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS
from signalflow import SineOscillator, AudioGraph, Line, SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS
from signalflow import NodeAlreadyPlayingException, NodeNotPlayingException
import signalflow as sf
import numpy as np
Expand All @@ -14,7 +14,7 @@ def test_node_no_graph():
def test_node_process(graph):
a = SineOscillator(440)
a.process(1024)
assert a.output_buffer.shape == (SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS, 1024)
assert a.output_buffer.shape == (SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS, 1024)


def test_node_add_input(graph):
Expand Down Expand Up @@ -77,13 +77,13 @@ def test_node_write_to_output_buffer(graph):
a.output_buffer[0][3] = 1.0
assert a.output_buffer[0][3] == 1.0

assert a.output_buffer.shape == (SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS, graph.output_buffer_size)
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS - 1][-1] = 1.0
assert a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS - 1][-1] == 1.0
assert a.output_buffer.shape == (SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS, graph.output_buffer_size)
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS - 1][-1] = 1.0
assert a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS - 1][-1] == 1.0
with pytest.raises(IndexError):
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS][graph.output_buffer_size - 1] == 1.0
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS][graph.output_buffer_size - 1] == 1.0
with pytest.raises(IndexError):
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS][graph.output_buffer_size] == 1.0
a.output_buffer[SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS][graph.output_buffer_size] == 1.0


def test_node_trigger(graph):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_node_multichannel_expansion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from signalflow import SineOscillator, SquareOscillator, ChannelMixer, ChannelArray, StereoPanner, Buffer, BufferPlayer, \
AudioGraph, AudioOut_Dummy, SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS
AudioGraph, AudioOut_Dummy, SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS
from signalflow import BiquadFilter, AllpassDelay, WaveShaper, WaveShaperBuffer, Constant, Add, AudioGraphConfig
from signalflow import InvalidChannelCountException
import numpy as np
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_expansion_recursive_processing(graph):
def test_expansion_buffer_reallocation(graph):
a = SineOscillator([440] * 4)
assert a.num_output_channels == 4
assert a.num_output_channels_allocated == max(4, SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS)
assert a.num_output_channels_allocated == max(4, SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS)
a.set_input("frequency", [440] * 100)
assert a.num_output_channels == 100
assert a.num_output_channels_allocated == 100
Expand All @@ -190,7 +190,7 @@ def test_expansion_input_reallocation(graph):
Need to allocate more output buffers for upmixing
rename num_output_channels_allocated to num_allocated_output_buffers
"""
channel_count = SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS + 1
channel_count = SIGNALFLOW_NODE_INITIAL_OUTPUT_CHANNELS + 1
a = Constant(4)
b = Add(a, [9] * channel_count)
assert b.num_output_channels == channel_count
Expand Down

0 comments on commit fa4f0be

Please sign in to comment.