• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2015> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef __GST_AUDIO_RESAMPLER_MACROS_H__
21 #define __GST_AUDIO_RESAMPLER_MACROS_H__
22 
23 #include <string.h>
24 
25 #include "audio-resampler-private.h"
26 
27 #define PRECISION_S16 15
28 #define PRECISION_S32 31
29 
30 #define DECL_GET_TAPS_FULL_FUNC(type)                           \
31 gpointer                                                        \
32 get_taps_##type##_full (GstAudioResampler * resampler,          \
33     gint *samp_index, gint *samp_phase, type icoeff[4])
34 
35 DECL_GET_TAPS_FULL_FUNC (gint16);
36 DECL_GET_TAPS_FULL_FUNC (gint32);
37 DECL_GET_TAPS_FULL_FUNC (gfloat);
38 DECL_GET_TAPS_FULL_FUNC (gdouble);
39 
40 
41 #define DECL_GET_TAPS_INTERPOLATE_FUNC(type, inter)             \
42 gpointer                                                        \
43 get_taps_##type##_##inter (GstAudioResampler * resampler,       \
44     gint *samp_index, gint *samp_phase, type icoeff[4])         \
45 
46 DECL_GET_TAPS_INTERPOLATE_FUNC (gint16, linear);
47 DECL_GET_TAPS_INTERPOLATE_FUNC (gint32, linear);
48 DECL_GET_TAPS_INTERPOLATE_FUNC (gfloat, linear);
49 DECL_GET_TAPS_INTERPOLATE_FUNC (gdouble, linear);
50 
51 DECL_GET_TAPS_INTERPOLATE_FUNC (gint16, cubic);
52 DECL_GET_TAPS_INTERPOLATE_FUNC (gint32, cubic);
53 DECL_GET_TAPS_INTERPOLATE_FUNC (gfloat, cubic);
54 DECL_GET_TAPS_INTERPOLATE_FUNC (gdouble, cubic);
55 
56 
57 #define DECL_RESAMPLE_FUNC(type,inter,channels,arch)                    \
58 void                                                                    \
59 resample_ ##type## _ ##inter## _ ##channels## _ ##arch (GstAudioResampler * resampler,      \
60     gpointer in[], gsize in_len,  gpointer out[], gsize out_len,        \
61     gsize * consumed)
62 
63 #define MAKE_RESAMPLE_FUNC(type,inter,channels,arch)            \
64 DECL_RESAMPLE_FUNC (type, inter, channels, arch)                \
65 {                                                               \
66   gint c, di = 0;                                               \
67   gint n_taps = resampler->n_taps;                              \
68   gint blocks = resampler->blocks;                              \
69   gint ostride = resampler->ostride;                            \
70   gint taps_stride = resampler->taps_stride;                    \
71   gint samp_index = 0;                                          \
72   gint samp_phase = 0;                                          \
73                                                                 \
74   for (c = 0; c < blocks; c++) {                                \
75     type *ip = in[c];                                           \
76     type *op = ostride == 1 ? out[c] : (type *)out[0] + c;      \
77                                                                 \
78     samp_index = resampler->samp_index;                         \
79     samp_phase = resampler->samp_phase;                         \
80                                                                 \
81     for (di = 0; di < out_len; di++) {                          \
82       type *ipp, icoeff[4], *taps;                              \
83                                                                 \
84       ipp = &ip[samp_index * channels];                         \
85                                                                 \
86       taps = get_taps_ ##type##_##inter                         \
87               (resampler, &samp_index, &samp_phase, icoeff);    \
88       inner_product_ ##type##_##inter##_##channels##_##arch     \
89               (op, ipp, taps, n_taps, icoeff, taps_stride);     \
90       op += ostride;                                            \
91     }                                                           \
92     if (in_len > samp_index)                                    \
93       memmove (ip, &ip[samp_index * channels],                  \
94           (in_len - samp_index) * sizeof(type) * channels);     \
95   }                                                             \
96   *consumed = samp_index - resampler->samp_index;               \
97                                                                 \
98   resampler->samp_index = 0;                                    \
99   resampler->samp_phase = samp_phase;                           \
100 }
101 
102 #define DECL_RESAMPLE_FUNC_STATIC(type,inter,channels,arch)     \
103 static DECL_RESAMPLE_FUNC (type, inter, channels, arch)
104 
105 #define MAKE_RESAMPLE_FUNC_STATIC(type,inter,channels,arch)     \
106 static MAKE_RESAMPLE_FUNC (type, inter, channels, arch)
107 
108 #endif /* __GST_AUDIO_RESAMPLER_MACROS_H__ */
109