Home | History | Annotate | Download | only in celt
      1 /* Copyright (c) 2007-2008 CSIRO
      2    Copyright (c) 2007-2009 Xiph.Org Foundation
      3    Written by Jean-Marc Valin */
      4 /**
      5    @file pitch.h
      6    @brief Pitch analysis
      7  */
      8 
      9 /*
     10    Redistribution and use in source and binary forms, with or without
     11    modification, are permitted provided that the following conditions
     12    are met:
     13 
     14    - Redistributions of source code must retain the above copyright
     15    notice, this list of conditions and the following disclaimer.
     16 
     17    - Redistributions in binary form must reproduce the above copyright
     18    notice, this list of conditions and the following disclaimer in the
     19    documentation and/or other materials provided with the distribution.
     20 
     21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     22    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     24    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     25    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     26    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     28    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     29    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 */
     33 
     34 #ifndef PITCH_H
     35 #define PITCH_H
     36 
     37 #include "modes.h"
     38 #include "cpu_support.h"
     39 
     40 #if (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)) \
     41   || ((defined(OPUS_X86_MAY_HAVE_SSE4_1) || defined(OPUS_X86_MAY_HAVE_SSE2)) && defined(FIXED_POINT))
     42 #include "x86/pitch_sse.h"
     43 #endif
     44 
     45 #if defined(MIPSr1_ASM)
     46 #include "mips/pitch_mipsr1.h"
     47 #endif
     48 
     49 #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \
     50   || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
     51 # include "arm/pitch_arm.h"
     52 #endif
     53 
     54 void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
     55       int len, int C, int arch);
     56 
     57 void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y,
     58                   int len, int max_pitch, int *pitch, int arch);
     59 
     60 opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
     61       int N, int *T0, int prev_period, opus_val16 prev_gain, int arch);
     62 
     63 
     64 /* OPT: This is the kernel you really want to optimize. It gets used a lot
     65    by the prefilter and by the PLC. */
     66 static OPUS_INLINE void xcorr_kernel_c(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
     67 {
     68    int j;
     69    opus_val16 y_0, y_1, y_2, y_3;
     70    celt_assert(len>=3);
     71    y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
     72    y_0=*y++;
     73    y_1=*y++;
     74    y_2=*y++;
     75    for (j=0;j<len-3;j+=4)
     76    {
     77       opus_val16 tmp;
     78       tmp = *x++;
     79       y_3=*y++;
     80       sum[0] = MAC16_16(sum[0],tmp,y_0);
     81       sum[1] = MAC16_16(sum[1],tmp,y_1);
     82       sum[2] = MAC16_16(sum[2],tmp,y_2);
     83       sum[3] = MAC16_16(sum[3],tmp,y_3);
     84       tmp=*x++;
     85       y_0=*y++;
     86       sum[0] = MAC16_16(sum[0],tmp,y_1);
     87       sum[1] = MAC16_16(sum[1],tmp,y_2);
     88       sum[2] = MAC16_16(sum[2],tmp,y_3);
     89       sum[3] = MAC16_16(sum[3],tmp,y_0);
     90       tmp=*x++;
     91       y_1=*y++;
     92       sum[0] = MAC16_16(sum[0],tmp,y_2);
     93       sum[1] = MAC16_16(sum[1],tmp,y_3);
     94       sum[2] = MAC16_16(sum[2],tmp,y_0);
     95       sum[3] = MAC16_16(sum[3],tmp,y_1);
     96       tmp=*x++;
     97       y_2=*y++;
     98       sum[0] = MAC16_16(sum[0],tmp,y_3);
     99       sum[1] = MAC16_16(sum[1],tmp,y_0);
    100       sum[2] = MAC16_16(sum[2],tmp,y_1);
    101       sum[3] = MAC16_16(sum[3],tmp,y_2);
    102    }
    103    if (j++<len)
    104    {
    105       opus_val16 tmp = *x++;
    106       y_3=*y++;
    107       sum[0] = MAC16_16(sum[0],tmp,y_0);
    108       sum[1] = MAC16_16(sum[1],tmp,y_1);
    109       sum[2] = MAC16_16(sum[2],tmp,y_2);
    110       sum[3] = MAC16_16(sum[3],tmp,y_3);
    111    }
    112    if (j++<len)
    113    {
    114       opus_val16 tmp=*x++;
    115       y_0=*y++;
    116       sum[0] = MAC16_16(sum[0],tmp,y_1);
    117       sum[1] = MAC16_16(sum[1],tmp,y_2);
    118       sum[2] = MAC16_16(sum[2],tmp,y_3);
    119       sum[3] = MAC16_16(sum[3],tmp,y_0);
    120    }
    121    if (j<len)
    122    {
    123       opus_val16 tmp=*x++;
    124       y_1=*y++;
    125       sum[0] = MAC16_16(sum[0],tmp,y_2);
    126       sum[1] = MAC16_16(sum[1],tmp,y_3);
    127       sum[2] = MAC16_16(sum[2],tmp,y_0);
    128       sum[3] = MAC16_16(sum[3],tmp,y_1);
    129    }
    130 }
    131 
    132 #ifndef OVERRIDE_XCORR_KERNEL
    133 #define xcorr_kernel(x, y, sum, len, arch) \
    134     ((void)(arch),xcorr_kernel_c(x, y, sum, len))
    135 #endif /* OVERRIDE_XCORR_KERNEL */
    136 
    137 
    138 static OPUS_INLINE void dual_inner_prod_c(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
    139       int N, opus_val32 *xy1, opus_val32 *xy2)
    140 {
    141    int i;
    142    opus_val32 xy01=0;
    143    opus_val32 xy02=0;
    144    for (i=0;i<N;i++)
    145    {
    146       xy01 = MAC16_16(xy01, x[i], y01[i]);
    147       xy02 = MAC16_16(xy02, x[i], y02[i]);
    148    }
    149    *xy1 = xy01;
    150    *xy2 = xy02;
    151 }
    152 
    153 #ifndef OVERRIDE_DUAL_INNER_PROD
    154 # define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
    155     ((void)(arch),dual_inner_prod_c(x, y01, y02, N, xy1, xy2))
    156 #endif
    157 
    158 /*We make sure a C version is always available for cases where the overhead of
    159   vectorization and passing around an arch flag aren't worth it.*/
    160 static OPUS_INLINE opus_val32 celt_inner_prod_c(const opus_val16 *x,
    161       const opus_val16 *y, int N)
    162 {
    163    int i;
    164    opus_val32 xy=0;
    165    for (i=0;i<N;i++)
    166       xy = MAC16_16(xy, x[i], y[i]);
    167    return xy;
    168 }
    169 
    170 #if !defined(OVERRIDE_CELT_INNER_PROD)
    171 # define celt_inner_prod(x, y, N, arch) \
    172     ((void)(arch),celt_inner_prod_c(x, y, N))
    173 #endif
    174 
    175 #ifdef NON_STATIC_COMB_FILTER_CONST_C
    176 void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
    177      opus_val16 g10, opus_val16 g11, opus_val16 g12);
    178 #endif
    179 
    180 
    181 #ifdef FIXED_POINT
    182 opus_val32
    183 #else
    184 void
    185 #endif
    186 celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
    187       opus_val32 *xcorr, int len, int max_pitch);
    188 
    189 #if !defined(OVERRIDE_PITCH_XCORR)
    190 #ifdef FIXED_POINT
    191 opus_val32
    192 #else
    193 void
    194 #endif
    195 celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
    196       opus_val32 *xcorr, int len, int max_pitch, int arch);
    197 
    198 #endif
    199 
    200 #endif
    201