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

Ooscil/Ooscili

INSTRUMENT design -- wavetable and function-table oscillator objects

The Ooscili object is an interpolating wavetable and function table unit generator used in RTcmix instrument design. What the heck does this mean? It's an oscillator. It oscillates. The thing that it oscillates is the wavetable or function table array. The slightly less-functional Ooscil object does pretty much the same thing except that it does not interpolate (except for the nexti method intended for use in special cases).

They can replace the older oscili and oscil functions used in previous incarnations of RTcmix/cmix. They can also partially replace the tablei and table and array/table functions used for generating longer-span control envelopes. This cute trick is accomplished by creating an Ooscili or Ooscil object with the frequency set to 1.0/dur where dur is the time-span of the control function.

The values returned by the Ooscili::next() method will be interpolated between points in the original wavetable/function table array. The wavetable/function table array will be accessed cyclically at a rate determined by the frequency set for the Ooscili object. Again, Ooscil does the same thing but no interpolation.


Constructors

    Ooscili(float SR, float freq, int arrnumber)

    SR is the current sampling rate (an Instrument class variable).
    freq is the frequency of the oscillator in Hz.
    arrnumber is the number of the function/wavetable array specified and constructed by the makegen directive in the score.


    Ooscili(float SR, float freq, double array[])

    SR is the current sampling rate (an Instrument class variable).
    freq is the frequency of the oscillator in Hz.
    array is the name (pointer) to an array that will be used by the Ooscil object for wavetable or function table lookups.


    Ooscili(float SR, float freq, double array[], int length)
    Ooscil(float SR, float freq, double array[], int length)

    SR is the current sampling rate (an Instrument class variable).
    freq is the frequency of the oscillator in Hz.
    array is the name (pointer) to an array that will be used by the Ooscil object for wavetable or function table lookups.
    length is the length of the array to use. Generally this will be identical to the actual length of the array, but occasionally only a portion of array may be desired.



Access Methods

    float Ooscili::next()
    float Ooscil::next()
    float Ooscil::nexti()

    returns the next floating-point sample value from the wavetable or function table array being oscillated.

    The nexti method for the Ooscil object will interpolate sample values like Ooscili always does. For most interpolation situations, Ooscili is a better choice.



    float Ooscili::next(sample_number)

    returns a floating-point sample value, but this method is intended for when the Ooscili object is used as an envelope or control signal generator. This is done by setting the frequency of oscillation to 1.0/duration, where the duration is the length of time for the envelope or control signal. The "oscillator" in this case will only scan through the wavetable or function table array once for the total duration. sample_number allows the lookup of values along the control signal or envelope without having to call the Ooscili::next() method for every sample synthesized.


    void Ooscili::setfreq(float freq)
    void Ooscil::setfreq(float freq)

    sets the frequency of the oscillator to freq Hz.


    void Ooscili::setphase(double phase)
    void Ooscil::setphase(double phase)

    sets the phase of the oscillator to phase. phase is the index number into the wavetable or function table array.


    int Ooscili::getlength()
    int Ooscil::getlength()

    returns the length (in samples) of the wavetable or function table array being used by the Ooscili object.

Examples

used as an oscillator:
    #include <Ougens.h>
    
    Ooscili *theOscil;
    
    int MYINSTRUMENT::init(float p[], int n_args)
    {
    
    	...
    
    	theOscil = new Ooscili(freq, 2); // assumes makegen 2 for waveform
    
    	...
    
    }
    
    int MYINSTRUMENT::run()
    {
    	float out[2];
    
    	...
    
    	for (i = 0; i < framesToRun(); i++)
    	{
    		out[0] = theOscil->next();
    	}
    
    	...
    
    }
    

used as an envelope or control signal generator:
    #include <Ougens.h>
    
    Ooscili *theEnv;
    
    int resetsamps, resetcount;
    
    int MYINSTRUMENT::init(float p[], int n_args)
    {
    	float dur;
    
    	dur = p[2];
    
    	...
    
    	theEnv = new Ooscili(1.0/dur, 1); // assumes makegen 1 for envelope
    	resetsamps = 100; // update the envelope only once every 100 samps
    	resetcount = 0;
    
    	...
    
    }
    
    int MYINSTRUMENT::run()
    {
    	float out[2];
    	float amp;
    
    	...
    
    	for (i = 0; i < framesToRun(); i++)
    	{
    		if (resetcount >= resetsamps)  // update the envelope
    		{
    			amp = theEnv->next(currentFrame());
    			resetcount = 0;
    		}
    
    		increment();
    	}
    
    	...
    
    }