-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtables.m
128 lines (113 loc) · 2.64 KB
/
tables.m
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/octave -qf
pkg load signal;
%---------------------------------------------------------------
HEADER = "\
/*\n\
*/\n\
\n\
#define VOLSTEPS\t\t\t%d\n\
extern const float scale[VOLSTEPS];\n\
extern const int16_t db[VOLSTEPS];\n\
\n\
#define NUMTAPS_SR\t\t\t%d\n\
#define UPSAMPLE_SHIFT_SR\t\t%d\n\
extern const float hc_sr[NUMTAPS_SR];\n\
\n\
#define NUMTAPS_DR\t\t\t%d\n\
#define UPSAMPLE_SHIFT_DR\t\t%d\n\
extern const float hc_dr[NUMTAPS_DR];\n\
\n\
";
BODY = "\
/*\n\
*/\n\
\n\
#include <stdint.h>\n\
\n\
const float scale[] = {\n\
%s\
};\n\
\n\
const int16_t db[] = {\n\
%s\
};\n\
\n\
const float hc_sr[] = {\n\
%s\
};\n\
\n\
const float hc_dr[] = {\n\
%s\
};\n\
\n\
";
%---------------------------------------------------------------
function o = retap(u, v)
o = [];
n = length(v);
ph = n / u;
for i = [u:-1:1]
t = i;
for k = [ph:-1:1]
o = [o, v(t)]; t = t + u;
endfor
endfor
endfunction
function s = carray(v)
s = sprintf(["\t%.8ff,\n"], v);
endfunction
function s = sfir(e, n)
f = 2^e;
s = carray(retap(f, f * fir1(n-1, 1/f)));
endfunction
function s = sample(n, fs)
s = carray(sin(2*pi*[0:n-1]*1000/fs));
endfunction
%---------------------------------------------------------------
VOLSTEPS=61;
ATTN = 10^(-3/20);
function x = db(x)
x = 20 * log10(x);
endfunction
function x = vol(x)
x = exp(log(1000) * x) / 1000;
endfunction
VOL = vol([1:-1/(VOLSTEPS-1):0]);
%---------------------------------------------------------------
NUMTAPS_SR = 48;
NUMTAPS_DR = 24;
UPSAMPLE_SHIFT_SR = 3;
UPSAMPLE_SHIFT_DR = 2;
% ---------------------------------------
% UPSAMPLE : NUMTAPS : PHASELEN : BACKLOG
% ---------------------------------------
% 8 : 16 : 2 : 2
% 16 : 32 : 2 : 2
% ---------------------------------------
% 8 : 24 : 3 : 4
% 16 : 48 : 3 : 4
% ---------------------------------------
% 8 : 32 : 4 : 6
% 16 : 64 : 4 : 6
% ---------------------------------------
% 8 : 48 : 6 : 10
% 16 : 96 : 6 : 10
% ---------------------------------------
av = argv();
switch (substr(av{1}, -1))
case "h"
fd = fopen(av{1}, "w");
fprintf(fd, HEADER,
VOLSTEPS,
NUMTAPS_SR, UPSAMPLE_SHIFT_SR,
NUMTAPS_DR, UPSAMPLE_SHIFT_DR);
fclose(fd);
case "c"
fd = fopen(av{1}, "w");
fprintf(fd, BODY,
carray(VOL),
sprintf(["\t%8d,\n"], fix(256 * db(VOL))),
sfir(UPSAMPLE_SHIFT_SR,NUMTAPS_SR),
sfir(UPSAMPLE_SHIFT_DR,NUMTAPS_DR));
fclose(fd);
endswitch