File: vector-cmp.c

package info (click to toggle)
audacity 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 86,844 kB
  • sloc: ansic: 225,005; cpp: 221,240; sh: 27,327; python: 16,896; makefile: 8,186; lisp: 8,002; perl: 317; xml: 307; sed: 16
file content (53 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* SoX Resampler Library      Copyright (c) 2007-13 robs@users.sourceforge.net
 * Licence for this file: LGPL v2.1                  See LICENCE for details. */

/* Utility used to help test the library; not for general consumption.
 *
 * Compare two swept-sine files.  */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../src/rint.h"

int main(int bit, char const * arg[])
{
  FILE    * f1       = fopen(arg[1], "rb"),
          * f2       = fopen(arg[2], "rb");
  double  rate       = atof (arg[3]), /* Rate for this vector */
          leader_len = atof (arg[4]), /* Leader length in seconds */
          len        = atof (arg[5]), /* Sweep length (excl. leader_len) */
          expect_bits= atof (arg[6]),
          expect_bw  = atof (arg[7]);

  int32_t s1, s2;
  long count = 0;
  static long thresh[32];
  double bw, prev = 0;

  for (; fread(&s1, sizeof(s1), 1, f1) == 1 &&
         fread(&s2, sizeof(s2), 1, f2) == 1; ++count) {
    long diff = abs((int)(s1 - s2));
    for (bit = 0; diff && bit < 32; bit++, diff >>= 1)
      if ((diff & 1) && !thresh[bit])
        thresh[bit] = count + 1;
  }

  if (count != (long)((leader_len + len) * rate + .5)) {
    printf("incorrect file length\n");
    exit(1);
  }

  for (bit = 0; bit < 32; ++bit) {
    bw = ((double)thresh[bit] - 1) / rate - leader_len;
    if (bit && bw >= 0 && (bw - prev) * 100 / len < .08) {
      --bit;
      break;
    }
    prev = bw;
  }
  bit = 32 - bit;
  bw = bw * 100 / len;
  printf("Bit perfect to %i bits, from DC to %.2f%% nyquist.\n", bit, bw);
  return !(bit >= expect_bits && bw >= expect_bw);
}