Granulator~ example patch compilation errors in Xcode

Todd Krupa's icon

Hi, I wanted to point out a potential issue exporting RNBO patchers containing Granulator~. During the build process (Xcode) I get:

Non-void function does not return a value in all control paths

It's a factory function using a classname if that helps, and other factory functions not containing granulator seem to be fine. The function in question involves @interp and the conditionals for specifying a mode. By adding a default to the end (either 0 or one of the conditional interp functions), the issue can be resolved and the code builds.

Here is the code with a manual patch at the very end.

template <typename T> inline SampleValue bufferreadsample(
    T& buffer,
    const SampleValue sampleIndex,
    const Index channel,
    const SampleIndex start,
    const SampleIndex end,
    const int interp
) {
    if (sampleIndex < 0.0) {
        return 0.0;
    }

    SampleIndex truncIndex = (SampleIndex)(trunc(sampleIndex));

    if (interp == 5) {
        return buffer->getSample(channel, truncIndex);
    } else {
        number frac = sampleIndex - truncIndex;
        number wrap = end - 1;

        if (interp == 0) {
            SampleIndex index1 = (SampleIndex)(truncIndex);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            return this->linearinterp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2)
            );
        } else if (interp == 1) {
            SampleIndex index1 = (SampleIndex)(truncIndex - 1);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            SampleIndex index3 = (SampleIndex)(index2 + 1);

            if (index3 > wrap)
                index3 = start;

            SampleIndex index4 = (SampleIndex)(index3 + 1);

            if (index4 > wrap)
                index4 = start;

            return this->cubicinterp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2),
                buffer->getSample(channel, index3),
                buffer->getSample(channel, index4)
            );
        } else if (interp == 6) {
            SampleIndex index1 = (SampleIndex)(truncIndex - 1);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            SampleIndex index3 = (SampleIndex)(index2 + 1);

            if (index3 > wrap)
                index3 = start;

            SampleIndex index4 = (SampleIndex)(index3 + 1);

            if (index4 > wrap)
                index4 = start;

            return this->fastcubicinterp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2),
                buffer->getSample(channel, index3),
                buffer->getSample(channel, index4)
            );
        } else if (interp == 2) {
            SampleIndex index1 = (SampleIndex)(truncIndex - 1);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            SampleIndex index3 = (SampleIndex)(index2 + 1);

            if (index3 > wrap)
                index3 = start;

            SampleIndex index4 = (SampleIndex)(index3 + 1);

            if (index4 > wrap)
                index4 = start;

            return this->splineinterp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2),
                buffer->getSample(channel, index3),
                buffer->getSample(channel, index4)
            );
        } else if (interp == 7) {
            SampleIndex index1 = (SampleIndex)(truncIndex - 2);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            SampleIndex index3 = (SampleIndex)(index2 + 1);

            if (index3 > wrap)
                index3 = start;

            SampleIndex index4 = (SampleIndex)(index3 + 1);

            if (index4 > wrap)
                index4 = start;

            SampleIndex index5 = (SampleIndex)(index4 + 1);

            if (index5 > wrap)
                index5 = start;

            SampleIndex index6 = (SampleIndex)(index5 + 1);

            if (index6 > wrap)
                index6 = start;

            return this->spline6interp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2),
                buffer->getSample(channel, index3),
                buffer->getSample(channel, index4),
                buffer->getSample(channel, index5),
                buffer->getSample(channel, index6)
            );
        } else if (interp == 3) {
            SampleIndex index1 = (SampleIndex)(truncIndex);

            if (index1 < 0)
                index1 = wrap;

            SampleIndex index2 = (SampleIndex)(index1 + 1);

            if (index2 > wrap)
                index2 = start;

            return this->cosineinterp(
                frac,
                buffer->getSample(channel, index1),
                buffer->getSample(channel, index2)
            );
        }
    }

    // Added a default return value if none of the above conditions are met.  Also works with one of the expressions from conditions
    return 0.0;
}

Is there anything in the patcher I could do to prevent this? I've tried explicitly setting @interp on the granulator.

Thanks in advance!