/* Reverse the audio file foo.wav and save it in bar.wav. * libsndfile example * Hans Fugal */ #include #include int main() { SF_INFO info; SNDFILE *input, *output; float *samples; int len, i; /* open input file */ input = sf_open("foo.wav", SFM_READ, &info); /* allocate buffer */ len = info.frames; samples = malloc(sizeof(float) * len); /* read in input file */ sf_read_float(input, samples, len); /* close the input file */ sf_close(input); /* open output file */ output = sf_open("bar.wav", SFM_WRITE, &info); /* write samples in reverse order to output file */ for (i=len-1; i>=0; i--) { sf_write_float(output, &samples[i], 1); } /* close output file */ sf_close(output); /* deallocate buffer */ free(samples); return 0; }