]> git.sesse.net Git - ffmpeg/blob - libswresample/arm/resample_init.c
Merge commit '113aeee6aed35cb786a9f6d69b0cb210f498b9da'
[ffmpeg] / libswresample / arm / resample_init.c
1 /*
2  * Audio resampling
3  *
4  * Copyright (c) 2004-2012 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "config.h"
24
25 #include "libavutil/cpu.h"
26 #include "libavutil/avassert.h"
27
28 #include "libavutil/arm/cpu.h"
29 #include "libswresample/resample.h"
30
31 #define DECLARE_RESAMPLE_COMMON_TEMPLATE(TYPE, DELEM, FELEM, FELEM2, OUT)                         \
32                                                                                                   \
33 void ff_resample_common_apply_filter_x4_##TYPE##_neon(FELEM2 *acc, const DELEM *src,              \
34                                                       const FELEM *filter, int length);           \
35                                                                                                   \
36 void ff_resample_common_apply_filter_x8_##TYPE##_neon(FELEM2 *acc, const DELEM *src,              \
37                                                       const FELEM *filter, int length);           \
38                                                                                                   \
39 static int ff_resample_common_##TYPE##_neon(ResampleContext *c, void *dest, const void *source,   \
40                                             int n, int update_ctx)                                \
41 {                                                                                                 \
42     DELEM *dst = dest;                                                                            \
43     const DELEM *src = source;                                                                    \
44     int dst_index;                                                                                \
45     int index= c->index;                                                                          \
46     int frac= c->frac;                                                                            \
47     int sample_index = index >> c->phase_shift;                                                   \
48     int x4_aligned_filter_length = c->filter_length & ~3;                                         \
49     int x8_aligned_filter_length = c->filter_length & ~7;                                         \
50                                                                                                   \
51     index &= c->phase_mask;                                                                       \
52     for (dst_index = 0; dst_index < n; dst_index++) {                                             \
53         FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;                     \
54                                                                                                   \
55         FELEM2 val=0;                                                                             \
56         int i = 0;                                                                                \
57         if (x8_aligned_filter_length >= 8) {                                                      \
58             ff_resample_common_apply_filter_x8_##TYPE##_neon(&val, &src[sample_index],            \
59                                                              filter, x8_aligned_filter_length);   \
60             i += x8_aligned_filter_length;                                                        \
61                                                                                                   \
62         } else if (x4_aligned_filter_length >= 4) {                                               \
63             ff_resample_common_apply_filter_x4_##TYPE##_neon(&val, &src[sample_index],            \
64                                                              filter, x4_aligned_filter_length);   \
65             i += x4_aligned_filter_length;                                                        \
66         }                                                                                         \
67         for (; i < c->filter_length; i++) {                                                       \
68             val += src[sample_index + i] * (FELEM2)filter[i];                                     \
69         }                                                                                         \
70         OUT(dst[dst_index], val);                                                                 \
71                                                                                                   \
72         frac  += c->dst_incr_mod;                                                                 \
73         index += c->dst_incr_div;                                                                 \
74         if (frac >= c->src_incr) {                                                                \
75             frac -= c->src_incr;                                                                  \
76             index++;                                                                              \
77         }                                                                                         \
78         sample_index += index >> c->phase_shift;                                                  \
79         index &= c->phase_mask;                                                                   \
80     }                                                                                             \
81                                                                                                   \
82     if(update_ctx){                                                                               \
83         c->frac= frac;                                                                            \
84         c->index= index;                                                                          \
85     }                                                                                             \
86                                                                                                   \
87     return sample_index;                                                                          \
88 }                                                                                                 \
89
90 #define OUT(d, v) d = v
91 DECLARE_RESAMPLE_COMMON_TEMPLATE(float, float, float, float, OUT)
92 #undef OUT
93
94 #define OUT(d, v) (v) = ((v) + (1<<(14)))>>15; (d) = av_clip_int16(v)
95 DECLARE_RESAMPLE_COMMON_TEMPLATE(s16, int16_t, int16_t, int32_t, OUT)
96 #undef OUT
97
98 av_cold void swri_resample_dsp_arm_init(ResampleContext *c)
99 {
100     int cpu_flags = av_get_cpu_flags();
101
102     if (!have_neon(cpu_flags))
103         return;
104
105     switch(c->format) {
106     case AV_SAMPLE_FMT_FLTP:
107         if (!c->linear)
108             c->dsp.resample = ff_resample_common_float_neon;
109         break;
110     case AV_SAMPLE_FMT_S16P:
111         if (!c->linear)
112             c->dsp.resample = ff_resample_common_s16_neon;
113         break;
114     }
115 }