1 /*
2 t48_8_short.c
3 David Rowe
4 Dec 2021
5 */
6
7 #include <assert.h>
8 #include <math.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include "codec2_fdmdv.h"
12
13 #define N8 180 /* processing buffer size at 8 kHz */
14 #define N48 (N8*FDMDV_OS_48)
15 #define MEM8 FDMDV_OS_TAPS_48_8K
16 #define FRAMES 50
17 #define TWO_PI 6.283185307
18 #define FS 48000
19
20 #define SINE
21
main()22 int main() {
23 short in8k[MEM8+N8];
24 short out48k[N48];
25 FILE *f48;
26
27 short in48k[FDMDV_OS_TAPS_48K + N48];
28 short out8k[N48];
29 FILE *f8, *f8in;
30
31 int i,f,t,t1;
32 float freq = 800.0;
33
34 f48 = fopen("out48.raw", "wb");
35 assert(f48 != NULL);
36 f8 = fopen("out8.raw", "wb");
37 assert(f8 != NULL);
38 f8in = fopen("in8.raw", "wb");
39 assert(f8in != NULL);
40
41 /* clear filter memories */
42
43 for(i=0; i<MEM8; i++)
44 in8k[i] = 0.0;
45 for(i=0; i<FDMDV_OS_TAPS_48K; i++)
46 in48k[i] = 0.0;
47
48 t = t1 = 0;
49 for(f=0; f<FRAMES; f++) {
50
51 #ifdef DC
52 for(i=0; i<N8; i++)
53 in8k[MEM8+i] = 16000.0;
54 #endif
55 #ifdef SINE
56 for(i=0; i<N8; i++,t++)
57 in8k[MEM8+i] = 16000.0*cos(TWO_PI*t*freq/(FS/FDMDV_OS_48));
58 #endif
59 fwrite(&in8k[MEM8], sizeof(short), N8, f8in);
60
61 /* upsample */
62 fdmdv_8_to_48_short(out48k, &in8k[MEM8], N8);
63
64 /* save 48k to disk for plotting and check out */
65 fwrite(out48k, sizeof(short), N48, f48);
66
67 /* add a 10 kHz spurious signal for fun, we want down sampler to
68 knock this out */
69 for(i=0; i<N48; i++,t1++)
70 in48k[i+FDMDV_OS_TAPS_48K] = out48k[i] + 16000.0*cos(TWO_PI*t1*1E4/FS);
71
72 /* downsample */
73 fdmdv_48_to_8_short(out8k, &in48k[FDMDV_OS_TAPS_48K], N8);
74
75 /* save 8k to disk for plotting and check out */
76 fwrite(out8k, sizeof(short), N8, f8);
77 }
78
79 fclose(f48);
80 fclose(f8);
81 fclose(f8in);
82 return 0;
83
84 }
85