media/libopus/celt/pitch.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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  */
     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:
    14    - Redistributions of source code must retain the above copyright
    15    notice, this list of conditions and the following disclaimer.
    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.
    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 */
    34 #ifndef PITCH_H
    35 #define PITCH_H
    37 #include "modes.h"
    38 #include "cpu_support.h"
    40 #if defined(__SSE__) && !defined(FIXED_POINT)
    41 #include "x86/pitch_sse.h"
    42 #endif
    44 #if defined(OPUS_ARM_ASM) && defined(FIXED_POINT)
    45 # include "arm/pitch_arm.h"
    46 #endif
    48 void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
    49       int len, int C, int arch);
    51 void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y,
    52                   int len, int max_pitch, int *pitch, int arch);
    54 opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
    55       int N, int *T0, int prev_period, opus_val16 prev_gain);
    57 /* OPT: This is the kernel you really want to optimize. It gets used a lot
    58    by the prefilter and by the PLC. */
    59 #ifndef OVERRIDE_XCORR_KERNEL
    60 static OPUS_INLINE void xcorr_kernel(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
    61 {
    62    int j;
    63    opus_val16 y_0, y_1, y_2, y_3;
    64    celt_assert(len>=3);
    65    y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
    66    y_0=*y++;
    67    y_1=*y++;
    68    y_2=*y++;
    69    for (j=0;j<len-3;j+=4)
    70    {
    71       opus_val16 tmp;
    72       tmp = *x++;
    73       y_3=*y++;
    74       sum[0] = MAC16_16(sum[0],tmp,y_0);
    75       sum[1] = MAC16_16(sum[1],tmp,y_1);
    76       sum[2] = MAC16_16(sum[2],tmp,y_2);
    77       sum[3] = MAC16_16(sum[3],tmp,y_3);
    78       tmp=*x++;
    79       y_0=*y++;
    80       sum[0] = MAC16_16(sum[0],tmp,y_1);
    81       sum[1] = MAC16_16(sum[1],tmp,y_2);
    82       sum[2] = MAC16_16(sum[2],tmp,y_3);
    83       sum[3] = MAC16_16(sum[3],tmp,y_0);
    84       tmp=*x++;
    85       y_1=*y++;
    86       sum[0] = MAC16_16(sum[0],tmp,y_2);
    87       sum[1] = MAC16_16(sum[1],tmp,y_3);
    88       sum[2] = MAC16_16(sum[2],tmp,y_0);
    89       sum[3] = MAC16_16(sum[3],tmp,y_1);
    90       tmp=*x++;
    91       y_2=*y++;
    92       sum[0] = MAC16_16(sum[0],tmp,y_3);
    93       sum[1] = MAC16_16(sum[1],tmp,y_0);
    94       sum[2] = MAC16_16(sum[2],tmp,y_1);
    95       sum[3] = MAC16_16(sum[3],tmp,y_2);
    96    }
    97    if (j++<len)
    98    {
    99       opus_val16 tmp = *x++;
   100       y_3=*y++;
   101       sum[0] = MAC16_16(sum[0],tmp,y_0);
   102       sum[1] = MAC16_16(sum[1],tmp,y_1);
   103       sum[2] = MAC16_16(sum[2],tmp,y_2);
   104       sum[3] = MAC16_16(sum[3],tmp,y_3);
   105    }
   106    if (j++<len)
   107    {
   108       opus_val16 tmp=*x++;
   109       y_0=*y++;
   110       sum[0] = MAC16_16(sum[0],tmp,y_1);
   111       sum[1] = MAC16_16(sum[1],tmp,y_2);
   112       sum[2] = MAC16_16(sum[2],tmp,y_3);
   113       sum[3] = MAC16_16(sum[3],tmp,y_0);
   114    }
   115    if (j<len)
   116    {
   117       opus_val16 tmp=*x++;
   118       y_1=*y++;
   119       sum[0] = MAC16_16(sum[0],tmp,y_2);
   120       sum[1] = MAC16_16(sum[1],tmp,y_3);
   121       sum[2] = MAC16_16(sum[2],tmp,y_0);
   122       sum[3] = MAC16_16(sum[3],tmp,y_1);
   123    }
   124 }
   125 #endif /* OVERRIDE_XCORR_KERNEL */
   127 #ifndef OVERRIDE_DUAL_INNER_PROD
   128 static OPUS_INLINE void dual_inner_prod(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
   129       int N, opus_val32 *xy1, opus_val32 *xy2)
   130 {
   131    int i;
   132    opus_val32 xy01=0;
   133    opus_val32 xy02=0;
   134    for (i=0;i<N;i++)
   135    {
   136       xy01 = MAC16_16(xy01, x[i], y01[i]);
   137       xy02 = MAC16_16(xy02, x[i], y02[i]);
   138    }
   139    *xy1 = xy01;
   140    *xy2 = xy02;
   141 }
   142 #endif
   144 #ifdef FIXED_POINT
   145 opus_val32
   146 #else
   147 void
   148 #endif
   149 celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
   150       opus_val32 *xcorr, int len, int max_pitch);
   152 #if !defined(OVERRIDE_PITCH_XCORR)
   153 /*Is run-time CPU detection enabled on this platform?*/
   154 # if defined(OPUS_HAVE_RTCD)
   155 extern
   156 #  if defined(FIXED_POINT)
   157 opus_val32
   158 #  else
   159 void
   160 #  endif
   161 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
   162       const opus_val16 *, opus_val32 *, int, int);
   164 #  define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
   165   ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \
   166         xcorr, len, max_pitch))
   167 # else
   168 #  define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
   169   ((void)(arch),celt_pitch_xcorr_c(_x, _y, xcorr, len, max_pitch))
   170 # endif
   171 #endif
   173 #endif

mercurial