wavout

Files: wavout.h, wavout.c

Writes a mono signal to a WAV file. This module uses the public-domain dr_wav library to write WAV files to disk. This module is ideal for instances where GPL-licensed libsndfile cannot be used for legal reasons.

Functions

sp_wavout_create(sp_wavout **wavout)
sp_wavout_init(sp_data *sp, sp_wavout *wavout, const char*filename)
sp_wavout_compute(sp_data *sp, sp_wavout *wavout, SPFLOAT *input, SPFLOAT *out)
sp_wavout_destroy(sp_wavout **wavout)

Mandatory Parameters

filename: The filename of the output file.
(Recommended value: N/A)

Inputs

input: Mono input signal.

Outputs

out: A passthrough signal: a copy of the input signal.

Example Code

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

typedef struct {
    sp_wavout *wavout;
    sp_osc *osc;
    sp_ftbl *ft; 
} UserData;

void process(sp_data *sp, void *udata) {
    UserData *ud = udata;
    SPFLOAT osc = 0, wavout = 0;
    sp_osc_compute(sp, ud->osc, NULL, &osc);
    sp_wavout_compute(sp, ud->wavout, &osc, &wavout);
    sp->out[0] = wavout;
}

int main() {
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_srand(sp, 1234567);

    sp_wavout_create(&ud.wavout);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 2048);

    sp_wavout_init(sp, ud.wavout, "wavout.wav");
    sp_gen_sine(sp, ud.ft);
    sp_osc_init(sp, ud.osc, ud.ft, 0);

    sp->len = 44100 * 5;
    sp_process(sp, &ud, process);

    printf("file wavout.wav written to disk.\n");
    sp_wavout_destroy(&ud.wavout);
    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);

    sp_destroy(&sp);
    return 0;
}