rtbaddout
INSTRUMENT design -- sample output-writing function
The rtbaddout() function is used in RTcmix
instrument design to write an array of generated samples
to the output buffer for audition or soundfile-writing.
It will write a block of samples corresponding to the
length argument of the function.
Typically rtbaddout is used
inside the INSTRUMENT::run() member function, but after
in the sample-computing loop (i.e. an array of samples needs to
be computed).
rtbaddout assumes that rtsetoutput()
was called in the INSTRUMENT::init() member function.
It replaces
the older baddout function used in
disk-only cmix.
Usage
int rtbaddout(float sample_array[], int length)
-
sample_array is the name of a float array used to store
an array of samples. This array needs to be set up properly for
mono or stereo (interleaved) output; i.e. if it is a 2-channel
array, the left and right channels should be interleaved
(ch0, ch1, ch0, ch1, ...) through the entire array.
For example, if the output were stereo, sample_array for
1024 sample would be declared like this:
float sample_array[2*1024];
where sample_array[0] would contain the first sample for the
left output channel, and sample_array[1] would contain
the first right output channel sample, sample_array[2] would contain
the second left output sample, sample_array[3] would hold
the second right output sample, etc.
length is the total number of samples in the array.
The rtbaddout()
function returns the number of samples written. See also the
rtaddout function.
Examples
#include <Instrument.h>
int MYINSTRUMENT::run()
{
float out[2*RTBUFSAMPS];
for (i = 0; i < framesToRun(); i++)
{
...
out[i*2] = leftchannelsample;
out[i*2+1] = rightchannelsample;
}
rtbaddout(out, 2*RTBUFSAMPS);
}
See Also