Line data Source code
1 : /***********************************************************************
2 : Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 : Redistribution and use in source and binary forms, with or without
4 : modification, are permitted provided that the following conditions
5 : are met:
6 : - Redistributions of source code must retain the above copyright notice,
7 : this list of conditions and the following disclaimer.
8 : - Redistributions in binary form must reproduce the above copyright
9 : notice, this list of conditions and the following disclaimer in the
10 : documentation and/or other materials provided with the distribution.
11 : - Neither the name of Internet Society, IETF or IETF Trust, nor the
12 : names of specific contributors, may be used to endorse or promote
13 : products derived from this software without specific prior written
14 : permission.
15 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 : AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 : ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 : LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 : CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 : SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 : INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 : CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 : ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 : POSSIBILITY OF SUCH DAMAGE.
26 : ***********************************************************************/
27 :
28 : #ifdef HAVE_CONFIG_H
29 : #include "config.h"
30 : #endif
31 :
32 : #include "SigProc_FIX.h"
33 : #include "resampler_private.h"
34 :
35 : /* Upsample by a factor 2, high quality */
36 : /* Uses 2nd order allpass filters for the 2x upsampling, followed by a */
37 : /* notch filter just above Nyquist. */
38 0 : void silk_resampler_private_up2_HQ(
39 : opus_int32 *S, /* I/O Resampler state [ 6 ] */
40 : opus_int16 *out, /* O Output signal [ 2 * len ] */
41 : const opus_int16 *in, /* I Input signal [ len ] */
42 : opus_int32 len /* I Number of input samples */
43 : )
44 : {
45 : opus_int32 k;
46 : opus_int32 in32, out32_1, out32_2, Y, X;
47 :
48 0 : silk_assert( silk_resampler_up2_hq_0[ 0 ] > 0 );
49 0 : silk_assert( silk_resampler_up2_hq_0[ 1 ] > 0 );
50 0 : silk_assert( silk_resampler_up2_hq_0[ 2 ] < 0 );
51 0 : silk_assert( silk_resampler_up2_hq_1[ 0 ] > 0 );
52 0 : silk_assert( silk_resampler_up2_hq_1[ 1 ] > 0 );
53 0 : silk_assert( silk_resampler_up2_hq_1[ 2 ] < 0 );
54 :
55 : /* Internal variables and state are in Q10 format */
56 0 : for( k = 0; k < len; k++ ) {
57 : /* Convert to Q10 */
58 0 : in32 = silk_LSHIFT( (opus_int32)in[ k ], 10 );
59 :
60 : /* First all-pass section for even output sample */
61 0 : Y = silk_SUB32( in32, S[ 0 ] );
62 0 : X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 0 ] );
63 0 : out32_1 = silk_ADD32( S[ 0 ], X );
64 0 : S[ 0 ] = silk_ADD32( in32, X );
65 :
66 : /* Second all-pass section for even output sample */
67 0 : Y = silk_SUB32( out32_1, S[ 1 ] );
68 0 : X = silk_SMULWB( Y, silk_resampler_up2_hq_0[ 1 ] );
69 0 : out32_2 = silk_ADD32( S[ 1 ], X );
70 0 : S[ 1 ] = silk_ADD32( out32_1, X );
71 :
72 : /* Third all-pass section for even output sample */
73 0 : Y = silk_SUB32( out32_2, S[ 2 ] );
74 0 : X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_0[ 2 ] );
75 0 : out32_1 = silk_ADD32( S[ 2 ], X );
76 0 : S[ 2 ] = silk_ADD32( out32_2, X );
77 :
78 : /* Apply gain in Q15, convert back to int16 and store to output */
79 0 : out[ 2 * k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
80 :
81 : /* First all-pass section for odd output sample */
82 0 : Y = silk_SUB32( in32, S[ 3 ] );
83 0 : X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 0 ] );
84 0 : out32_1 = silk_ADD32( S[ 3 ], X );
85 0 : S[ 3 ] = silk_ADD32( in32, X );
86 :
87 : /* Second all-pass section for odd output sample */
88 0 : Y = silk_SUB32( out32_1, S[ 4 ] );
89 0 : X = silk_SMULWB( Y, silk_resampler_up2_hq_1[ 1 ] );
90 0 : out32_2 = silk_ADD32( S[ 4 ], X );
91 0 : S[ 4 ] = silk_ADD32( out32_1, X );
92 :
93 : /* Third all-pass section for odd output sample */
94 0 : Y = silk_SUB32( out32_2, S[ 5 ] );
95 0 : X = silk_SMLAWB( Y, Y, silk_resampler_up2_hq_1[ 2 ] );
96 0 : out32_1 = silk_ADD32( S[ 5 ], X );
97 0 : S[ 5 ] = silk_ADD32( out32_2, X );
98 :
99 : /* Apply gain in Q15, convert back to int16 and store to output */
100 0 : out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( out32_1, 10 ) );
101 : }
102 0 : }
103 :
104 0 : void silk_resampler_private_up2_HQ_wrapper(
105 : void *SS, /* I/O Resampler state (unused) */
106 : opus_int16 *out, /* O Output signal [ 2 * len ] */
107 : const opus_int16 *in, /* I Input signal [ len ] */
108 : opus_int32 len /* I Number of input samples */
109 : )
110 : {
111 0 : silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
112 0 : silk_resampler_private_up2_HQ( S->sIIR, out, in, len );
113 0 : }
|