delaylib

    delaylib is a library designed to delay the output signal against the input signal. The delay is implemented with a simple circular buffer. The algorithm is as follows. First, enough memory is allocated to hold the necessary number of samples. A pointer is set to the start of the delayline. The value is read for each sample in the delayline to pass to the output, and then the current input sample is written. Then the pointer to the next location in the delayline is incremented. If the pointer reaches the end of the allocated space, it is set to the first memory location.

CONTENTS

SYNOPSIS  Return Error String Function  Delay Function  EXAMPLE

SYNOPSIS

The functions of delaylib are defined as follows:

    char *return_error_string(int error_code);

    double *delay( double *input,
                            int input_length,
                            double d_time,
                            DelayBuffer *d,
                            minmax extr,
                            int *output_length,
                            int *error_code );

Return Error String Function

    char *return_error_string(int error_code);

This function returns the error string which is defined by the error_code value.

Delay Function

    double *delay( double *input,
                            int input_length,
                            double d_time,
                            DelayBuffer *d,
                            minmax extr,
                            int *output_length,
                            int *error_code );

The DelayBuffer structure is made to remember delayed samples. This defines structure of the circle buffer:

    typedef struct {
        double *delayLineStart;
        double *delayLineEnd;
        double *delayReadPtr;
    } DelayBuffer;

The minmax structure defines the maximal and minimal values the signal can have:

    typedef struct {
        double max;
        double min;
    } minmax;

Input parameters:
double *input is the input signal. That must be a simple array with real values. The samples of the signal     must be lined up so, that the first sample is the oldest one.
int input_length is the length of the input array. If this value is equal to 0, no samples from input are read, and the function returns the rest of the delayed samples in the buffer.
double d_time is the value that determines number of samples that should delay the output signal. If this value was negative, the output signal is shifted forward in time.
DelayBuffer *d saves capacity of the circle buffer.
minmax extr is the structure that contains the minimal and maximal allowed values of the signal.
int *output_length is the length (number of samples) of the output signal.
int *error_code is the error code. If this value was zero, no error has fallen.

On success, the delay function returns a non NULL pointer which points to a new allocated buffer, that contains the delayed output signal.On fail, the delay function returns a NULL pointer.

EXAMPLE

    long double audiodata[10];
    long double *audioout = NULL;
    minmax extr;
    long int o_l;
    int err;
    DelayBuffer delbuf;
    delbuf.delayLineStart = NULL;

    /*delay input signal for two samples*/
    audioout = delay(audiodata,10,2,&delbuf,extr,&o_l,&err);
    /*return rest of the delayed samples in circle buffer*/
    audioout = delay(audiodata,0,2,&delbuf,extr,&o_l,&err);