4 * Copyright (c) 2004-2005 Vassili Karpov (malc)
5 * Copyright (c) 1998 Fabrice Bellard
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * Processed signed long samples from ibuf to obuf.
28 * Return number of samples processed.
30 void NAME (void *opaque
, st_sample_t
*ibuf
, st_sample_t
*obuf
,
31 int *isamp
, int *osamp
)
33 struct rate
*rate
= opaque
;
34 st_sample_t
*istart
, *iend
;
35 st_sample_t
*ostart
, *oend
;
36 st_sample_t ilast
, icur
, out
;
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
);
64 /* Safety catch to make sure we have input samples. */
69 /* read as many input samples so that ipos > opos */
71 while (rate
->ipos
<= (rate
->opos
>> 32)) {
74 /* See if we finished the input buffer yet */
85 t
= (rate
->opos
& UINT_MAX
) * (1.f
/ UINT_MAX
);
87 t
= (rate
->opos
& UINT_MAX
) / (real_t
) UINT_MAX
;
89 out
.l
= (ilast
.l
* (1.0 - t
)) + icur
.l
* t
;
90 out
.r
= (ilast
.r
* (1.0 - t
)) + icur
.r
* t
;
92 t
= rate
->opos
& 0xffffffff;
93 out
.l
= (ilast
.l
* ((int64_t) UINT_MAX
- t
) + icur
.l
* t
) >> 32;
94 out
.r
= (ilast
.r
* ((int64_t) UINT_MAX
- t
) + icur
.r
* t
) >> 32;
97 /* output sample & increment position */
101 rate
->opos
+= rate
->opos_inc
;
105 *isamp
= ibuf
- istart
;
106 *osamp
= obuf
- ostart
;