Files: nsmp.h, nsmp.c

Nanosamp: a tiny sampler built for Soundpipe
A nanosamp file is comprised of a mono audio file and an ini file. Nanosamp is geared towards percussive and found sound sample players, and is intended to be combined with soundpipe modules.
The ini file contains mappings that correspond to the audio file. Such an entry would look like this:

pos = 2.3
size = 3
In this instance, an entry called "keyword" has been made, starting at 2.3 seconds in the audio file, with a length of 3 seconds. An example file oneart.ini has been created in the examples folder.
The SoundPipe implementation of nanosamp will automatically index the entries in the order they appear in the INI file and must be selected this way by changing the index parameter. Soundpipe will only select the new entry when the trigger input is a non-zero value.


sp_nsmp_create(sp_nsmp **nsmp)
sp_nsmp_init(sp_data *sp, sp_nsmp *nsmp, sp_ftbl*ft, int sr, const char*init)
sp_nsmp_compute(sp_data *sp, sp_nsmp *nsmp, SPFLOAT *trigger, SPFLOAT *signal out)
sp_nsmp_destroy(sp_nsmp **nsmp)

Mandatory Parameters

ft: ftbl of the audio file. It should be mono.
(Recommended value: N/A)
sr: samplerate.
(Recommended value: N/A)
init: ini file.
(Recommended value: N/A)

Optional Parameters

index: This is an optional parameter. These values are always set to a value by default, and can be set after the init function has been called.
(Default value: 0)


trigger: Trigger input.


signal out: Signal output.

Other Functions:

sp_nsmp_print_index(sp_data *sp, sp_nsmp *nsmp)
Prints the index and their corresponding keyword

Example Code

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

typedef struct {
    sp_metro *met;
    sp_nsmp *nsmp;
    sp_ftbl *ft;
} UserData;

void process(sp_data *sp, void *udata) {
    UserData *ud = udata;
    SPFLOAT met = 0, nsmp = 0;
    sp_metro_compute(sp, ud->met, NULL, &met);
    if(met) {
        ud->nsmp->index = rand() % 3;
    sp_nsmp_compute(sp, ud->nsmp, &met, &nsmp);
    sp->out[0] = nsmp;

int main() {
    UserData ud;
    sp_data *sp;

    sp_ftbl_loadfile(sp, &ud.ft, "oneart.wav");

    sp_metro_init(sp, ud.met);
    ud.met->freq = 2;
    sp_nsmp_init(sp, ud.nsmp, ud.ft, 44100, "oneart.ini");

    sp_nsmp_print_index(sp, ud.nsmp);

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



    return 0;