media/libopus/silk/resampler_private_up2_HQ.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libopus/silk/resampler_private_up2_HQ.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +/***********************************************************************
     1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved.
     1.6 +Redistribution and use in source and binary forms, with or without
     1.7 +modification, are permitted provided that the following conditions
     1.8 +are met:
     1.9 +- Redistributions of source code must retain the above copyright notice,
    1.10 +this list of conditions and the following disclaimer.
    1.11 +- Redistributions in binary form must reproduce the above copyright
    1.12 +notice, this list of conditions and the following disclaimer in the
    1.13 +documentation and/or other materials provided with the distribution.
    1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the
    1.15 +names of specific contributors, may be used to endorse or promote
    1.16 +products derived from this software without specific prior written
    1.17 +permission.
    1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 +POSSIBILITY OF SUCH DAMAGE.
    1.29 +***********************************************************************/
    1.30 +
    1.31 +#ifdef HAVE_CONFIG_H
    1.32 +#include "config.h"
    1.33 +#endif
    1.34 +
    1.35 +#include "SigProc_FIX.h"
    1.36 +#include "resampler_private.h"
    1.37 +
    1.38 +/* Upsample by a factor 2, high quality */
    1.39 +/* Uses 2nd order allpass filters for the 2x upsampling, followed by a      */
    1.40 +/* notch filter just above Nyquist.                                         */
    1.41 +void silk_resampler_private_up2_HQ(
    1.42 +    opus_int32                      *S,             /* I/O  Resampler state [ 6 ]       */
    1.43 +    opus_int16                      *out,           /* O    Output signal [ 2 * len ]   */
    1.44 +    const opus_int16                *in,            /* I    Input signal [ len ]        */
    1.45 +    opus_int32                      len             /* I    Number of input samples     */
    1.46 +)
    1.47 +{
    1.48 +    opus_int32 k;
    1.49 +    opus_int32 in32, out32_1, out32_2, Y, X;
    1.50 +
    1.51 +    silk_assert( silk_resampler_up2_hq_0[ 0 ] > 0 );
    1.52 +    silk_assert( silk_resampler_up2_hq_0[ 1 ] > 0 );
    1.53 +    silk_assert( silk_resampler_up2_hq_0[ 2 ] < 0 );
    1.54 +    silk_assert( silk_resampler_up2_hq_1[ 0 ] > 0 );
    1.55 +    silk_assert( silk_resampler_up2_hq_1[ 1 ] > 0 );
    1.56 +    silk_assert( silk_resampler_up2_hq_1[ 2 ] < 0 );
    1.57 +
    1.58 +    /* Internal variables and state are in Q10 format */
    1.59 +    for( k = 0; k < len; k++ ) {
    1.60 +        /* Convert to Q10 */
    1.61 +        in32 = silk_LSHIFT( (opus_int32)in[ k ], 10 );
    1.62 +
    1.63 +        /* First all-pass section for even output sample */
    1.64 +        Y       = silk_SUB32( in32, S[ 0 ] );
    1.65 +        X       = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 0 ] );
    1.66 +        out32_1 = silk_ADD32( S[ 0 ], X );
    1.67 +        S[ 0 ]  = silk_ADD32( in32, X );
    1.68 +
    1.69 +        /* Second all-pass section for even output sample */
    1.70 +        Y       = silk_SUB32( out32_1, S[ 1 ] );
    1.71 +        X       = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 1 ] );
    1.72 +        out32_2 = silk_ADD32( S[ 1 ], X );
    1.73 +        S[ 1 ]  = silk_ADD32( out32_1, X );
    1.74 +
    1.75 +        /* Third all-pass section for even output sample */
    1.76 +        Y       = silk_SUB32( out32_2, S[ 2 ] );
    1.77 +        X       = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_0[ 2 ] );
    1.78 +        out32_1 = silk_ADD32( S[ 2 ], X );
    1.79 +        S[ 2 ]  = silk_ADD32( out32_2, X );
    1.80 +
    1.81 +        /* Apply gain in Q15, convert back to int16 and store to output */
    1.82 +        out[ 2 * k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
    1.83 +
    1.84 +        /* First all-pass section for odd output sample */
    1.85 +        Y       = silk_SUB32( in32, S[ 3 ] );
    1.86 +        X       = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 0 ] );
    1.87 +        out32_1 = silk_ADD32( S[ 3 ], X );
    1.88 +        S[ 3 ]  = silk_ADD32( in32, X );
    1.89 +
    1.90 +        /* Second all-pass section for odd output sample */
    1.91 +        Y       = silk_SUB32( out32_1, S[ 4 ] );
    1.92 +        X       = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 1 ] );
    1.93 +        out32_2 = silk_ADD32( S[ 4 ], X );
    1.94 +        S[ 4 ]  = silk_ADD32( out32_1, X );
    1.95 +
    1.96 +        /* Third all-pass section for odd output sample */
    1.97 +        Y       = silk_SUB32( out32_2, S[ 5 ] );
    1.98 +        X       = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_1[ 2 ] );
    1.99 +        out32_1 = silk_ADD32( S[ 5 ], X );
   1.100 +        S[ 5 ]  = silk_ADD32( out32_2, X );
   1.101 +
   1.102 +        /* Apply gain in Q15, convert back to int16 and store to output */
   1.103 +        out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
   1.104 +    }
   1.105 +}
   1.106 +
   1.107 +void silk_resampler_private_up2_HQ_wrapper(
   1.108 +    void                            *SS,            /* I/O  Resampler state (unused)    */
   1.109 +    opus_int16                      *out,           /* O    Output signal [ 2 * len ]   */
   1.110 +    const opus_int16                *in,            /* I    Input signal [ len ]        */
   1.111 +    opus_int32                      len             /* I    Number of input samples     */
   1.112 +)
   1.113 +{
   1.114 +    silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
   1.115 +    silk_resampler_private_up2_HQ( S->sIIR, out, in, len );
   1.116 +}

mercurial