Csound Csound-dev Csound-tekno Search About

[Csnd] port opcode and envelopes

Date2021-01-12 16:13
FromBernard Geyer
Subject[Csnd] port opcode and envelopes
In my midi-controlled instruments, the amplitude is determined by 3 factors : midi velocity, a slider for each channel and a master slider. The velocity is determined at i rate and the slider values at k rate. I use the CsoundQt GUI sliders.

In order to avoid clicks when I move sliders, I use the port opcode, and I first tried the port time 0.05 that is given in some examples.
The clicks are gone, but there are 2 new problems : 
- on instruments with a short attack, the original attack is destroyed and replaced by a more slow attack
- on instruments with very few overtones, specially sinus-like; there are artefacts on each segment of the envelope.

With port time 0.01, the attack is still not correct.
With port time 0.001, there are clicks when I move the sliders .
So, I choosed 0.005 as a compromise.

Here is an example of my code :

opcode Oscillator, aa, iiiii

iChannel, iKey, iVelocity, iGain, iWaveform xin


;(other parameters are stored in tables):

SetKeyParam(iChannel, iKey, giNumChannels, 1)

iTuning = GetKeyParam(iChannel, iKey, giTuning)

kEnv = kADSR(iChannel, iKey)


iVelo = (iVelocity / 127)

iVelo *= iVelo ;squared

kAmp = iGain * iVelo * \

GetKeyParam(iChannel, iKey, giVolume) * \

kGetChannelParam(iChannel, giChannelVolume) * \

kGetChannelParam(0, giChannelVolume) ; 0 = master volume


kAmp port kAmp, 0.005 ; smooth audio_vol


aSig poscil kAmp * kEnv, iTuning, iWaveform


xout aSig, aSig

endop


In some instruments I use poscil, in others loscil, without difference concerning this problem.

Some ideas ?


Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-01-12 20:46
FromTarmo Johannes
SubjectRe: [Csnd] port opcode and envelopes
Hi!

three things to try -

- use a-rate for amplitude and envelope, use  interp(kamp), if necessary -  depending on ksmps, it can give audible steps when changing
- try to use the init value parameter in the port opcode -  otherwis it starts always from 0. I am not sure if it helps but you can to determine what is the value in i-time and start form that:

iAmp = iGain * iVelo * \

GetKeyParam(iChannel, iKey, giVolume) * \

iGetChannelParam(iChannel, giChannelVolume) * \

iGetChannelParam(0, giChannelVolume)


kAmp = ...

kAmp port kAmp, 0.02, iAmp

I often use lines like:
kVolume port chnget:k("volume"), 0.02, chnget:i("volume")
to smoothen values coming from channels

- Try lag opcode instead:

Hope it helps!
tarmo


T, 12. jaanuar 2021 18:14 Bernard Geyer <micamusic2@gmail.com> kirjutas:
In my midi-controlled instruments, the amplitude is determined by 3 factors : midi velocity, a slider for each channel and a master slider. The velocity is determined at i rate and the slider values at k rate. I use the CsoundQt GUI sliders.

In order to avoid clicks when I move sliders, I use the port opcode, and I first tried the port time 0.05 that is given in some examples.
The clicks are gone, but there are 2 new problems : 
- on instruments with a short attack, the original attack is destroyed and replaced by a more slow attack
- on instruments with very few overtones, specially sinus-like; there are artefacts on each segment of the envelope.

With port time 0.01, the attack is still not correct.
With port time 0.001, there are clicks when I move the sliders .
So, I choosed 0.005 as a compromise.

Here is an example of my code :

opcode Oscillator, aa, iiiii

iChannel, iKey, iVelocity, iGain, iWaveform xin


;(other parameters are stored in tables):

SetKeyParam(iChannel, iKey, giNumChannels, 1)

iTuning = GetKeyParam(iChannel, iKey, giTuning)

kEnv = kADSR(iChannel, iKey)


iVelo = (iVelocity / 127)

iVelo *= iVelo ;squared

kAmp = iGain * iVelo * \

GetKeyParam(iChannel, iKey, giVolume) * \

kGetChannelParam(iChannel, giChannelVolume) * \

kGetChannelParam(0, giChannelVolume) ; 0 = master volume


kAmp port kAmp, 0.005 ; smooth audio_vol


aSig poscil kAmp * kEnv, iTuning, iWaveform


xout aSig, aSig

endop


In some instruments I use poscil, in others loscil, without difference concerning this problem.

Some ideas ?


Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-01-12 21:28
FromEduardo Moguillansky
SubjectRe: [Csnd] port opcode and envelopes

As Tarmo said, port alone is not what you need. At least interp(port(...)). A better solution is lag, which is audio-rate.

On 12.01.21 17:13, Bernard Geyer wrote:
In my midi-controlled instruments, the amplitude is determined by 3 factors : midi velocity, a slider for each channel and a master slider. The velocity is determined at i rate and the slider values at k rate. I use the CsoundQt GUI sliders.

In order to avoid clicks when I move sliders, I use the port opcode, and I first tried the port time 0.05 that is given in some examples.
The clicks are gone, but there are 2 new problems : 
- on instruments with a short attack, the original attack is destroyed and replaced by a more slow attack
- on instruments with very few overtones, specially sinus-like; there are artefacts on each segment of the envelope.

With port time 0.01, the attack is still not correct.
With port time 0.001, there are clicks when I move the sliders .
So, I choosed 0.005 as a compromise.

Here is an example of my code :

opcode Oscillator, aa, iiiii

iChannel, iKey, iVelocity, iGain, iWaveform xin


;(other parameters are stored in tables):

SetKeyParam(iChannel, iKey, giNumChannels, 1)

iTuning = GetKeyParam(iChannel, iKey, giTuning)

kEnv = kADSR(iChannel, iKey)


iVelo = (iVelocity / 127)

iVelo *= iVelo ;squared

kAmp = iGain * iVelo * \

GetKeyParam(iChannel, iKey, giVolume) * \

kGetChannelParam(iChannel, giChannelVolume) * \

kGetChannelParam(0, giChannelVolume) ; 0 = master volume


kAmp port kAmp, 0.005 ; smooth audio_vol


aSig poscil kAmp * kEnv, iTuning, iWaveform


xout aSig, aSig

endop


In some instruments I use poscil, in others loscil, without difference concerning this problem.

Some ideas ?


Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-01-15 21:59
FromJustin Smith
SubjectRe: [Csnd] port opcode and envelopes
- on instruments with a short attack, the original attack is destroyed and replaced by a more slow attack

this makes me think that the velocity is fed into the same port that the sliders do - this is incorrect IMHO, dynamic runtime controls should be smoothed by port, but the velocity should be a separate factor with no port smoothing.
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here