File: raw2h.c

package info (click to toggle)
codec2 0.9.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,072 kB
  • sloc: ansic: 412,877; python: 4,004; sh: 1,540; objc: 817; asm: 683; makefile: 588
file content (45 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (3)
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
/*
  raw2h.c
  David Rowe
  10 April 2013

  Converts a raw sound file to a C header file.  Used for generating arrays to
  test Codec2 on embedded systems without disk I/O.
*/

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    FILE *fraw, *fheader;
    int   i, samples, ret;
    short sam;

    if (argc != 5) {
	printf("usage: %s inputRawFile outputHeaderFile arrayName samples\n", argv[0]);
	exit(1);
    }

    fraw = fopen(argv[1] ,"rb");
    assert(fraw != NULL);
    fheader = fopen(argv[2],"wt");
    assert(fheader != NULL);
    samples = atoi(argv[4]);

    fprintf(fheader, "short %s[] = {\n", argv[3]);
    for(i=0; i<samples-1; i++) {
	ret = fread(&sam, sizeof(short), 1, fraw);
        assert(ret == 1);
        fprintf(fheader, "%d,\n", sam);
    }
    ret = fread(&sam, sizeof(short), 1, fraw);
    assert(ret == 1);
    fprintf(fheader, "%d\n};\n", sam);

    fclose(fraw);
    fclose(fheader);

    return 0;
}