drip

Files: drip.h, drip.c

Water drop physical model
Physical model of the sound of dripping water. When triggered, it will produce a droplet of water.

Functions

sp_drip_create(sp_drip **drip)
sp_drip_init(sp_data *sp, sp_drip *drip, SPFLOAT dettack)
sp_drip_compute(sp_data *sp, sp_drip *drip, SPFLOAT *trig, SPFLOAT *out)
sp_drip_destroy(sp_drip **drip)

Mandatory Parameters

dettack: Period of time over which all sound is stopped.
(Recommended value: 0.09)

Optional Parameters

num_tubes: Number of units.
(Default value: 10)
amp: Amplitude.
(Default value: 0.3)
damp: The damping factor. Maximum value is 2.0.
(Default value: 0.2)
shake_max: The amount of energy to add back into the system.
(Default value: 0)
freq: Main resonant frequency.
(Default value: 450)
freq1: The first resonant frequency.
(Default value: 600)
freq2: The second resonant frequency.
(Default value: 750)

Inputs

trig: Trigger value. When non-zero, it will re-init the drip and create a drip sound.

Outputs

out: Stereo left output for drip.

Example Code

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"

typedef struct {
    sp_drip *drip;
    sp_dust *trig;
    sp_revsc *rev;
} UserData;

void write_osc(sp_data *sp, void *ud) {
    UserData *udp = ud;
    SPFLOAT trig, rev1, rev2, drip;
    sp_dust_compute(sp, udp->trig, NULL, &trig);
    sp_drip_compute(sp, udp->drip, &trig, &drip);
    sp_revsc_compute(sp, udp->rev, &drip, &drip, &rev1, &rev2);
    sp->out[0] = drip + rev1 * 0.05;
}

int main() {
    srand(time(NULL));
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_revsc_create(&ud.rev);
    sp_drip_create(&ud.drip);
    sp_dust_create(&ud.trig);
    
    sp_dust_init(sp, ud.trig);
    ud.trig->amp = 1;
    ud.trig->density = 1;
    sp_drip_init(sp, ud.drip, 0.09);
    ud.drip->amp = 0.3;
    sp_revsc_init(sp, ud.rev);
    ud.rev->feedback = 0.9;
    
    sp->len = 44100 * 30;
    sp_process(sp, &ud, write_osc);
    sp_drip_destroy(&ud.drip);
    sp_dust_destroy(&ud.trig);
    sp_revsc_destroy(&ud.rev);
    sp_destroy(&sp);
    return 0;
}