Cabbage Logo
Back to Cabbage Site

CSOUND : chnset , chnget ... how does this work

Hello,

I think this is a pure CSound so please forgive me for being so noob… I discovered Csound 3 weeks ago.
I would like to use Cabbage to make a VST synth like Synth1 (OK, I am far from it yet).
I am getting lost with the internal clocks… like everyone else before I suppose.

What I would like to achieve is a kinda modular thing (not in the sense of Moog modular), I want to isolate each function in one instrument and connect it to other instruments to understand what is the effect of each ( and make the code more readable as Csound… is really a nightmare to read even it is THE price to pay for a fantastic toolbox)

Example (here attached)
One oscillator sending via chnset -> madsr -> outsound

I dont want the adsr to be inside the main instrument, i want it to be inside another instrument Instr 2

Somehow what I do does not work, could someone explain me why please?
Thank you for your help.
JMSynth_01.csd (4.5 KB)

You’re off to a good start, and breaking things down like this is a good idea, but it involves the use of some extra opcodes to get it to work. One way you can do it is to trigger the other instrument from play from the main instrument. You can do this using subinstr. It’s not used that often any more since UDO can into being, but it’ll do the trick. What I did was this:

chnset aOutL, "Audio1L"
chnset aOutR, "Audio1R"

;start instr2 and play for as long as this instrument is playing
aL, aR subinstr "ADSR_Instr"
outs aL, aR

When the first instrument plays, via the keyboard, it plays the second instrument and grabs the output from it.It then feeds that output to the speakers. When you call an instrument with subinstr, it won’t output to the speakers. The output has to be retrieved from the calling instrument. I’ve attached the updated file. Note that you could probably use channels and send it to another instrument that is always on, but perhaps this way is a little clear. And you can name your instruments to make thing even clearer.

Let me know if this all makes sense :wink: JMSynth_01.csd (4.5 KB)

Oh Thank you ! This works If I understand you well, it is not because an instrument is “active” that it will play. It needs to be called from the main instrument which is triggered by midi.
About the sound , I hear clicks when release a key- Is this relqted to the windows drier ?

At the end of the release section? Hmm, it’s probably because the calling instrument stops. If you put an madsr in there with a release tail it should help. You don’t need to use it for anything, it will simply prolong instrument 1 as soon as you release a key. That should do the trick.

I did a chnclear after the outs of the ADSR + little tail in release does the trick.

Should you have a little time, could you show how the UDO could replace what I did ? I suppose this could also be a good tutorial for beginners like me :slight_smile:

Here is how you could do the same thing using a UDO.JMSynth_01.csd (4.5 KB)
The UDO is sent the input audio and envelope parameters as input arguments to the UDO rather than using named channels so that is can be used multiple times within the same orchestra with different values, and hence as a flexible module.

Thank you a lot! Indeed it is very easy to understand that way. It look more like a procedure of any programming language. I’ll keep it as a model for further experiments.