Ooscili
INSTRUMENT design -- wavetable and function-table interpolating oscillator object
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.
It can replace
the older oscili function used in previous
incarnations of RTcmix/cmix. It can also partially replace
the tablei array/table function used
for generating longer-span control envelopes. This cute trick is
accomplished by creating an Ooscili 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 access cyclically
at a rate determined by the frequency set for the Ooscili object.
Constructors
Ooscili(float freq, int arrnumber)
-
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 freq, float array[])
-
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 freq, float array[], int length)
-
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()
-
returns the next floating-point sample value from the wavetable or
function table array being oscillated.
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)
-
sets the frequency of the oscillator to freq Hz.
void Ooscili::setphase(float phase)
-
sets the phase of the oscillator to phase. phase is
the index number into the wavetable or function table array.
void Ooscili::getlength()
-
returns the length (in samples)
of the wavetable or function table array being
used by the Ooscili object.
void Ooscili::getdur()
-
returns the duration (in seconds) for one cycle
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();
}
...
}