annotate libtest/wavrdhelp.c @ 50:9ae58ffb4197

libgsmefr/cnst.h: add DTX_HANGOVER definition, needed for encoder and decoder state structures
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 06:39:10 +0000
parents 30d1d0a705c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our helper functions
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * on top of the basic WAV reader.
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "wavreader.h"
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "wavrdhelp.h"
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 int wavrd_check_header(void *wav, const char *filename)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int format, sampleRate, channels, bitsPerSample;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 if (!wav_get_header(wav, &format, &channels, &sampleRate,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 &bitsPerSample, NULL)) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 fprintf(stderr, "error: %s is not a valid WAV file\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 filename);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (format != 1) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 fprintf(stderr, "error: %s has unsupported WAV format %d\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 filename, format);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (bitsPerSample != 16) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fprintf(stderr,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 "error: %s has unsupported WAV sample depth %d\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 filename, bitsPerSample);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (channels != 1) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr, "error: %s has %d channels, need 1\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 filename, channels);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (sampleRate != 8000) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fprintf(stderr,
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 "error: %s has %d Hz sample rate, need 8000 Hz\n",
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 filename, sampleRate);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return -1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return 0;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 int wavrd_get_pcm_block(void *wav, int16_t *pcm)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 uint8_t bytes[320], *dp;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 int cc, i;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 cc = wav_read_data(wav, bytes, 320);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 cc >>= 1;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 dp = bytes;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (i = 0; i < cc; i++) {
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 pcm[i] = dp[0] | (dp[1] << 8);
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 dp += 2;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 while (i < 160)
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 pcm[i++] = 0;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return cc;
30d1d0a705c0 libtest: add WAV reader helper functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }