in

Files: in.h, in.c

Reads from standard input.
Expects type of SPFLOAT, which by default is a float. If the input data is larger than the number of samples, you will get a complaint about a broken pipe (but it will still work). If there is no input data from STDIN, it will hang.

The expected use case of sp_in is to utilize pipes from the commandline, like so:

cat /dev/urandom | ./my_program

Assuming my_program is using sp_in, this will write /dev/urandom (essentially white noise) to an audio file.

Functions

sp_in_create(sp_in **in)
sp_in_init(sp_data *sp, sp_in *in)
sp_in_compute(sp_data *sp, sp_in *in, SPFLOAT *dummy, SPFLOAT *out)
sp_in_destroy(sp_in **in)

Outputs

out: Signal output.

Example Code

/*
 * This module reads from standard input, and writes it to a wave file.
 * 
 * To write 5 seconds of white noise:
 *
 * cat /dev/urandom | ./ex_in.bin
 *
 */

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

typedef struct {
    sp_in *in;
} UserData;

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

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

    sp_in_create(&ud.in);

    sp_in_init(sp, ud.in);

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

    sp_in_destroy(&ud.in);

    sp_destroy(&sp);
    return 0;
}