an open-source digital signal processing and sound synthesis language
about · links · contact

rtaddout

INSTRUMENT design -- sample output-writing function

The rtaddout() function is used in RTcmix instrument design to write one frame of generated samples to the output buffer for hearing or soundfile-writing. It will write the appropriate number of channels depending on the value of the INSTRUMENT variable outputchans (see the Instrument listing for more information about INSTRUMENT variables).

Typically rtaddout is used in the sample-computing loop inside the INSTRUMENT::run() member function. rtaddout assumes that rtsetoutput() was called in the INSTRUMENT::init() member function.

It replaces the older ADDOUT macro used in disk-only cmix.


Usage

    int rtaddout(float frame_array[])

    frame_array is the name of a float array used to store a frame of samples. A "frame" contains samples for each output channel, thus frame_array will have only one element for mono output, two for stereo, four for quad, etc.

    For example, if the output were stereo, frame_array would be declared like this:

      float frame_array[2];
    where frame_array[0] would contain the sample for the left output channel, and frame_array[1] would contain the right output channel sample.

    The rtaddout() function returns the number of channels of the output.

Examples

    #include <Instrument.h>
    
    int MYINSTRUMENT::run()
    {
    	float out[2];
    
    	for (i = 0; i < framesToRun(); i++)
    	{
    		...
    
    		out[0] = leftchannelsample;
    		out[1] = rightchannelsample;
    
    		rtaddout(out);
    	}
    }
    


See Also