LCOV - code coverage report
Current view: top level - src/libswresample - resample_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 66 71 93.0 %
Date: 2017-01-19 23:52:33 Functions: 8 12 66.7 %

          Line data    Source code
       1             : /*
       2             :  * audio resampling
       3             :  * Copyright (c) 2004-2012 Michael Niedermayer <michaelni@gmx.at>
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * audio resampling
      25             :  * @author Michael Niedermayer <michaelni@gmx.at>
      26             :  */
      27             : 
      28             : #if defined(TEMPLATE_RESAMPLE_DBL)
      29             : 
      30             : #    define RENAME(N) N ## _double
      31             : #    define FILTER_SHIFT 0
      32             : #    define DELEM  double
      33             : #    define FELEM  double
      34             : #    define FELEM2 double
      35             : #    define FOFFSET 0
      36             : #    define OUT(d, v) d = v
      37             : 
      38             : #elif    defined(TEMPLATE_RESAMPLE_FLT)
      39             : 
      40             : #    define RENAME(N) N ## _float
      41             : #    define FILTER_SHIFT 0
      42             : #    define DELEM  float
      43             : #    define FELEM  float
      44             : #    define FELEM2 float
      45             : #    define FOFFSET 0
      46             : #    define OUT(d, v) d = v
      47             : 
      48             : #elif defined(TEMPLATE_RESAMPLE_S32)
      49             : 
      50             : #    define RENAME(N) N ## _int32
      51             : #    define FILTER_SHIFT 30
      52             : #    define DELEM  int32_t
      53             : #    define FELEM  int32_t
      54             : #    define FELEM2 int64_t
      55             : #    define FELEM_MAX INT32_MAX
      56             : #    define FELEM_MIN INT32_MIN
      57             : #    define FOFFSET (1<<(FILTER_SHIFT-1))
      58             : #    define OUT(d, v) (d) = av_clipl_int32((v)>>FILTER_SHIFT)
      59             : 
      60             : #elif    defined(TEMPLATE_RESAMPLE_S16)
      61             : 
      62             : #    define RENAME(N) N ## _int16
      63             : #    define FILTER_SHIFT 15
      64             : #    define DELEM  int16_t
      65             : #    define FELEM  int16_t
      66             : #    define FELEM2 int32_t
      67             : #    define FELEML int64_t
      68             : #    define FELEM_MAX INT16_MAX
      69             : #    define FELEM_MIN INT16_MIN
      70             : #    define FOFFSET (1<<(FILTER_SHIFT-1))
      71             : #    define OUT(d, v) (d) = av_clip_int16((v)>>FILTER_SHIFT)
      72             : 
      73             : #endif
      74             : 
      75          20 : static void RENAME(resample_one)(void *dest, const void *source,
      76             :                                  int dst_size, int64_t index2, int64_t incr)
      77             : {
      78          20 :     DELEM *dst = dest;
      79          20 :     const DELEM *src = source;
      80             :     int dst_index;
      81             : 
      82      112916 :     for (dst_index = 0; dst_index < dst_size; dst_index++) {
      83      112896 :         dst[dst_index] = src[index2 >> 32];
      84      112896 :         index2 += incr;
      85             :     }
      86          20 : }
      87             : 
      88       85840 : static int RENAME(resample_common)(ResampleContext *c,
      89             :                                    void *dest, const void *source,
      90             :                                    int n, int update_ctx)
      91             : {
      92       85840 :     DELEM *dst = dest;
      93       85840 :     const DELEM *src = source;
      94             :     int dst_index;
      95       85840 :     int index= c->index;
      96       85840 :     int frac= c->frac;
      97       85840 :     int sample_index = 0;
      98             : 
      99      171680 :     while (index >= c->phase_count) {
     100           0 :         sample_index++;
     101           0 :         index -= c->phase_count;
     102             :     }
     103             : 
     104    31066137 :     for (dst_index = 0; dst_index < n; dst_index++) {
     105    30980297 :         FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
     106             : 
     107    30980297 :         FELEM2 val = FOFFSET;
     108    30980297 :         FELEM2 val2= 0;
     109             :         int i;
     110   580032014 :         for (i = 0; i + 1 < c->filter_length; i+=2) {
     111   549051717 :             val  += src[sample_index + i    ] * (FELEM2)filter[i    ];
     112   549051717 :             val2 += src[sample_index + i + 1] * (FELEM2)filter[i + 1];
     113             :         }
     114    30980297 :         if (i < c->filter_length)
     115      279784 :             val  += src[sample_index + i    ] * (FELEM2)filter[i    ];
     116             : #ifdef FELEML
     117     5572121 :         OUT(dst[dst_index], val + (FELEML)val2);
     118             : #else
     119    25408176 :         OUT(dst[dst_index], val + val2);
     120             : #endif
     121             : 
     122    30980297 :         frac  += c->dst_incr_mod;
     123    30980297 :         index += c->dst_incr_div;
     124    30980297 :         if (frac >= c->src_incr) {
     125     9345264 :             frac -= c->src_incr;
     126     9345264 :             index++;
     127             :         }
     128             : 
     129    82680616 :         while (index >= c->phase_count) {
     130    20720022 :             sample_index++;
     131    20720022 :             index -= c->phase_count;
     132             :         }
     133             :     }
     134             : 
     135       85840 :     if(update_ctx){
     136       47028 :         c->frac= frac;
     137       47028 :         c->index= index;
     138             :     }
     139             : 
     140       85840 :     return sample_index;
     141             : }
     142             : 
     143         739 : static int RENAME(resample_linear)(ResampleContext *c,
     144             :                                    void *dest, const void *source,
     145             :                                    int n, int update_ctx)
     146             : {
     147         739 :     DELEM *dst = dest;
     148         739 :     const DELEM *src = source;
     149             :     int dst_index;
     150         739 :     int index= c->index;
     151         739 :     int frac= c->frac;
     152         739 :     int sample_index = 0;
     153             : #if FILTER_SHIFT == 0
     154         513 :     double inv_src_incr = 1.0 / c->src_incr;
     155             : #endif
     156             : 
     157        1478 :     while (index >= c->phase_count) {
     158           0 :         sample_index++;
     159           0 :         index -= c->phase_count;
     160             :     }
     161             : 
     162      918565 :     for (dst_index = 0; dst_index < n; dst_index++) {
     163      917826 :         FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index;
     164      917826 :         FELEM2 val = FOFFSET, v2 = FOFFSET;
     165             : 
     166             :         int i;
     167    37429242 :         for (i = 0; i < c->filter_length; i++) {
     168    36511416 :             val += src[sample_index + i] * (FELEM2)filter[i];
     169    36511416 :             v2  += src[sample_index + i] * (FELEM2)filter[i + c->filter_alloc];
     170             :         }
     171             : #ifdef FELEML
     172      277333 :         val += (v2 - val) * (FELEML) frac / c->src_incr;
     173             : #else
     174             : #    if FILTER_SHIFT == 0
     175      640493 :         val += (v2 - val) * inv_src_incr * frac;
     176             : #    else
     177           0 :         val += (v2 - val) / c->src_incr * frac;
     178             : #    endif
     179             : #endif
     180      917826 :         OUT(dst[dst_index], val);
     181             : 
     182      917826 :         frac += c->dst_incr_mod;
     183      917826 :         index += c->dst_incr_div;
     184      917826 :         if (frac >= c->src_incr) {
     185      561622 :             frac -= c->src_incr;
     186      561622 :             index++;
     187             :         }
     188             : 
     189     2379415 :         while (index >= c->phase_count) {
     190      543763 :             sample_index++;
     191      543763 :             index -= c->phase_count;
     192             :         }
     193             :     }
     194             : 
     195         739 :     if(update_ctx){
     196         739 :         c->frac= frac;
     197         739 :         c->index= index;
     198             :     }
     199             : 
     200         739 :     return sample_index;
     201             : }
     202             : 
     203             : #undef RENAME
     204             : #undef FILTER_SHIFT
     205             : #undef DELEM
     206             : #undef FELEM
     207             : #undef FELEM2
     208             : #undef FELEML
     209             : #undef FELEM_MAX
     210             : #undef FELEM_MIN
     211             : #undef OUT
     212             : #undef FOFFSET

Generated by: LCOV version 1.12