Nucli: param range not working correctly

I want to pass a number of bins into a spectral function so it must be an integer. If I set the param range from 64-16384 and move the slider, it goes from 64.059 to 16383.945, which I assume is because it’s represented as a float.

I’m not sure if this is actually a bug or whether there’s a way to specify that the param only takes integers. It seems to work properly if I wire an Int to the input.

edit- maybe I should use a quantize function to round the input to the nearest power of 2.

Slightly off-topic, but if I do spectral name(number, 4), I don’t understand why I can’t pass it the param id because if I want to conditionally set the number of bins, I have to write multiple spectral functions eg name_64, name_128, etc and I have to make a massive if statement to decide which one to use to pass to the outputs. A switch/case statement would be nice too.

Integer params: Nucli params are plain floats. They update once per audio block, and the slider moves continuously across the range, so 64.059 is the slider doing what it’s told. I don’t know of a way to declare a param as integer. Round it in the code instead:

param bins = 1024 (64 .. 16384)
let n = round(bins)

FFT sizes are nearly always powers of two, though, so a 64–16384 slider mostly lands on sizes you can’t use. A small index param works better:

param size = 4 (0 .. 8) // 0 = 64 … 8 = 16384
let i = round(size)

That gives nine clean steps, and you can turn i into 64 × 2^i in code.

Why spectral name(number, 4) won’t take a param: I believe the FFT size has to be known when the code compiles. It fixes the buffer sizes and the latency the node reports to the host. A param can change at any moment while audio runs, so the size has to be a literal number. Changing it live would mean rebuilding buffers and changing the plugin’s latency mid-stream.

Choosing a size at run time: separate spectral functions per size, picked with if on the rounded index, is the only way I know. Keep it to the few sizes you actually need, and check the CPU, because I’m not sure the unused ones stop running. Another option is one Nucli node per size, with the choice made outside the node.

switch/case: as far as I know Nucli only has if/else. An if chain on a rounded index does the job meanwhile. A switch, and a size argument that can take a constant expression, would make good feature requests for Mario.

Thanks! That’s very helpful. I think they’re only called when the code executes.

I’ve already moved on from this experiment and have now made a spectral vocoder, which is surprisingly easy.