File: t48_8_short.c

package info (click to toggle)
codec2 1.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 121,056 kB
  • sloc: ansic: 414,118; sh: 2,612; objc: 2,574; python: 2,105; cpp: 2,091; asm: 683; makefile: 598
file content (84 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
   t48_8_short.c
   David Rowe
   Dec 2021
*/

#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "codec2_fdmdv.h"

#define N8         180        /* processing buffer size at 8 kHz */
#define N48        (N8*FDMDV_OS_48)
#define MEM8       FDMDV_OS_TAPS_48_8K
#define FRAMES     50
#define TWO_PI     6.283185307
#define FS         48000

#define SINE

int main() {
    short in8k[MEM8+N8];
    short out48k[N48];
    FILE *f48;

    short in48k[FDMDV_OS_TAPS_48K + N48];
    short out8k[N48];
    FILE *f8, *f8in;

    int i,f,t,t1;
    float freq = 800.0;

    f48 = fopen("out48.raw", "wb");
    assert(f48 != NULL);
    f8 = fopen("out8.raw", "wb");
    assert(f8 != NULL);
    f8in = fopen("in8.raw", "wb");
    assert(f8in != NULL);

    /* clear filter memories */

    for(i=0; i<MEM8; i++)
	in8k[i] = 0.0;
    for(i=0; i<FDMDV_OS_TAPS_48K; i++)
	in48k[i] = 0.0;

    t = t1 = 0;
    for(f=0; f<FRAMES; f++) {

#ifdef DC
	for(i=0; i<N8; i++)
	    in8k[MEM8+i] = 16000.0;
#endif
#ifdef SINE
	for(i=0; i<N8; i++,t++)
	    in8k[MEM8+i] = 16000.0*cos(TWO_PI*t*freq/(FS/FDMDV_OS_48));
#endif
	fwrite(&in8k[MEM8], sizeof(short), N8, f8in);

	/* upsample  */
	fdmdv_8_to_48_short(out48k, &in8k[MEM8], N8);

	/* save 48k to disk for plotting and check out */
	fwrite(out48k, sizeof(short), N48, f48);

	/* add a 10 kHz spurious signal for fun, we want down sampler to
	   knock this out */
	for(i=0; i<N48; i++,t1++)
	    in48k[i+FDMDV_OS_TAPS_48K] = out48k[i] + 16000.0*cos(TWO_PI*t1*1E4/FS);

	/* downsample */
	fdmdv_48_to_8_short(out8k, &in48k[FDMDV_OS_TAPS_48K], N8);

	/* save 8k to disk for plotting and check out */
	fwrite(out8k, sizeof(short), N8, f8);
    }

    fclose(f48);
    fclose(f8);
    fclose(f8in);
    return 0;

}