gogins / csound-ac

A C++ library for algorithmic composition, designed to be used with Csound, with both C++ and Python interfaces.
GNU Lesser General Public License v2.1
6 stars 0 forks source link

Best practices for Csound instruments #3

Closed gogins closed 2 years ago

gogins commented 2 years ago
gogins commented 2 years ago

Handling standard score events, "note on" and "note off" events, and MIDI events in the same instrument definition is tricky.

  1. For Csound instruments following my Silence pattern, MIDI inter-op command line options must be used: --midi-key=4 --midi-velocity=5.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. The xtratim opcode should be used to carry the duration of the note well past the end of the release segment.
  7. Some sounds have inherent discontinuities that can and will cause clicks. In particular aliasing can cause clicks.
  8. For instruments requiring arbitrary delays or complex envelopes, setksmps 1 should be used.
gogins commented 2 years ago

It's too much to go ahead and try to fix all my patches at once, and if I did, I would miss something. I am going to fix them as I use them and commit them back to csound-ac.

gogins commented 2 years ago

I need to isolate the effects of envelopes/declicking/deblock2 etc. I will do experiments using first a pure sine tone. All variants will be imported into Audacity at the same as separate tracks, and critical sections will be closely examined.

gogins commented 2 years ago
gogins commented 2 years ago

Strategy that works:

  1. Implement entire instrument.
  2. Record only the envelopes.
  3. Record the envelopes plus a signal that is just a sine tone.
  4. Record the actual instrument.
gogins commented 2 years ago

I can't get rid of all the clicks even with a sine tone. I am investigating if this has something to do with Apple or with Audacity. If necessary I will try some of these experiments on Linux. There is definitely a problem -- I hear these clicks even if I create tones in Audacity without using Csound at all. Maybe it has something to do with Bluetooth, so I will try headphones. Yes, it's Bluetooth. But then with USB audio I get a ground loop!!....

gogins commented 2 years ago

For now I'm using Bluetooth for ordinary work and studio monitor headphones for critical work.

gogins commented 2 years ago

What I'm looking for here is instruments usable for cloud-music, that is, no external dependencies. Some should have sharp attacks and a fairly long decay, others should be pads.

gogins commented 2 years ago

I have cleaned up all of these Csound instrument patches that do not have external dependencies such as Faust or plugins, and that therefore can be used with the WebAssembly build of Csound.

I have not touched effect patches.