Hello, I have written a very basic VST host that will play a MIDI file to a WAV. It currently renders one or all tracks with one instrument. I would like to be able to render multiple instruments but I’m not sure what the next step is.
Two ideas occur to me:
I could setup my instruments as a chain, passing silence into the first instrument, the result of instrument 1 into instrument 2 (processReplacing), …, to instrument N
I could separately process each instrument and somehow mux the streams.
Both require a fair amount of work so I am hoping for a pointer or two before I dive in.
When I started, it was very confusing to me how to handle more than one track/instrument (or “mux” if I understand how you call it), but in the end it turns out to be very simple. You simply add (mathematic sum) each instruments…
…and by “adding” it is literally adding (+) each sample with each other and write the result to the buffers provided
I do not know all the requirements of your design but sounds to me like solution 2 would be a lot easier to implement.
Also as a side note, you mention “processReplacing” which I believe is a VST2 concept. Steinberg officially ended VST2 back in October 2018 so I would suggest looking at VST3 instead.
Audio programming is pretty new to me so please excuse any dumb questions … but regarding adding the samples I was worried about limits. Say if two instruments give a value of 1 on a frame, that would sum to two. Then I would clamp that value … would that result in clipping?
I guess the only real way to know is to try it!
And regarding processReplacing, I thought that was the new function to call. But I’m kind of guessing my way through, if you can point to some documentation around this I would really appreciate it.
I would not suggest clamping. The sum is the sum. I agree with you it seems that it is going to be reaching > 1 very quickly but remember that if you sum a bunch of instruments, what matters is the sum of ALL of them. For example, if you have a plugin that generates a sine wave varying between +2 and -2 and another plugin that generates a sine wave in opposite phase (varying between -2 and +2), each plugin is obviously going beyond +1, but the sum of those 2 plugins will be total silence!
If that becomes an issue, I would suggest adding gain knobs for your instruments so that the USER (not the software) can lower/raise each instrument according to what sounds “right” and not a hard mathematical formula (clamp).
I would suggest reading the documentation that comes with the SDK (index.html at the root).
Also, and this is personal promotion , I would suggest looking at Jamba (GitHub - pongasoft/jamba: A lightweight VST2/3 framework) a framework I am developing to help in writing VST3 (as well as VST2 wrapper and Audio Unit wrapper) plugins. Especially when you start, you can create a fully working plugin with a simple command line (vs copy/paste/scratch your head to figure out what to change with the plain VST SDK).