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