1
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
2
* Licence for this file: LGPL v2.1 See LICENCE for details. */
4
/* Example 1a: Variant of example 1 using libsamplerate-like bindings. */
7
#include "examples-common.h"
9
float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
10
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1,
11
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1};
13
int main(int argc, char const * arg[])
15
double irate = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
16
double orate = argc > 2? atof(arg[2]) : 2; /* by a factor of 2. */
18
size_t olen = (size_t)(AL(in) * orate / irate + .5); /* Assay output len. */
19
float * out = (float *)malloc(sizeof(*out) * olen); /* Allocate output buf. */
26
data.input_frames = AL(in);
27
data.output_frames = (int)olen;
28
data.src_ratio = orate / irate;
29
error = src_simple(&data, SRC_SINC_FASTEST, 1);
31
while (i++ < data.output_frames_gen) /* Print out the resampled data, */
32
printf("%5.2f%c", out[i-1], " \n"[!(i&7) || i == data.output_frames_gen]);
33
printf("%-26s %s\n", arg[0], src_strerror(error)); /* and reported result. */
35
free(out); /* Tidy up. */