1 /*
2 t48_8.c
3 David Rowe
4 May 10 2012
5
6 Unit test for 48 to 8 kHz sample rate conversion functions. I
7 evaluated output by plotting using Octave and looking for jaggies:
8
9 pl("../unittest/out48.raw",1,3000)
10 pl("../unittest/out8.raw",1,3000)
11
12 Listening to it also shows up anything nasty:
13
14 $ play -s -2 -r 48000 out48.raw
15 $ play -s -2 -r 8000 out8.raw
16
17 */
18
19 #include <assert.h>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "codec2_fdmdv.h"
24
25 #define N8 180 /* processing buffer size at 8 kHz */
26 #define N48 (N8*FDMDV_OS_48)
27 #define MEM8 FDMDV_OS_TAPS_48_8K
28 #define FRAMES 50
29 #define TWO_PI 6.283185307
30 #define FS 48000
31
32 #define SINE
33
main()34 int main() {
35 float in8k[MEM8 + N8];
36 short in8k_short[N8];
37 float out48k[N48];
38 short out48k_short[N48];
39 FILE *f48;
40
41 float in48k[FDMDV_OS_TAPS_48K + N48];
42 float out8k[N48];
43 short out8k_short[N8];
44 FILE *f8, *f8in;
45
46 int i,f,t,t1;
47 float freq = 800.0;
48
49 f48 = fopen("out48.raw", "wb");
50 assert(f48 != NULL);
51 f8 = fopen("out8.raw", "wb");
52 assert(f8 != NULL);
53 f8in = fopen("in8.raw", "wb");
54 assert(f8in != NULL);
55
56 /* clear filter memories */
57
58 for(i=0; i<MEM8; i++)
59 in8k[i] = 0.0;
60 for(i=0; i<FDMDV_OS_TAPS_48K; i++)
61 in48k[i] = 0.0;
62
63 t = t1 = 0;
64 for(f=0; f<FRAMES; f++) {
65
66 #ifdef DC
67 for(i=0; i<N8; i++)
68 in8k[MEM8+i] = 16000.0;
69 #endif
70 #ifdef SINE
71 for(i=0; i<N8; i++,t++)
72 in8k[MEM8+i] = 16000.0*cos(TWO_PI*t*freq/(FS/FDMDV_OS_48));
73 #endif
74 for(i=0; i<N8; i++)
75 in8k_short[i] = (short)in8k[i];
76 fwrite(in8k_short, sizeof(short), N8, f8in);
77
78 /* upsample */
79
80 fdmdv_8_to_48(out48k, &in8k[MEM8], N8);
81
82 /* save 48k to disk for plotting and check out */
83
84 for(i=0; i<N48; i++)
85 out48k_short[i] = (short)out48k[i];
86 fwrite(out48k_short, sizeof(short), N48, f48);
87
88 /* add a 10 kHz spurious signal for fun, we want down sampler to
89 knock this out */
90
91 for(i=0; i<N48; i++,t1++)
92 in48k[i+FDMDV_OS_TAPS_48K] = out48k[i] + 16000.0*cos(TWO_PI*t1*1E4/FS);
93
94 /* downsample */
95
96 fdmdv_48_to_8(out8k, &in48k[FDMDV_OS_TAPS_48K], N8);
97
98 /* save 8k to disk for plotting and check out */
99
100 for(i=0; i<N8; i++)
101 out8k_short[i] = (short)out8k[i];
102 fwrite(out8k_short, sizeof(short), N8, f8);
103
104 }
105
106 fclose(f48);
107 fclose(f8);
108 fclose(f8in);
109 return 0;
110
111 }
112