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

Ocomb/Ocombi

INSTRUMENT design -- comb-filter (delay) objects

The Ocomb and Ocombi objects are used to build feedback delay lines known as "comb" filters. In fact, the Ocomb and Ocombi objects are essentially just wrappers for the Odelay and Odelayi objects. However, the parameters used to set and control the Ocomb and Ocombi objects are more convenient for many computer-music applications. Comb filter delays are used extensively in room-simulation and reverberation algorihms, and the effect has also figured prominently in many 'classic computer music pieces.

Ocomb is non-interpolating, so that requests for delay times that translate into a fractional point between two samples will be 'rounded' to the nearest sample value. This fractional delaying can happen quite often with dynamically-changing delay lines, which makes Ocombi probably a better choice in those cases. Shifting the delay time of Ocomb may result in audio "glitches" because of this round-off error, but these may be a desirable effect. Ocombi is slightly less efficient because of the interpolation math to calculate a fractional sample-point.

Ocomb and Ocombi replace the older CMIX comb and combset functions.


Constructors

    Ocomb(float SR, float loopTime, float reverbTime)

    SR is the current sampling rate (an Instrument class variable).
    loopTime is the delay time of the comb filter (in seconds).
    reverbTime is the length of time for the amplitude of samples to decay 60 dB (in seconds). This time should be > 0.0.


    Ocomb(float SR, float loopTime, float defaultLoopTime, float reverbTime, Odelay *del)

    SR is the current sampling rate (an Instrument class variable).
    loopTime is the initial delay time of the comb filter (in seconds).
    defaultLoopTime is the expected maximum delay of the filter filter (in seconds).
    reverbTime is the length of time for the amplitude of samples to decay 60 dB (in seconds). This time should be > 0.0.
    del is a pointer to an Odelay object. This is useful if you want to create and manage your own delay line for the filter. If this value is NULL then the constructor will allocate an internal Odelay object.


    Ocombi(float SR, float loopTime, float defaultLoopTime, float reverbTime)

    SR is the current sampling rate (an Instrument class variable).
    loopTime is the initial delay time of the comb filter (in seconds).
    defaultLoopTime is the expected maximum delay of the filter filter (in seconds).
    reverbTime is the length of time for the amplitude of samples to decay -60 dB (in seconds). This time should be > 0.0.



Access Methods

    void Ocomb::clear()
    void Ocombi::clear()

    will clear (fill with 0.0) the delay line.


    void Ocomb::setReverbTime(float reverbTime)
    void Ocombi::setReverbTime(float reverbTime)

    sets the time it takes for samples entering the comb filter delay line to decay -60 dB in amplitude. reverbTime is expressed in seconds. Internally it is used to set a regeneration multiplier to feed samples back into the delay line. The multiplier is calculated to give the desired decay time.


    float Ocomb::next(float input)
    float Ocombi::next(float input)

    returns a floating-point sample value from the recirculating comb filter delay line and places an incoming sample into the filter (input).


    float Ocomb::next(float input, float delaySamps)
    float Ocombi::next(float input, float delaySamps)

    returns a floating-point sample value from the recirculating comb filter delay line and places an incoming sample into the filter (input). The delaySamps variable will also resize the comb filter delay line. This is the mechanism used to dynamically change the 'sounding pitch' of the comb filter. Note that delaySamps is a floating-point number of samples. For Ocomb this is ignored (truncated), for Ocombi it is factored in to an interpolating delay. (see the setdelay methods for the Odelay and Odelayi objects).


    float Ocomb::frequency()
    float Ocombi::frequency()

    returns the current frequency of the comb filter, based upon the most recently set length of the delay line. The returned value is in Hz.


Examples

    #include <Ougens.h>
    
    Ocombi *comb;
    
    // this instrument has a delay line
    int MYINSTRUMENT::init(float p[], int n_args)
    {
    
    	...
    
    	comb = new Ocombi(SR, loopt, loopt, rvbtime);
    	if (comb->frequency() == 0.0)
    		return die("COMBIT", "Failed to allocate comb memory!");
    
    	...
    
    }
    
    int MYINSTRUMENT::run()
    {
    	float out[2];
    	float sample;
    
    	...
    
    	for (i = 0; i < framesToRun(); i++)
    	{
    		sample = someSampleGeneratingProcess();
    		out[0] = comb->next(sample);
    	}
    
    	...
    
    }