FreeCalypso > hg > gsm-codec-lib
annotate miscutil/wav2raw.c @ 409:4184ccc136a3
libtwamr/typedef.h: drop Pfloat from EFR, not used in AMR
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 01:04:17 +0000 |
parents | 578fdedf4327 |
children |
rev | line source |
---|---|
142
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a 16-bit linear PCM speech recording in WAV format |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * and converts it to raw format, either BE or LE. |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "../libtest/wavreader.h" |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../libtest/wavrdhelp.h" |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int big_endian; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 void *wav; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 FILE *outf; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int16_t pcm[160], samp; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t bytes[320], *dp; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int cc, rc, i; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (argc != 4) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 usage: fprintf(stderr, "usage: %s input.wav output.raw be|le\n", |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 argv[0]); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (!strcmp(argv[3], "be")) |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 big_endian = 1; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 else if (!strcmp(argv[3], "le")) |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 big_endian = 0; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 else |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 goto usage; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 wav = wav_read_open(argv[1]); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!wav) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 perror(argv[1]); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rc = wavrd_check_header(wav, argv[1]); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (rc < 0) |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); /* error msg already printed */ |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 outf = fopen(argv[2], "w"); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (!outf) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 perror(argv[2]); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 exit(1); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 for (;;) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 cc = wavrd_get_pcm_block(wav, pcm); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (!cc) |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 break; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 dp = bytes; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (i = 0; i < cc; i++) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 samp = pcm[i]; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (big_endian) { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 *dp++ = (samp >> 8) & 0xFF; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 *dp++ = samp & 0xFF; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } else { |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 *dp++ = samp & 0xFF; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 *dp++ = (samp >> 8) & 0xFF; |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fwrite(bytes, 2, cc, outf); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fclose(outf); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(0); |
578fdedf4327
pcm16-wav2raw utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |