Bug in my module

Hi people, I’m developing a polyphonic utility module: 1 polyphonic input → 5 monophonic outputs (which emit the signal of the channel selected by each of the 5 knobs) Polyphonic main output.

The input works fine. I haven’t worked on the knobs yet. The mono outputs work fine. In the main output I have a bug that I cannot find / fix in the code. In addition to malfunctioning, it causes some Rack crashes. Can anyone kindly help me?



Hard to help without seeing code, but at a glance it looks like you are assigning your input channels to your simd processors incorrectly.

Here is the code

struct Deviat5 : Module {
	enum ParamId {
	enum InputId {
	enum OutputId {
	enum LightId {
    //edit channels = -1
	int channels = 5;
    //edit lastChannels 0
	int lastChannels = 1;

	Deviat5() {
        configParam(SEL1_PARAM, 0.f, 15.f, 15.f, "Channel Selector 1");
		configParam(SEL2_PARAM, 0.f, 15.f, 15.f, "Channel Selector 2");
		configParam(SEL3_PARAM, 0.f, 15.f, 15.f, "Channel Selector 3");
		configParam(SEL4_PARAM, 0.f, 15.f, 15.f, "Channel Selector 4");
		configParam(SEL5_PARAM, 0.f, 15.f, 15.f, "Channel Selector 5");
		configInput(IN_INPUT, "Polyphonic");
        configOutput(OUT1_OUTPUT, "Output 1");
		configOutput(OUT2_OUTPUT, "Output 2");
		configOutput(OUT3_OUTPUT, "Output 3");
		configOutput(OUT4_OUTPUT, "Output 4");
		configOutput(OUT5_OUTPUT, "Output 5");
		configOutput(MAIN_OUTPUT, "Main Output");

	void process(const ProcessArgs& args) override {
		for (int c = 0; c < 16; c++) {
			float v = inputs[IN_INPUT].getVoltage(c);
			outputs[OUT1_OUTPUT + c].setVoltage(v);
            outputs[MAIN_OUTPUT].setVoltage(v, c);

		lastChannels = inputs[IN_INPUT].getChannels();
        int automaticChannels = 5;
        automaticChannels = lastChannels;
        outputs[MAIN_OUTPUT].channels = (channels >= 0) ? channels : automaticChannels;

You have six outputs, but your loop goes up to 15, so you’re going off the end of the outputs array.

1 Like

Well, first off, output[].channels is deprecated API. Use output[].setChannels(channels) instead.

Second, for clarity, you should use inputs[].getChannels() before your for loop to fetch the number of channels on your inport, and use that variable to decide how many times to loop instead.

OUT1_OUTPUT + c exceeds OUTPUT_LEN so likely some object pointer splats some data structure with occasional segmentation faults.

1 Like

In the meantime, thanks to everyone. @3HR instead MinGW gave me problems with .setChannels, while it interprets .channels correctly

@jackokring @Richie putting back “lastChannels = 0” and typing “5” instead of “16”, it seems to work (without removing + c)

I’ll have to try opening Rack several times to see if it still crashes, but at the moment everything seems to be working fine.

I have a question however, having written 5 instead of 16, does this mean that the input receives a maximum of 5 channels?

Let me explain: The outputs must be 5 (= main), but the input must be able to receive 16 channels of polyphony in order to make a channel selection with the knobs.

an edit?

1 Like

Once you have the knobs working, you’ll no longer need to loop through the 16 channels. You’ll loop through the five outputs, and for each one you’ll read the channel from the knob.

1 Like

Hmm, I’m not sure I’m getting the desired result this way (@Richie) but I definitely think I’ll have to get the knobs to work to find out.

The bug seems to have disappeared and the output works fine, so I consider the topic solved.

Thanks again guys, for the bug fix and other suggestions.