Possibly a number-scaling opcode? also, an envelope generator with k-rate arguments?

hi there! I’m in no place to be asking for features and I don’t want to potentially put too much work/pressure on the shoulders of the devs out there, but I was wondering about the possible addition of a couple features into Csound… If there are already opcodes that do what I bring up I’m sorry if I wasted your time here!

One of the things I felt could be useful would be a scale opcode that works more like the scale object in Max - I found that there’s a scale opcode in Csound already but it seems that its input only allows numbers ranging from 0 to 1. It could be useful to have a scaling opcode that lets users input any range (or a much wider range) of numbers.

Another thing I’m wondering about is the possibility of an envelope generator (like linsegr, expsegr, and so on) whose parameters (the points’ values and the duration of the “tracing” in between the points) can be adjusted as a note is playing (so k or a rate, I think?). I’m in the process of building an instrument at the moment and it feels rather tedious/unnecessary to have to play another note every time I want to hear the effect of an envelope being changed (for example, adjusting the sustain value while holding the note and hearing the effect, instead of having to re-play the note over and over for each adjustment I make). Although the loopseg opcode exists, looping an envelope may not be what a user may be looking to do.

Perhaps there are workarounds and ways to achieve these things already and I haven’t figured them out yet. I’m going to keep trying to think of ways/alternatives to do these things but if anyone wants to chime in please feel free to help!

Hi @fellusive. You can work with signals in any range with the scale opcode in Csound. You just need to use the extra optional parameters to set the input range. If that doesn’t work, you could quickly write one yourself:

opcode Scaler, k,kkk
    kSignal, kMin, kMax xin
    setksmps 1

    if kSignal < kMin then
        kOut = kMin
    elseif kSignal > kMax then
        kOut = kMax
    else
        kOut = kSignal
    endif    

    xout kOut
endop


instr 1
    k1 line -100, p3, 100
    if metro(2) == 1 then
        kScl Scaler k1, -50, 50
        printk2 kScl
    endif
endin

schedule(1, 0, 5)

As for envelope with k-rate parameters. I don’t see how this would work. How could you change a duration after the fact, or during the segment for that matter without causing issues. Envelopes segments are calculated based on their start value, target value and duration. Changing any one of those during performance would lead to discontinuities in the signal and lead to pops or clicks.

You don’t need k-rate envelopes for this. Simply multiply the envelope by a given gain factor to increase the sustain. It’s all heading towards 0 after that anyway.

instr 2
    iAtt = 0.3
    iDec = 0.4
    iDel = iAtt+iDec
    kSusChange linseg 1, iDel, 1, 1, 2, 0, 2
    kEnv madsr iAtt, iDec, .2, 1
    aOsc oscil kEnv*kSusChange, kEnv*kSusChange*300
    outs aOsc, aOsc
endin

schedule(2, 0, 5)

There are definitely other ways to control the amplitude of the various points within an envelope. It might involve writing your own envelope generator UDO, which is a good exercise in itself.

Hi Rory! Thanks for your thorough explanations and examples. I hadn’t thought of those solutions (as you can tell) so they were quite eye-opening. Making my own UDOs is something I haven’t done before but now I’ll start incorporating them into my work thanks to your help.

Also, big thanks to you and everyone else who helped make this forum a reality! It’s an honor to have posted the first dumb question in this channel haha.

And I got to answer the first question :muscle: :laughing:

1 Like

for scaling, there is the linlin opcode by eduardo moguillansky:
https://csound.com/docs/manual/linlin.html

perhaps this page can be useful to search for opcodes:
https://flossmanual.csound.com/appendix/opcode-guide

best -
joachim

1 Like

thank you so much for these suggestions joachim! linlin looks like another nice way to scale in addition to what rory pointed out, and that floss page is so helpful. I’ll definitely be using it in the future :slight_smile: