1 /***********************************************************************
2 Copyright (c) 2006-2010, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, (subject to the limitations in the disclaimer below)
5 are permitted provided that the following conditions 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 Skype Limited, nor the names of specific
12 contributors, may be used to endorse or promote products derived from
13 this software without specific prior written permission.
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27 
28 /*                                                                      *
29  * File Name:    SKP_Silk_resample_4_3.c                              *
30  *                                                                      *
31  * Resamples by a factor 4/3                                            *
32  *                                                                      *
33  * Copyright 2009 (c), Skype Limited                                    *
34  * All rights reserved.                                                 *
35  *                                                                      *
36  * Date: 090407                                                         *
37  *                                                                      */
38 
39 #include "SKP_Silk_SigProc_FIX.h"
40 
41 #define OUT_SUBFR_LEN        80
42 
43 /* Resamples by a factor 4/3 */
SKP_Silk_resample_4_3(SKP_int16 * out,SKP_int32 * S,const SKP_int16 * in,const SKP_int inLen)44 void SKP_Silk_resample_4_3(
45     SKP_int16            *out,       /* O:   Fs_low signal    [inLen * 4/3]           */
46     SKP_int32            *S,         /* I/O: State vector    [7+4+4]                  */
47     const SKP_int16      *in,        /* I:   Fs_high signal    [inLen]                */
48     const SKP_int        inLen       /* I:   input length, must be a multiple of 3    */
49 )
50 {
51     SKP_int      outLen, LSubFrameIn, LSubFrameOut;
52     SKP_int16    outH[    3 * OUT_SUBFR_LEN ];
53     SKP_int16    outHH[   6 * OUT_SUBFR_LEN ];
54     SKP_int32    scratch[ 9 * OUT_SUBFR_LEN / 2 ];
55 
56     /* Check that input is multiple of 3 */
57     SKP_assert( inLen % 3 == 0 );
58 
59     outLen = SKP_DIV32_16( SKP_LSHIFT( inLen, 2 ), 3 );
60     while( outLen > 0 ) {
61         LSubFrameOut = SKP_min_int( OUT_SUBFR_LEN, outLen );
62         LSubFrameIn  = SKP_SMULWB( 49152, LSubFrameOut );
63 
64         /* Upsample two times by a factor 2 */
65         /* Scratch size needs to be: 3 * LSubFrameIn * sizeof( SKP_int32 ) */
66         SKP_Silk_resample_2_1_coarse( in,   &S[ 0 ], outH,  scratch,             LSubFrameIn      );
67         /* Scratch size needs to be: 6 * LSubFrameIn * sizeof( SKP_int32 ) */
68         SKP_Silk_resample_2_1_coarse( outH, &S[ 4 ], outHH, scratch, SKP_LSHIFT( LSubFrameIn, 1 ) );
69 
70         /* Downsample by a factor 3 */
71         SKP_Silk_resample_1_3( out, &S[ 8 ], outHH, SKP_LSHIFT( LSubFrameIn, 2 ) );
72 
73         in     += LSubFrameIn;
74         out    += LSubFrameOut;
75         outLen -= LSubFrameOut;
76     }
77 }
78