~ubuntu-branches/ubuntu/trusty/libsoxr/trusty

« back to all changes in this revision

Viewing changes to examples/1a-lsr.c

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2013-01-19 13:59:15 UTC
  • Revision ID: package-import@ubuntu.com-20130119135915-ig85015j5zwtf0rp
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SoX Resampler Library      Copyright (c) 2007-13 robs@users.sourceforge.net
 
2
 * Licence for this file: LGPL v2.1                  See LICENCE for details. */
 
3
 
 
4
/* Example 1a: Variant of example 1 using libsamplerate-like bindings. */
 
5
 
 
6
#include <soxr-lsr.h>
 
7
#include "examples-common.h"
 
8
 
 
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};
 
12
 
 
13
int main(int argc, char const * arg[])
 
14
{
 
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. */
 
17
 
 
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. */
 
20
 
 
21
  int error, i = 0;
 
22
  SRC_DATA data;
 
23
 
 
24
  data.data_in = in;
 
25
  data.data_out = out;
 
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);
 
30
 
 
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. */
 
34
 
 
35
  free(out);                                                      /* Tidy up. */
 
36
  return !!error;
 
37
}