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
30void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
31 size_t *isamp, size_t *osamp)
32{
33 struct rate *rate = opaque;
34 struct st_sample *istart, *iend;
35 struct st_sample *ostart, *oend;
36 struct st_sample ilast, icur, out;
37#ifdef FLOAT_MIXENG
38 mixeng_real t;
39#else
40 int64_t t;
41#endif
42
43 istart = ibuf;
44 iend = ibuf + *isamp;
45
46 ostart = obuf;
47 oend = obuf + *osamp;
48
49 if (rate->opos_inc == (1ULL + UINT_MAX)) {
50 int i, n = *isamp > *osamp ? *osamp : *isamp;
51 for (i = 0; i < n; i++) {
52 OP (obuf[i].l, ibuf[i].l);
53 OP (obuf[i].r, ibuf[i].r);
54 }
55 *isamp = n;
56 *osamp = n;
57 return;
58 }
59
60
61 if (ibuf >= iend) {
62 *osamp = 0;
63 return;
64 }
65
66 ilast = rate->ilast;
67
68 while (true) {
69
70
71 while (rate->ipos <= (rate->opos >> 32)) {
72 ilast = *ibuf++;
73 rate->ipos++;
74
75
76 if (ibuf >= iend) {
77 goto the_end;
78 }
79 }
80
81
82 if (obuf >= oend) {
83 break;
84 }
85
86 icur = *ibuf;
87
88
89 if (rate->ipos >= 0x10001) {
90 rate->ipos = 1;
91 rate->opos &= 0xffffffff;
92 }
93
94
95#ifdef FLOAT_MIXENG
96#ifdef RECIPROCAL
97 t = (rate->opos & UINT_MAX) * (1.f / UINT_MAX);
98#else
99 t = (rate->opos & UINT_MAX) / (mixeng_real) UINT_MAX;
100#endif
101 out.l = (ilast.l * (1.0 - t)) + icur.l * t;
102 out.r = (ilast.r * (1.0 - t)) + icur.r * t;
103#else
104 t = rate->opos & 0xffffffff;
105 out.l = (ilast.l * ((int64_t) UINT_MAX - t) + icur.l * t) >> 32;
106 out.r = (ilast.r * ((int64_t) UINT_MAX - t) + icur.r * t) >> 32;
107#endif
108
109
110 OP (obuf->l, out.l);
111 OP (obuf->r, out.r);
112 obuf += 1;
113 rate->opos += rate->opos_inc;
114 }
115
116the_end:
117 *isamp = ibuf - istart;
118 *osamp = obuf - ostart;
119 rate->ilast = ilast;
120}
121
122#undef NAME
123#undef OP
124