This is example2.c in view mode; [Download] [Up]
/* * FILE: example2.c * BY: Christopher Lee Fraley * DESC: An example of a function which takes a sound and an integer as input, * and returns a sound. * * 1.0 ( 3-JUN-89) - created. (clf) */ #include <math.h> #include "xlisp.h" #include "sound.h" SoundPtr round(sound, k) SoundPtr sound; int k; { SoundPtr val; SDataPtr data; int len, newLen; double newSrate; int i; /* Must flatten sound before I can access its samples: */ (void)s_flatten(sound); len = sound->ptr.sample->length; /* Let's create the return value: */ val = s_create(); newLen = len; /* Make return sound the same length as input sound */ newSrate = sound->srate; /* Make val have same srate as input sound */ data = sdata_create(newLen); val->ptr.sample = spl_create(data, newLen, newSrate); val->tag = SAMPLES; val->to = val->logicalTo = newLen / newSrate; val->srate = newSrate; val->shift = sound->shift; for (i=0; i<len && i<newLen; i++) { /* Put your own calculations here, for example: */ val->ptr.sample->data[i] = floor(sound->ptr.sample->data[i] / k) * k; } return (val); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.