I have a piece I’m working on where I have a main instrument that runs for a while fires off a sequential series of either a sample-based instrument or an oscillator-based instrument. The sample files are of varied lengths. I don’t know until I load a file (or query it using filelen) how long it is, so I want the sample-playing instrument to be able to ensure that its duration is sufficient to play the entire sample before ending,
I can use xtratim for this, but I have a vague memory that people sometimes set the value of p4 within an instrument to change its duration. Does this work, and Is it a safe thing to do?
Hey Dave,
not sure I’m 100% getting the question but if you’re using a trigger instrument as your main instrument a simple if statement works inside the sample instr. Note in this example it doesn’t matter if schedkwhen duration is .1 or 10 seconds it still plays the full sample once like the traditional “one shot” setting in a sampler.
Also note the trigger instr is only set for 1 second, just too illustrate that no matter what the full sample will play.
Thanks, I corrected that error in a reply above. I do use the technique of launching instruments with duration of -1 and then stopping them later with a release envelope, but it requires a little more overhead (creating fractional instruments and keeping track of them) and it’s overkill for this particular application. I’ve tried both xtratrim and setting p3, and both solutions are working fine for me. I settled for xtratrim because I think it makes the intent of the code a bit clearer.
we all should do this step by step when we come across lacks or faults.
once you logged in to gihub, you can directly type your suggestion in the browser, and then send as pull request. in this case probably this page:
This is what I found after a lot of experience and experiments. There may be mistakes or more to learn. Please comment.
Handling standard score events, “note on” and “note off” events, and MIDI events in the same instrument definition is tricky.
For Csound instruments following my Silence pattern, MIDI inter-op command line options must be used: --midi-key=4 --midi-velocity=5.
For notes with indefinite durations, p1 must have a tag (ID), e.g. 1.036 for instrument 1. For “note on” messages, p3 must be negative, and normally is -1. For “note off” messages, p1 must be exactly the same as the p1 of the matching “note on” event, and p3 must be 0.
In the instrument definition, instruments with indefinite duration (whether from MIDI or from “note on” events), must not use p3 as a duration, e.g. for the sustain segment of an envelope, but rather create an i_sustain or i_decayvalue that is as long as makes sense for that instrument. That would be as long as possible for a sustained instrument, or the maximum reasonable decay for an emulation of a struck or plucked resonator.
The instrument should usually have a releasing envelope to get rid of clicks. The attack and release segments of this envelope should be continuous, as it is very easy to get clicks with short linear envelopes. This can be done using cossegr. The attack and release segments should be as long as necessary to mask unwanted artifacts, and this should be determined by experiment.
The “physical envelope” and the “declicking envelope” should be multiplied to produce a final envelope, and this should be low-pass filtered to blur as many discontinuities as possible. Filter cutoff and rolloff also should be determined by experiment.
The xtratim opcode should be used to carry the duration of the note well past the end of the release segment.
Some sounds have inherent discontinuities that can and will cause clicks. In particular aliasing can cause clicks.
For instruments requiring arbitrary delays or complex envelopes, setksmps 1 should be used.