[Csnd] Trying to wrap my head around reinit, can not get it right
Date | 2019-01-03 11:23 |
From | Anton Kholomiov |
Subject | [Csnd] Trying to wrap my head around reinit, can not get it right |
Hi! I'm trying to understand reinit but seems to do smth wrong.But now I've got two phases: * fade out old file * file reload And this where I'm stuck. I'm trying various combos of reinit and timout but can not get it right. here is my code so far: It's as close as I could get, but unfortunately it ignores the code inside fade_out label. So the code inside it is not reinit'ed and I can not figure out why... ``` <CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac -d ;;;realtime audio out ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o oscili.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 opcode AmbiRow, aa, S[]kki Sfiles[], kSpeed, kUserIndex, iFadeTime xin kNext init 0 iSize lenarray Sfiles fade_out: prints "Do fade\n", 0.001 kenv linseg 1, iFadeTime, 0, 1, 0 rireturn load_file: kenv linseg 0, iFadeTime, 1, 1, 1 prints "Do load: %d\n", 0.001, kNext iIndex = i(kNext) if (iIndex >= 0) && (iIndex < iSize) then Sfile = Sfiles[iIndex] iStop = 0 else iStop = 1 endif if iStop == 0 then aLeft, aRight diskin2 Sfile, kSpeed else aLeft = 0 aRight = 0 endif rireturn kenv linseg 0, iFadeTime, 1, 1, 1 kUserIndex = floor(kUserIndex) aLeft init 0 aRight init 0 kTrig changed kUserIndex kTrigChange delayk kTrig, iFadeTime kSkipFirst linseg 0, iFadeTime + 0.1, 0, 0.1, 1 kTrigChange = kTrigChange * kSkipFirst if (kTrig == 1) && (kNext != kUserIndex) then printks "Fade out: %d\n", 0.001, kUserIndex kNext = kUserIndex reinit fade_out endif if kTrigChange == 1 then printks "Change: %d\n", 0.001, kUserIndex reinit load_file endif xout kenv * aLeft, kenv * aRight endop instr 2 kRandInd randi 3, 1 kGate metro (1/6) kInd samphold kRandInd, kGate kInd = abs(kInd) Sfiles[] init 3 Sfiles[0] strcpy "samples/pad-maj-base-1.wav" Sfiles[1] strcpy "samples/pad-min-base-1.wav" Sfiles[2] strcpy "samples/pad-min-base-2.wav" aL, aR AmbiRow Sfiles, 1, kInd, 3 outs aL, aR endin </CsInstruments> <CsScore> i2 0 60 e </CsScore> </CsoundSynthesizer> ``` Anton |
Date | 2019-01-06 01:26 |
From | Steven Yi |
Subject | Re: [Csnd] Trying to wrap my head around reinit, can not get it right |
Hi Anton, I never really like using reinit myself and largely avoid it by using a strategy to turn off previous instances and start new instances. If you have a release-time envelope, this would allow you to fade out the previous instrument. I tested this code in live.csound.com: instr Sine icps = p4 asig = poscil(0.25, icps) asig *= linsegr(1, 0.1, 1, 2, 0) out(asig, asig) endin schedule("Sine", 0, -1, 440) schedule(-nstrnum("Sine"), 0, 0) schedule("Sine", 0, -1, 880) I can eval the first schedule, then eval the next two lines together to turn off the first sine and start the second one. In my mind, the code is fairly clear for intention. You could use numbered instruments and fractional numbers for managing voice allocations if that fits the use case. Hope that helps! Steven On Thu, Jan 3, 2019 at 6:23 AM Anton Kholomiov |
Date | 2019-01-06 15:15 |
From | Anton Kholomiov |
Subject | Re: [Csnd] Trying to wrap my head around reinit, can not get it right |
Thanks. for hint Steven! i wasn't aware that it's possible to negate named instruments!вс, 6 янв. 2019 г. в 04:26, Steven Yi <stevenyi@gmail.com>: Hi Anton, |
Date | 2019-01-06 15:19 |
From | Anton Kholomiov |
Subject | Re: [Csnd] Trying to wrap my head around reinit, can not get it right |
Indeed that approach looks promising, I need to try it out. and crossfade between samples is easy to do in this case. I can just use linsegr. вс, 6 янв. 2019 г. в 18:15, Anton Kholomiov <anton.kholomiov@gmail.com>:
|
Date | 2019-01-06 18:41 |
From | Steven Yi |
Subject | Re: [Csnd] Trying to wrap my head around reinit, can not get it right |
Glad that's useful. I suppose that depending on the duration of fades, you might also consider an equal-power or other fade. The fade system I have in Blue is based on the code from Ardour: https://github.com/kunstmusik/blue/blob/develop/blue-score-layers-audio-core/src/blue/score/layers/audio/core/blue_fade.udo transegr might be a good opcode to consider too. All best! Steven On Sun, Jan 6, 2019 at 10:19 AM Anton Kholomiov |
Date | 2019-01-06 18:58 |
From | joachim heintz |
Subject | Re: [Csnd] Trying to wrap my head around reinit, can not get it right |
i think linenr offers with the iatdec parameter an option for different decay curves, too. On 06/01/19 19:41, Steven Yi wrote: > Glad that's useful. I suppose that depending on the duration of > fades, you might also consider an equal-power or other fade. The fade > system I have in Blue is based on the code from Ardour: > > https://github.com/kunstmusik/blue/blob/develop/blue-score-layers-audio-core/src/blue/score/layers/audio/core/blue_fade.udo > > transegr might be a good opcode to consider too. > > All best! > Steven > > On Sun, Jan 6, 2019 at 10:19 AM Anton Kholomiov > |