Blame gst-libs/gst/audio/audio-resampler-macros.h

Packit 971217
/* GStreamer
Packit 971217
 * Copyright (C) <2015> Wim Taymans <wim.taymans@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifndef __GST_AUDIO_RESAMPLER_MACROS_H__
Packit 971217
#define __GST_AUDIO_RESAMPLER_MACROS_H__
Packit 971217
Packit 971217
#include <string.h>
Packit 971217
Packit 971217
#include "audio-resampler-private.h"
Packit 971217
Packit 971217
#define PRECISION_S16 15
Packit 971217
#define PRECISION_S32 31
Packit 971217
Packit 971217
#define DECL_GET_TAPS_FULL_FUNC(type)                           \
Packit 971217
gpointer                                                        \
Packit 971217
get_taps_##type##_full (GstAudioResampler * resampler,          \
Packit 971217
    gint *samp_index, gint *samp_phase, type icoeff[4])
Packit 971217
Packit 971217
DECL_GET_TAPS_FULL_FUNC (gint16);
Packit 971217
DECL_GET_TAPS_FULL_FUNC (gint32);
Packit 971217
DECL_GET_TAPS_FULL_FUNC (gfloat);
Packit 971217
DECL_GET_TAPS_FULL_FUNC (gdouble);
Packit 971217
Packit 971217
Packit 971217
#define DECL_GET_TAPS_INTERPOLATE_FUNC(type, inter)             \
Packit 971217
gpointer                                                        \
Packit 971217
get_taps_##type##_##inter (GstAudioResampler * resampler,       \
Packit 971217
    gint *samp_index, gint *samp_phase, type icoeff[4])         \
Packit 971217
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gint16, linear);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gint32, linear);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gfloat, linear);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gdouble, linear);
Packit 971217
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gint16, cubic);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gint32, cubic);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gfloat, cubic);
Packit 971217
DECL_GET_TAPS_INTERPOLATE_FUNC (gdouble, cubic);
Packit 971217
Packit 971217
Packit 971217
#define DECL_RESAMPLE_FUNC(type,inter,channels,arch)                    \
Packit 971217
void                                                                    \
Packit 971217
resample_ ##type## _ ##inter## _ ##channels## _ ##arch (GstAudioResampler * resampler,      \
Packit 971217
    gpointer in[], gsize in_len,  gpointer out[], gsize out_len,        \
Packit 971217
    gsize * consumed)
Packit 971217
Packit 971217
#define MAKE_RESAMPLE_FUNC(type,inter,channels,arch)            \
Packit 971217
DECL_RESAMPLE_FUNC (type, inter, channels, arch)                \
Packit 971217
{                                                               \
Packit 971217
  gint c, di = 0;                                               \
Packit 971217
  gint n_taps = resampler->n_taps;                              \
Packit 971217
  gint blocks = resampler->blocks;                              \
Packit 971217
  gint ostride = resampler->ostride;                            \
Packit 971217
  gint taps_stride = resampler->taps_stride;                    \
Packit 971217
  gint samp_index = 0;                                          \
Packit 971217
  gint samp_phase = 0;                                          \
Packit 971217
                                                                \
Packit 971217
  for (c = 0; c < blocks; c++) {                                \
Packit 971217
    type *ip = in[c];                                           \
Packit 971217
    type *op = ostride == 1 ? out[c] : (type *)out[0] + c;      \
Packit 971217
                                                                \
Packit 971217
    samp_index = resampler->samp_index;                         \
Packit 971217
    samp_phase = resampler->samp_phase;                         \
Packit 971217
                                                                \
Packit 971217
    for (di = 0; di < out_len; di++) {                          \
Packit 971217
      type *ipp, icoeff[4], *taps;                              \
Packit 971217
                                                                \
Packit 971217
      ipp = &ip[samp_index * channels];                         \
Packit 971217
                                                                \
Packit 971217
      taps = get_taps_ ##type##_##inter                         \
Packit 971217
              (resampler, &samp_index, &samp_phase, icoeff);    \
Packit 971217
      inner_product_ ##type##_##inter##_##channels##_##arch     \
Packit 971217
              (op, ipp, taps, n_taps, icoeff, taps_stride);     \
Packit 971217
      op += ostride;                                            \
Packit 971217
    }                                                           \
Packit 971217
    if (in_len > samp_index)                                    \
Packit 971217
      memmove (ip, &ip[samp_index * channels],                  \
Packit 971217
          (in_len - samp_index) * sizeof(type) * channels);     \
Packit 971217
  }                                                             \
Packit 971217
  *consumed = samp_index - resampler->samp_index;               \
Packit 971217
                                                                \
Packit 971217
  resampler->samp_index = 0;                                    \
Packit 971217
  resampler->samp_phase = samp_phase;                           \
Packit 971217
}
Packit 971217
Packit 971217
#define DECL_RESAMPLE_FUNC_STATIC(type,inter,channels,arch)     \
Packit 971217
static DECL_RESAMPLE_FUNC (type, inter, channels, arch)
Packit 971217
Packit 971217
#define MAKE_RESAMPLE_FUNC_STATIC(type,inter,channels,arch)     \
Packit 971217
static MAKE_RESAMPLE_FUNC (type, inter, channels, arch)
Packit 971217
Packit 971217
#endif /* __GST_AUDIO_RESAMPLER_MACROS_H__ */