resample: reindent
[libav.git] / libavresample / resample_template.c
CommitLineData
64103976
JR
1/*
2 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of Libav.
5 *
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
aba70bb5
DB
21#include <math.h>
22#include <stdint.h>
23
24#include "libavutil/common.h"
25#include "internal.h"
26
64103976
JR
27#if defined(CONFIG_RESAMPLE_DBL)
28#define SET_TYPE(func) func ## _dbl
29#define FELEM double
30#define FELEM2 double
31#define FELEML double
32#define OUT(d, v) d = v
33#define DBL_TO_FELEM(d, v) d = v
34#elif defined(CONFIG_RESAMPLE_FLT)
35#define SET_TYPE(func) func ## _flt
36#define FELEM float
37#define FELEM2 float
38#define FELEML float
39#define OUT(d, v) d = v
40#define DBL_TO_FELEM(d, v) d = v
41#elif defined(CONFIG_RESAMPLE_S32)
42#define SET_TYPE(func) func ## _s32
43#define FELEM int32_t
44#define FELEM2 int64_t
45#define FELEML int64_t
46#define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
47#define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
48#else
49#define SET_TYPE(func) func ## _s16
50#define FELEM int16_t
51#define FELEM2 int32_t
52#define FELEML int64_t
53#define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
54#define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
55#endif
56
f20892eb
AK
57static void SET_TYPE(resample_nearest)(void *dst0, int dst_index, const void *src0, int index)
58{
59 FELEM *dst = dst0;
60 const FELEM *src = src0;
61 dst[dst_index] = src[index];
62}
63
64static void SET_TYPE(resample_one)(ResampleContext *c,
64103976
JR
65 void *dst0, int dst_index, const void *src0,
66 int src_size, int index, int frac)
67{
68 FELEM *dst = dst0;
69 const FELEM *src = src0;
3c84f6b5
AK
70 int i;
71 int sample_index = index >> c->phase_shift;
72 FELEM2 val = 0;
73 FELEM *filter = ((FELEM *)c->filter_bank) +
74 c->filter_length * (index & c->phase_mask);
64103976 75
3c84f6b5
AK
76 if (sample_index < 0) {
77 for (i = 0; i < c->filter_length; i++)
78 val += src[FFABS(sample_index + i) % src_size] *
79 (FELEM2)filter[i];
80 } else if (c->linear) {
81 FELEM2 v2 = 0;
82 for (i = 0; i < c->filter_length; i++) {
83 val += src[abs(sample_index + i)] * (FELEM2)filter[i];
84 v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
64103976 85 }
3c84f6b5
AK
86 val += (v2 - val) * (FELEML)frac / c->src_incr;
87 } else {
88 for (i = 0; i < c->filter_length; i++)
89 val += src[sample_index + i] * (FELEM2)filter[i];
90 }
64103976 91
3c84f6b5 92 OUT(dst[dst_index], val);
64103976
JR
93}
94
95static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
96 int tap_count)
97{
98 int i;
99 FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
100 for (i = 0; i < tap_count; i++) {
101 DBL_TO_FELEM(filter[i], tab[i]);
102 }
103}
104
105#undef SET_TYPE
106#undef FELEM
107#undef FELEM2
108#undef FELEML
109#undef OUT
110#undef DBL_TO_FELEM