Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
  3.  *
  4.  * This file is part of FFmpeg.
  5.  *
  6.  * FFmpeg 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.  * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19.  */
  20.  
  21. #if defined(CONFIG_RESAMPLE_DBL)
  22. #define SET_TYPE(func)  func ## _dbl
  23. #define FELEM         double
  24. #define FELEM2        double
  25. #define FELEML        double
  26. #define OUT(d, v) d = v
  27. #define DBL_TO_FELEM(d, v) d = v
  28. #elif defined(CONFIG_RESAMPLE_FLT)
  29. #define SET_TYPE(func)  func ## _flt
  30. #define FELEM         float
  31. #define FELEM2        float
  32. #define FELEML        float
  33. #define OUT(d, v) d = v
  34. #define DBL_TO_FELEM(d, v) d = v
  35. #elif defined(CONFIG_RESAMPLE_S32)
  36. #define SET_TYPE(func)  func ## _s32
  37. #define FELEM         int32_t
  38. #define FELEM2        int64_t
  39. #define FELEML        int64_t
  40. #define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
  41. #define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
  42. #else
  43. #define SET_TYPE(func)  func ## _s16
  44. #define FELEM         int16_t
  45. #define FELEM2        int32_t
  46. #define FELEML        int64_t
  47. #define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
  48. #define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
  49. #endif
  50.  
  51. static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
  52.                                    void *dst0, int dst_index, const void *src0,
  53.                                    int src_size, int index, int frac)
  54. {
  55.     FELEM *dst = dst0;
  56.     const FELEM *src = src0;
  57.  
  58.     if (no_filter) {
  59.         dst[dst_index] = src[index];
  60.     } else {
  61.         int i;
  62.         int sample_index = index >> c->phase_shift;
  63.         FELEM2 val = 0;
  64.         FELEM *filter = ((FELEM *)c->filter_bank) +
  65.                         c->filter_length * (index & c->phase_mask);
  66.  
  67.         if (sample_index < 0) {
  68.             for (i = 0; i < c->filter_length; i++)
  69.                 val += src[FFABS(sample_index + i) % src_size] *
  70.                        (FELEM2)filter[i];
  71.         } else if (c->linear) {
  72.             FELEM2 v2 = 0;
  73.             for (i = 0; i < c->filter_length; i++) {
  74.                 val += src[abs(sample_index + i)] * (FELEM2)filter[i];
  75.                 v2  += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
  76.             }
  77.             val += (v2 - val) * (FELEML)frac / c->src_incr;
  78.         } else {
  79.             for (i = 0; i < c->filter_length; i++)
  80.                 val += src[sample_index + i] * (FELEM2)filter[i];
  81.         }
  82.  
  83.         OUT(dst[dst_index], val);
  84.     }
  85. }
  86.  
  87. static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
  88.                                  int tap_count)
  89. {
  90.     int i;
  91.     FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
  92.     for (i = 0; i < tap_count; i++) {
  93.         DBL_TO_FELEM(filter[i], tab[i]);
  94.     }
  95. }
  96.  
  97. #undef SET_TYPE
  98. #undef FELEM
  99. #undef FELEM2
  100. #undef FELEML
  101. #undef OUT
  102. #undef DBL_TO_FELEM
  103.