[Csnd] A-rate audio envelopes and switching two together

Hi, I’m trying to find a way to create two envelopes, one following directly after the other, without there being any discontinuities. So far, I’ve yet to figure out how to capture the current level of the first envelope, as it may stop at any point in it’s cycle, and then pass this value to the first input to the second envelope.

I am able to get both envelopes working at their proper time, but the first stage of the second seems to revert to 0.

Mike
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

can you send some code (preferably as simple as possible)?
otherwise it is not possible to say something.

  joachim

I’ll send something tonight after I get off work.

I’ve attached my simplified version of my instrument. But first, I should give a description.

I’m using Iain McCurdy’s model for a monophonic midi instrument, so basically I can’t use the ‘r’ envelope generators. I’d like to use an audio envelope because I will be using several of these oscillators to modulate things in various ways. I wave to compare it with the k-rate version.

I’ve used cabbage to run this, but it only takes a midi input, so I figure any way of running it should produce the same results.

Thanks,

Mike

simplified.csd (2.07 KB)

Hi
It is reverting to 0 like that due to
i(kCurr)
in the linseg only working when the instrument is initialised, and at that point kCurr will be 0 as the performance hasn’t started.

It may be possible to use the reinit opcode to re-initialise the instrument and get the value of kCurr into i-rate, but a quick test (simplified-1.csd attached) has a few quirks and for some reason the first note is never right.

In simplified-2.csd attached, the release linseg starts at 1 and is then multiplied by the last value from the unreleased envelope, similar to what is happening in the manual example for xtratim (https://csound.com/docs/manual/xtratim.html)), this sounds like it may be as you intend or point in the right direction.

all the best
RK

simplified-2.csd (2.31 KB)

simplified-1.csd (2.38 KB)

this sounds like a clever solution to me.
another way would be to encapsulate both envelopes in own instruments, and call/terminate them depending on the kReleased state.

  j

RIchard and Joachim,

Thank you for your replies. I’ll look into using a reinit cycle, they’ve always been a bit confusing for me, but I guess I get to dive in deep on this one…

Also, as I’m trying to make this an audio rate envelope, how do I get the last value of the audio buffer? Does ‘downsamp’ just take the first/last value of the audio buffer? Or is there another way of obtaining it?

Thanks.

Take a look at the linenv opcode:

It does exactly what you describe (download: )

<CsoundSynthesizer>
<CsOptions>
</CsOptions>

<CsInstruments>
sr     = 44100
ksmps  = 64
nchnls = 2
0dbfs  = 1

giLevels[] fillarray  0, 1,   .75, .25, .5, .3, .7, .4, 0
giRates[]  fillarray     .01, .1,  3,   4,  5,  1,  .8, 2

instr 1
  gkCPS = 1000
  kGate = 1
  ; close the gate after 10 seconds
  if timeinsts() >= 10 then
    kGate = 0
  endif
  ; 6 indicates that the segment number 6 is a sustain segment. The envelope stays
  ; at that value until the gate is closed. Whenever the gate is closed the envelope
  ; transitions to the release section (the segments after the sustain)
  aEnv linenv kGate, 6, giLevels[0], giRates[0], giLevels[1], giRates[1], giLevels[2],\
    giRates[2],giLevels[3], giRates[3], giLevels[4], giRates[4], giLevels[5], giRates[5], \
    giLevels[6], giRates[6], giLevels[7], giRates[7], giLevels[8]
  aSig poscil3, aEnv, gkCPS
  outch 1, aSig
endin

</CsInstruments>

<CsScore>
i1 0 30
</CsScore>
</CsoundSynthesizer>

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

this is how you can get the last sample in an audio buffer (here as example in the last k-cycle, but you can do it at any time):

<CsoundSynthesizer>
<CsOptions>
-m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
//print last value of audio buffer
//in last k-cycle
instr PrintAudio
  aSig poscil 1,444
  if release()==1 then
   kIndx = ksmps-1
   kLastSample = aSig[kIndx]
   printf "last (index=%d) sample in audio buffer = %f\n", 1, kIndx, kLastSample
  endif
endin
</CsInstruments>
<CsScore>
i "PrintAudio" 0 .01
</CsScore>
</CsoundSynthesizer>

best -
  joachim

Eduardo, thanks for the suggestion. I downloaded the plugins, and copied them to the Mac Library folder (as indicated by the readme), but they don’t seem to load properly. Is there something about plugins that I need to do special? Here is the error message returned…

–Csound version 6.16 (double samples) Jun 28 2021

[commit: 6b447b4361a40af7333033bb03b551e667327042]

libsndfile-1.0.28

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libjsfx.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libpathtools.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libfluidOpcodes.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libelse.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libstdutil.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libvirtual.dylib’ (-1)

WARNING: could not open library ‘/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/librtjack.dylib’ (-1)

WARNING: could not open library ‘/Users/mjmogo/Library/csound/6.0/plugins64/libjsfx.dylib’ (-1)

WARNING: could not open library ‘/Users/mjmogo/Library/csound/6.0/plugins64/libpathtools.dylib’ (-1)

WARNING: could not open library ‘/Users/mjmogo/Library/csound/6.0/plugins64/libelse.dylib’ (-1)

Thank you, Joachim. I will have to dig into this tomorrow.

Ok, it appears that I’ve got something to work using reinit, but it doesn’t always seem to work, as there are sometimes discontinuities at the release, it seems to happen more on longer held notes.

Also, as a side note, can reinit be used in an opcode? I would like to eventually encapsulate this into an opcode.

ARateEnv.csd (2.51 KB)

Thanks for testing - Which macOS version are you using? Did you install csound via the provided installer? I just checked in a clean installation in macOS Mojave and the latest packaged csound (6.16.2) works there with the latest provided package of the plugins (>= 1.8.0)

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

I don’t recall the exact number of my system, but I’m nowhere near current, I’ll get it tonight. My hardware is pretty much no longer supported by Apple. I installed CSound when I installed Cabbage. Rory mentioned some commandline options to set, but I’ve not had a change to try it yet. While I’ve made some great progress thanks to everyone here, it would be great if I could get the plugins working, that would be awesome!

Hi Eduardo,

I just checked, I’m on 10.13.6 High Sierra. I’ve been noticing more and more that my favorite open source projects are becoming more and more out of reach because Apple keeps limiting their support for anything from the Unix/Linux world. I’ve been wanting to install some version of Linux on one of my Mac’s, if only to continue to use what Apple says is now inferior… (Rant off…!)

I tried to use the --opcode-lib option, but it doesn’t seem to make a difference… I’m going to go with the fact that my system is no longer supported by Apple!

Eduardo, any suggestions on what to try next for the plugins?

You can try compiling from source. See installation instructions at the readme here: .

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here