]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Silk part two... doh
authorBrian West <brian@freeswitch.org>
Thu, 25 Aug 2011 22:30:25 +0000 (17:30 -0500)
committerBrian West <brian@freeswitch.org>
Thu, 25 Aug 2011 22:30:25 +0000 (17:30 -0500)
29 files changed:
libs/silk/src/SKP_Silk_apply_sine_window_new.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_control_audio_bandwidth.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_decode_pitch.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_down2.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_down2_3.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_down3.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private.h [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_AR2.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_ARMA4.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_IIR_FIR.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_copy.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_down4.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_down_FIR.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_up2_HQ.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_private_up4.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_rom.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_rom.h [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_structs.h [new file with mode: 0644]
libs/silk/src/SKP_Silk_resampler_up2.c [new file with mode: 0644]
libs/silk/src/SKP_Silk_setup_complexity.h [new file with mode: 0644]
libs/silk/src/SKP_Silk_tuning_parameters.h [new file with mode: 0644]
libs/silk/src/SKP_Silk_warped_autocorrelation_FIX.c [new file with mode: 0644]
libs/silk/test_vectors/How to use the test vectors.txt [new file with mode: 0644]
libs/silk/test_vectors/test_decoder.bat [new file with mode: 0644]
libs/silk/test_vectors/test_decoder.sh [new file with mode: 0644]
libs/silk/test_vectors/test_encoder.bat [new file with mode: 0644]
libs/silk/test_vectors/test_encoder.sh [new file with mode: 0644]
src/mod/codecs/mod_silk/mod_silk.c

diff --git a/libs/silk/src/SKP_Silk_apply_sine_window_new.c b/libs/silk/src/SKP_Silk_apply_sine_window_new.c
new file mode 100644 (file)
index 0000000..b4db18e
--- /dev/null
@@ -0,0 +1,101 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+\r
+/* Apply sine window to signal vector.                                      */\r
+/* Window types:                                                            */\r
+/*    1 -> sine window from 0 to pi/2                                       */\r
+/*    2 -> sine window from pi/2 to pi                                      */\r
+/* Every other sample is linearly interpolated, for speed.                  */\r
+/* Window length must be between 16 and 120 (incl) and a multiple of 4.     */\r
+\r
+/* Matlab code for table: \r
+   for k=16:9*4:16+2*9*4, fprintf(' %7.d,', -round(65536*pi ./ (k:4:k+8*4))); fprintf('\n'); end\r
+*/\r
+static SKP_int16 freq_table_Q16[ 27 ] = {\r
+   12111,    9804,    8235,    7100,    6239,    5565,    5022,    4575,    4202,\r
+    3885,    3612,    3375,    3167,    2984,    2820,    2674,    2542,    2422,\r
+    2313,    2214,    2123,    2038,    1961,    1889,    1822,    1760,    1702,\r
+};\r
+\r
+\r
+void SKP_Silk_apply_sine_window_new(\r
+    SKP_int16                        px_win[],            /* O    Pointer to windowed signal                  */\r
+    const SKP_int16                  px[],                /* I    Pointer to input signal                     */\r
+    const SKP_int                    win_type,            /* I    Selects a window type                       */\r
+    const SKP_int                    length               /* I    Window length, multiple of 4                */\r
+)\r
+{\r
+    SKP_int   k, f_Q16, c_Q16;\r
+    SKP_int32 S0_Q16, S1_Q16;\r
+    SKP_assert( win_type == 1 || win_type == 2 );\r
+\r
+    /* Length must be in a range from 16 to 120 and a multiple of 4 */\r
+    SKP_assert( length >= 16 && length <= 120 );\r
+    SKP_assert( ( length & 3 ) == 0 );\r
+\r
+    /* Input pointer must be 4-byte aligned */\r
+    SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )px - ( SKP_int8* )0 ) & 3 ) == 0 );\r
+\r
+    /* Frequency */\r
+    k = ( length >> 2 ) - 4;\r
+    SKP_assert( k >= 0 && k <= 26 );\r
+    f_Q16 = (SKP_int)freq_table_Q16[ k ];\r
+\r
+    /* Factor used for cosine approximation */\r
+    c_Q16 = SKP_SMULWB( f_Q16, -f_Q16 );\r
+    SKP_assert( c_Q16 >= -32768 );\r
+\r
+    /* initialize state */\r
+    if( win_type == 1 ) {\r
+        /* start from 0 */\r
+        S0_Q16 = 0;\r
+        /* approximation of sin(f) */\r
+        S1_Q16 = f_Q16 + SKP_RSHIFT( length, 3 );\r
+    } else {\r
+        /* start from 1 */\r
+        S0_Q16 = ( 1 << 16 );\r
+        /* approximation of cos(f) */\r
+        S1_Q16 = ( 1 << 16 ) + SKP_RSHIFT( c_Q16, 1 ) + SKP_RSHIFT( length, 4 );\r
+    }\r
+\r
+    /* Uses the recursive equation:   sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f)    */\r
+    /* 4 samples at a time */\r
+    for( k = 0; k < length; k += 4 ) {\r
+        px_win[ k ]     = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k ] );\r
+        px_win[ k + 1 ] = (SKP_int16)SKP_SMULWB( S1_Q16, px[ k + 1] );\r
+        S0_Q16 = SKP_SMULWB( S1_Q16, c_Q16 ) + SKP_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1;\r
+        S0_Q16 = SKP_min( S0_Q16, ( 1 << 16 ) );\r
+\r
+        px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px[ k + 2] );\r
+        px_win[ k + 3 ] = (SKP_int16)SKP_SMULWB( S0_Q16, px[ k + 3 ] );\r
+        S1_Q16 = SKP_SMULWB( S0_Q16, c_Q16 ) + SKP_LSHIFT( S0_Q16, 1 ) - S1_Q16;\r
+        S1_Q16 = SKP_min( S1_Q16, ( 1 << 16 ) );\r
+    }\r
+}\r
+\r
diff --git a/libs/silk/src/SKP_Silk_control_audio_bandwidth.c b/libs/silk/src/SKP_Silk_control_audio_bandwidth.c
new file mode 100644 (file)
index 0000000..bf8b318
--- /dev/null
@@ -0,0 +1,137 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main.h"\r
+\r
+/* Control internal sampling rate */\r
+SKP_int SKP_Silk_control_audio_bandwidth(\r
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */\r
+    const SKP_int32             TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
+)\r
+{\r
+    SKP_int fs_kHz;\r
+\r
+    fs_kHz = psEncC->fs_kHz;\r
+    if( fs_kHz == 0 ) {\r
+        /* Encoder has just been initialized */\r
+        if( TargetRate_bps >= SWB2WB_BITRATE_BPS ) {\r
+            fs_kHz = 24;\r
+        } else if( TargetRate_bps >= WB2MB_BITRATE_BPS ) {\r
+            fs_kHz = 16;\r
+        } else if( TargetRate_bps >= MB2NB_BITRATE_BPS ) {\r
+            fs_kHz = 12;\r
+        } else {\r
+            fs_kHz = 8;\r
+        }\r
+        /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */\r
+        fs_kHz = SKP_min( fs_kHz, SKP_DIV32_16( psEncC->API_fs_Hz, 1000 ) );\r
+        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );\r
+    } else if( SKP_SMULBB( fs_kHz, 1000 ) > psEncC->API_fs_Hz || fs_kHz > psEncC->maxInternal_fs_kHz ) {\r
+        /* Make sure internal rate is not higher than external rate or maximum allowed */\r
+        fs_kHz = SKP_DIV32_16( psEncC->API_fs_Hz, 1000 );\r
+        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );\r
+    } else {\r
+        /* State machine for the internal sampling rate switching */\r
+        if( psEncC->API_fs_Hz > 8000 ) {\r
+            /* Accumulate the difference between the target rate and limit for switching down */\r
+            psEncC->bitrateDiff += SKP_MUL( psEncC->PacketSize_ms, psEncC->TargetRate_bps - psEncC->bitrate_threshold_down );\r
+            psEncC->bitrateDiff  = SKP_min( psEncC->bitrateDiff, 0 );\r
+\r
+            if( psEncC->vadFlag == NO_VOICE_ACTIVITY ) { /* Low speech activity */\r
+                /* Check if we should switch down */\r
+#if SWITCH_TRANSITION_FILTERING \r
+                if( ( psEncC->sLP.transition_frame_no == 0 ) &&                         /* Transition phase not active */\r
+                    ( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ||              /* Bitrate threshold is met */\r
+                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz == 24 ) ) ) {     /* Forced down-switching due to WB input */\r
+                        psEncC->sLP.transition_frame_no = 1;                            /* Begin transition phase */\r
+                        psEncC->sLP.mode                = 0;                            /* Switch down */\r
+                } else if( \r
+                    ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) &&    /* Transition phase complete */\r
+                    ( psEncC->sLP.mode == 0 ) ) {                                       /* Ready to switch down */\r
+                        psEncC->sLP.transition_frame_no = 0;                            /* Ready for new transition phase */\r
+#else\r
+                if( psEncC->bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) {               /* Bitrate threshold is met */ \r
+#endif            \r
+                    psEncC->bitrateDiff = 0;\r
+\r
+                    /* Switch to a lower sample frequency */\r
+                    if( psEncC->fs_kHz == 24 ) {\r
+                        fs_kHz = 16;\r
+                    } else if( psEncC->fs_kHz == 16 ) {\r
+                        fs_kHz = 12;\r
+                    } else {\r
+                        SKP_assert( psEncC->fs_kHz == 12 );\r
+                        fs_kHz = 8;\r
+                    }\r
+                }\r
+\r
+                /* Check if we should switch up */\r
+                if( ( ( psEncC->fs_kHz * 1000 < psEncC->API_fs_Hz ) &&\r
+                    ( psEncC->TargetRate_bps >= psEncC->bitrate_threshold_up ) && \r
+                    ( psEncC->sSWBdetect.WB_detected * psEncC->fs_kHz < 16 ) ) && \r
+                    ( ( ( psEncC->fs_kHz == 16 ) && ( psEncC->maxInternal_fs_kHz >= 24 ) ) || \r
+                    (   ( psEncC->fs_kHz == 12 ) && ( psEncC->maxInternal_fs_kHz >= 16 ) ) ||\r
+                    (   ( psEncC->fs_kHz ==  8 ) && ( psEncC->maxInternal_fs_kHz >= 12 ) ) ) \r
+#if SWITCH_TRANSITION_FILTERING\r
+                    && ( psEncC->sLP.transition_frame_no == 0 ) ) { /* No transition phase running, ready to switch */\r
+                        psEncC->sLP.mode = 1; /* Switch up */\r
+#else\r
+                    ) {\r
+#endif\r
+                    psEncC->bitrateDiff = 0;\r
+\r
+                    /* Switch to a higher sample frequency */\r
+                    if( psEncC->fs_kHz == 8 ) {\r
+                        fs_kHz = 12;\r
+                    } else if( psEncC->fs_kHz == 12 ) {\r
+                        fs_kHz = 16;\r
+                    } else {\r
+                        SKP_assert( psEncC->fs_kHz == 16 );\r
+                        fs_kHz = 24;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+#if SWITCH_TRANSITION_FILTERING\r
+        /* After switching up, stop transition filter during speech inactivity */\r
+        if( ( psEncC->sLP.mode == 1 ) &&\r
+            ( psEncC->sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) && \r
+            ( psEncC->vadFlag == NO_VOICE_ACTIVITY ) ) {\r
+\r
+                psEncC->sLP.transition_frame_no = 0;\r
+\r
+                /* Reset transition filter state */\r
+                SKP_memset( psEncC->sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );\r
+        }\r
+#endif\r
+    }\r
+\r
+\r
+\r
+    return fs_kHz;\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_decode_pitch.c b/libs/silk/src/SKP_Silk_decode_pitch.c
new file mode 100644 (file)
index 0000000..d625996
--- /dev/null
@@ -0,0 +1,57 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/***********************************************************\r
+* Pitch analyser function\r
+********************************************************** */\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_common_pitch_est_defines.h"\r
+\r
+void SKP_Silk_decode_pitch(\r
+    SKP_int          lagIndex,                        /* I                             */\r
+    SKP_int          contourIndex,                    /* O                             */\r
+    SKP_int          pitch_lags[],                    /* O 4 pitch values              */\r
+    SKP_int          Fs_kHz                           /* I sampling frequency (kHz)    */\r
+)\r
+{\r
+    SKP_int lag, i, min_lag;\r
+\r
+    min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz );\r
+\r
+    /* Only for 24 / 16 kHz version for now */\r
+    lag = min_lag + lagIndex;\r
+    if( Fs_kHz == 8 ) {\r
+        /* Only a small codebook for 8 khz */\r
+        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {\r
+            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ];\r
+        }\r
+    } else {\r
+        for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {\r
+            pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ];\r
+        }\r
+    }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler.c b/libs/silk/src/SKP_Silk_resampler.c
new file mode 100644 (file)
index 0000000..980f81f
--- /dev/null
@@ -0,0 +1,323 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler.c                                                                    *\r
+ *                                                                                                                                             *\r
+ * Description: Interface to collection of resamplers                                  *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                      */\r
+\r
+/* Matrix of resampling methods used:\r
+ *                                        Fs_out (kHz)\r
+ *                        8      12     16     24     32     44.1   48\r
+ *\r
+ *               8        C      UF     U      UF     UF     UF     UF\r
+ *              12        AF     C      UF     U      UF     UF     UF\r
+ *              16        D      AF     C      UF     U      UF     UF\r
+ * Fs_in (kHz)  24        AIF    D      AF     C      UF     UF     U\r
+ *              32        UF     AF     D      AF     C      UF     UF\r
+ *              44.1      AMI    AMI    AMI    AMI    AMI    C      UF\r
+ *              48        DAF    DAF    AF     D      AF     UF     C\r
+ *\r
+ * default method: UF\r
+ *\r
+ * C   -> Copy (no resampling)\r
+ * D   -> Allpass-based 2x downsampling\r
+ * U   -> Allpass-based 2x upsampling\r
+ * DAF -> Allpass-based 2x downsampling followed by AR2 filter followed by FIR interpolation\r
+ * UF  -> Allpass-based 2x upsampling followed by FIR interpolation\r
+ * AMI -> ARMA4 filter followed by FIR interpolation\r
+ * AF  -> AR2 filter followed by FIR interpolation\r
+ *\r
+ * Input signals sampled above 48 kHz are first downsampled to at most 48 kHz.\r
+ * Output signals sampled above 48 kHz are upsampled from at most 48 kHz.\r
+ */\r
+\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Greatest common divisor */\r
+static SKP_int32 gcd(\r
+    SKP_int32 a,\r
+    SKP_int32 b\r
+)\r
+{\r
+    SKP_int32 tmp;\r
+    while( b > 0 ) {\r
+        tmp = a - b * SKP_DIV32( a, b );\r
+        a   = b;\r
+        b   = tmp;\r
+    }\r
+    return a;\r
+}\r
+\r
+/* Initialize/reset the resampler state for a given pair of input/output sampling rates */\r
+SKP_int SKP_Silk_resampler_init( \r
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
+       SKP_int32                                                       Fs_Hz_in,       /* I:   Input sampling rate (Hz)        */\r
+       SKP_int32                                                       Fs_Hz_out       /* I:   Output sampling rate (Hz)       */\r
+)\r
+{\r
+    SKP_int32 cycleLen, cyclesPerBatch, up2 = 0, down2 = 0;\r
+\r
+       /* Clear state */\r
+       SKP_memset( S, 0, sizeof( SKP_Silk_resampler_state_struct ) );\r
+\r
+       /* Input checking */\r
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
+       if( Fs_Hz_in < 8000 || Fs_Hz_in > 192000 || Fs_Hz_out < 8000 || Fs_Hz_out > 192000 ) {\r
+#else\r
+    if( Fs_Hz_in < 8000 || Fs_Hz_in >  48000 || Fs_Hz_out < 8000 || Fs_Hz_out >  48000 ) {\r
+#endif\r
+               SKP_assert( 0 );\r
+               return -1;\r
+       }\r
+\r
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
+       /* Determine pre downsampling and post upsampling */\r
+       if( Fs_Hz_in > 96000 ) {\r
+               S->nPreDownsamplers = 2;\r
+        S->down_pre_function = SKP_Silk_resampler_private_down4;\r
+    } else if( Fs_Hz_in > 48000 ) {\r
+               S->nPreDownsamplers = 1;\r
+        S->down_pre_function = SKP_Silk_resampler_down2;\r
+    } else {\r
+               S->nPreDownsamplers = 0;\r
+        S->down_pre_function = NULL;\r
+    }\r
+\r
+       if( Fs_Hz_out > 96000 ) {\r
+               S->nPostUpsamplers = 2;\r
+        S->up_post_function = SKP_Silk_resampler_private_up4;\r
+    } else if( Fs_Hz_out > 48000 ) {\r
+               S->nPostUpsamplers = 1;\r
+        S->up_post_function = SKP_Silk_resampler_up2;\r
+    } else {\r
+               S->nPostUpsamplers = 0;\r
+        S->up_post_function = NULL;\r
+    }\r
+\r
+    if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {\r
+        /* Ratio of output/input samples */\r
+           S->ratio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_out, 13 ), Fs_Hz_in ), 3 );\r
+        /* Make sure the ratio is rounded up */\r
+        while( SKP_SMULWW( S->ratio_Q16, Fs_Hz_in ) < Fs_Hz_out ) S->ratio_Q16++;\r
+\r
+        /* Batch size is 10 ms */\r
+        S->batchSizePrePost = SKP_DIV32_16( Fs_Hz_in, 100 );\r
+\r
+        /* Convert sampling rate to those after pre-downsampling and before post-upsampling */\r
+           Fs_Hz_in  = SKP_RSHIFT( Fs_Hz_in,  S->nPreDownsamplers  );\r
+           Fs_Hz_out = SKP_RSHIFT( Fs_Hz_out, S->nPostUpsamplers  );\r
+    }\r
+#endif\r
+\r
+    /* Number of samples processed per batch */\r
+    /* First, try 10 ms frames */\r
+    S->batchSize = SKP_DIV32_16( Fs_Hz_in, 100 );\r
+    if( ( SKP_MUL( S->batchSize, 100 ) != Fs_Hz_in ) || ( Fs_Hz_in % 100 != 0 ) ) {\r
+        /* No integer number of input or output samples with 10 ms frames, use greatest common divisor */\r
+        cycleLen = SKP_DIV32( Fs_Hz_in, gcd( Fs_Hz_in, Fs_Hz_out ) );\r
+        cyclesPerBatch = SKP_DIV32( RESAMPLER_MAX_BATCH_SIZE_IN, cycleLen );\r
+        if( cyclesPerBatch == 0 ) {\r
+            /* cycleLen too big, let's just use the maximum batch size. Some distortion will result. */\r
+            S->batchSize = RESAMPLER_MAX_BATCH_SIZE_IN;\r
+            SKP_assert( 0 );\r
+        } else {\r
+            S->batchSize = SKP_MUL( cyclesPerBatch, cycleLen );\r
+        }\r
+    }\r
+\r
+\r
+       /* Find resampler with the right sampling ratio */\r
+    if( Fs_Hz_out > Fs_Hz_in ) {\r
+        /* Upsample */\r
+        if( Fs_Hz_out == SKP_MUL( Fs_Hz_in, 2 ) ) {                             /* Fs_out : Fs_in = 2 : 1 */\r
+            /* Special case: directly use 2x upsampler */\r
+           S->resampler_function = SKP_Silk_resampler_private_up2_HQ_wrapper;\r
+        } else {\r
+               /* Default resampler */\r
+               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+            up2 = 1;\r
+            if( Fs_Hz_in > 24000 ) {\r
+                /* Low-quality all-pass upsampler */\r
+                S->up2_function = SKP_Silk_resampler_up2;\r
+            } else {\r
+                /* High-quality all-pass upsampler */\r
+                S->up2_function = SKP_Silk_resampler_private_up2_HQ;\r
+            }\r
+        }\r
+    } else if ( Fs_Hz_out < Fs_Hz_in ) {\r
+        /* Downsample */\r
+        if( SKP_MUL( Fs_Hz_out, 4 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {               /* Fs_out : Fs_in = 3 : 4 */\r
+           S->FIR_Fracs = 3;\r
+           S->Coefs = SKP_Silk_Resampler_3_4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 3 ) == SKP_MUL( Fs_Hz_in, 2 ) ) {        /* Fs_out : Fs_in = 2 : 3 */\r
+           S->FIR_Fracs = 2;\r
+           S->Coefs = SKP_Silk_Resampler_2_3_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 2 */\r
+           S->FIR_Fracs = 1;\r
+           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 8 ) == SKP_MUL( Fs_Hz_in, 3 ) ) {        /* Fs_out : Fs_in = 3 : 8 */\r
+           S->FIR_Fracs = 3;\r
+           S->Coefs = SKP_Silk_Resampler_3_8_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 3 */\r
+           S->FIR_Fracs = 1;\r
+           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 4 */\r
+           S->FIR_Fracs = 1;\r
+            down2 = 1;\r
+           S->Coefs = SKP_Silk_Resampler_1_2_COEFS;\r
+            S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) {                      /* Fs_out : Fs_in = 1 : 6 */\r
+           S->FIR_Fracs = 1;\r
+            down2 = 1;\r
+           S->Coefs = SKP_Silk_Resampler_1_3_COEFS;\r
+            S->resampler_function = SKP_Silk_resampler_private_down_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 80 ) ) {     /* Fs_out : Fs_in = 80 : 441 */\r
+           S->Coefs = SKP_Silk_Resampler_80_441_ARMA4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 120 ) ) {    /* Fs_out : Fs_in = 120 : 441 */\r
+           S->Coefs = SKP_Silk_Resampler_120_441_ARMA4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 160 ) ) {    /* Fs_out : Fs_in = 160 : 441 */\r
+           S->Coefs = SKP_Silk_Resampler_160_441_ARMA4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 240 ) ) {    /* Fs_out : Fs_in = 240 : 441 */\r
+           S->Coefs = SKP_Silk_Resampler_240_441_ARMA4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+        } else if( SKP_MUL( Fs_Hz_out, 441 ) == SKP_MUL( Fs_Hz_in, 320 ) ) {    /* Fs_out : Fs_in = 320 : 441 */\r
+           S->Coefs = SKP_Silk_Resampler_320_441_ARMA4_COEFS;\r
+           S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+        } else {\r
+               /* Default resampler */\r
+               S->resampler_function = SKP_Silk_resampler_private_IIR_FIR;\r
+            up2 = 1;\r
+            if( Fs_Hz_in > 24000 ) {\r
+                /* Low-quality all-pass upsampler */\r
+                S->up2_function = SKP_Silk_resampler_up2;\r
+            } else {\r
+                /* High-quality all-pass upsampler */\r
+                S->up2_function = SKP_Silk_resampler_private_up2_HQ;\r
+            }\r
+        }\r
+    } else {\r
+        /* Input and output sampling rates are equal: copy */\r
+        S->resampler_function = SKP_Silk_resampler_private_copy;\r
+    }\r
+\r
+    S->input2x = up2 | down2;\r
+\r
+    /* Ratio of input/output samples */\r
+    S->invRatio_Q16 = SKP_LSHIFT32( SKP_DIV32( SKP_LSHIFT32( Fs_Hz_in, 14 + up2 - down2 ), Fs_Hz_out ), 2 );\r
+    /* Make sure the ratio is rounded up */\r
+    while( SKP_SMULWW( S->invRatio_Q16, SKP_LSHIFT32( Fs_Hz_out, down2 ) ) < SKP_LSHIFT32( Fs_Hz_in, up2 ) ) {\r
+        S->invRatio_Q16++;\r
+    }\r
+\r
+       S->magic_number = 123456789;\r
+\r
+       return 0;\r
+}\r
+\r
+/* Clear the states of all resampling filters, without resetting sampling rate ratio */\r
+SKP_int SKP_Silk_resampler_clear( \r
+       SKP_Silk_resampler_state_struct *S                  /* I/O: Resampler state                     */\r
+)\r
+{\r
+       /* Clear state */\r
+       SKP_memset( S->sDown2, 0, sizeof( S->sDown2 ) );\r
+       SKP_memset( S->sIIR,   0, sizeof( S->sIIR ) );\r
+       SKP_memset( S->sFIR,   0, sizeof( S->sFIR ) );\r
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
+       SKP_memset( S->sDownPre, 0, sizeof( S->sDownPre ) );\r
+       SKP_memset( S->sUpPost,  0, sizeof( S->sUpPost ) );\r
+#endif\r
+    return 0;\r
+}\r
+\r
+/* Resampler: convert from one sampling rate to another                                 */\r
+SKP_int SKP_Silk_resampler( \r
+       SKP_Silk_resampler_state_struct *S,                 /* I/O: Resampler state                     */\r
+       SKP_int16                                                       out[],      /* O:       Output signal                           */\r
+       const SKP_int16                                         in[],       /* I:       Input signal                            */\r
+       SKP_int32                                                       inLen       /* I:       Number of input samples         */\r
+)\r
+{\r
+       /* Verify that state was initialized and has not been corrupted */\r
+    if( S->magic_number != 123456789 ) {\r
+        SKP_assert( 0 );\r
+        return -1;\r
+    }\r
+\r
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
+       if( S->nPreDownsamplers + S->nPostUpsamplers > 0 ) {\r
+               /* The input and/or output sampling rate is above 48000 Hz */\r
+        SKP_int32       nSamplesIn, nSamplesOut;\r
+               SKP_int16               in_buf[ 480 ], out_buf[ 480 ];\r
+\r
+        while( inLen > 0 ) {\r
+            /* Number of input and output samples to process */\r
+               nSamplesIn = SKP_min( inLen, S->batchSizePrePost );\r
+            nSamplesOut = SKP_SMULWB( S->ratio_Q16, nSamplesIn );\r
+\r
+            SKP_assert( SKP_RSHIFT32( nSamplesIn,  S->nPreDownsamplers ) <= 480 );\r
+            SKP_assert( SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers  ) <= 480 );\r
+\r
+               if( S->nPreDownsamplers > 0 ) {\r
+                S->down_pre_function( S->sDownPre, in_buf, in, nSamplesIn );\r
+                   if( S->nPostUpsamplers > 0 ) {\r
+                       S->resampler_function( S, out_buf, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
+                    S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );\r
+                } else {\r
+                       S->resampler_function( S, out, in_buf, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
+                }\r
+            } else {\r
+                       S->resampler_function( S, out_buf, in, SKP_RSHIFT32( nSamplesIn, S->nPreDownsamplers ) );\r
+                S->up_post_function( S->sUpPost, out, out_buf, SKP_RSHIFT32( nSamplesOut, S->nPostUpsamplers ) );\r
+            }\r
+\r
+               in += nSamplesIn;\r
+            out += nSamplesOut;\r
+               inLen -= nSamplesIn;\r
+        }\r
+       } else \r
+#endif\r
+       {\r
+               /* Input and output sampling rate are at most 48000 Hz */\r
+               S->resampler_function( S, out, in, inLen );\r
+       }\r
+\r
+       return 0;\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_down2.c b/libs/silk/src/SKP_Silk_resampler_down2.c
new file mode 100644 (file)
index 0000000..619442c
--- /dev/null
@@ -0,0 +1,77 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_down2.c                                         *\r
+ *                                                                      *\r
+ * Downsample by a factor 2, mediocre quality                           *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_rom.h"\r
+\r
+/* Downsample by a factor 2, mediocre quality */\r
+void SKP_Silk_resampler_down2(\r
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
+    SKP_int16                           *out,       /* O:   Output signal [ len ]               */\r
+    const SKP_int16                     *in,        /* I:   Input signal [ floor(len/2) ]       */\r
+    SKP_int32                           inLen       /* I:   Number of input samples             */\r
+)\r
+{\r
+    SKP_int32 k, len2 = SKP_RSHIFT32( inLen, 1 );\r
+    SKP_int32 in32, out32, Y, X;\r
+\r
+    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );\r
+    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );\r
+\r
+    /* Internal variables and state are in Q10 format */\r
+    for( k = 0; k < len2; k++ ) {\r
+        /* Convert to Q10 */\r
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );\r
+\r
+        /* All-pass section for even input sample */\r
+        Y      = SKP_SUB32( in32, S[ 0 ] );\r
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );\r
+        out32  = SKP_ADD32( S[ 0 ], X );\r
+        S[ 0 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Convert to Q10 */\r
+        in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );\r
+\r
+        /* All-pass section for odd input sample, and add to output of previous section */\r
+        Y      = SKP_SUB32( in32, S[ 1 ] );\r
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );\r
+        out32  = SKP_ADD32( out32, S[ 1 ] );\r
+        out32  = SKP_ADD32( out32, X );\r
+        S[ 1 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Add, convert back to int16 and store to output */\r
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );\r
+    }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_down2_3.c b/libs/silk/src/SKP_Silk_resampler_down2_3.c
new file mode 100644 (file)
index 0000000..31089f9
--- /dev/null
@@ -0,0 +1,102 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_down2_3.c                                       *\r
+ *                                                                      *\r
+ * Downsample by a factor 2/3, low quality                              *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+#define ORDER_FIR                   4\r
+\r
+/* Downsample by a factor 2/3, low quality */\r
+void SKP_Silk_resampler_down2_3(\r
+    SKP_int32                           *S,         /* I/O: State vector [ 6 ]                  */\r
+    SKP_int16                           *out,       /* O:   Output signal [ floor(2*inLen/3) ]  */\r
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
+    SKP_int32                           inLen       /* I:   Number of input samples             */\r
+)\r
+{\r
+       SKP_int32 nSamplesIn, counter, res_Q6;\r
+       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];\r
+       SKP_int32 *buf_ptr;\r
+\r
+       /* Copy buffered samples to start of buffer */  \r
+       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );\r
+\r
+       /* Iterate over blocks of frameSizeIn input samples */\r
+       while( 1 ) {\r
+               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );\r
+\r
+           /* Second-order AR filter (output in Q8) */\r
+           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, \r
+            SKP_Silk_Resampler_2_3_COEFS_LQ, nSamplesIn );\r
+\r
+               /* Interpolate filtered signal */\r
+        buf_ptr = buf;\r
+        counter = nSamplesIn;\r
+        while( counter > 2 ) {\r
+            /* Inner product */\r
+                   res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );\r
+\r
+            /* Scale down, saturate and store in output array */\r
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
+\r
+                   res_Q6 = SKP_SMULWB(         buf_ptr[ 1 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 4 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 5 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 3 ] );\r
+                   res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 ] );\r
+\r
+            /* Scale down, saturate and store in output array */\r
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
+\r
+            buf_ptr += 3;\r
+            counter -= 3;\r
+        }\r
+\r
+               in += nSamplesIn;\r
+               inLen -= nSamplesIn;\r
+\r
+               if( inLen > 0 ) {\r
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
+                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
+               } else {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* Copy last part of filtered signal to the state for the next call */\r
+       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_down3.c b/libs/silk/src/SKP_Silk_resampler_down3.c
new file mode 100644 (file)
index 0000000..70c86f6
--- /dev/null
@@ -0,0 +1,93 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_down3.c                                         *\r
+ *                                                                      *\r
+ * Downsample by a factor 3, low quality                                *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+#define ORDER_FIR                   6\r
+\r
+/* Downsample by a factor 3, low quality */\r
+void SKP_Silk_resampler_down3(\r
+    SKP_int32                           *S,         /* I/O: State vector [ 8 ]                  */\r
+    SKP_int16                           *out,       /* O:   Output signal [ floor(inLen/3) ]    */\r
+    const SKP_int16                     *in,        /* I:   Input signal [ inLen ]              */\r
+    SKP_int32                           inLen       /* I:   Number of input samples             */\r
+)\r
+{\r
+       SKP_int32 nSamplesIn, counter, res_Q6;\r
+       SKP_int32 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR ];\r
+       SKP_int32 *buf_ptr;\r
+\r
+       /* Copy buffered samples to start of buffer */  \r
+       SKP_memcpy( buf, S, ORDER_FIR * sizeof( SKP_int32 ) );\r
+\r
+       /* Iterate over blocks of frameSizeIn input samples */\r
+       while( 1 ) {\r
+               nSamplesIn = SKP_min( inLen, RESAMPLER_MAX_BATCH_SIZE_IN );\r
+\r
+           /* Second-order AR filter (output in Q8) */\r
+           SKP_Silk_resampler_private_AR2( &S[ ORDER_FIR ], &buf[ ORDER_FIR ], in, \r
+            SKP_Silk_Resampler_1_3_COEFS_LQ, nSamplesIn );\r
+\r
+               /* Interpolate filtered signal */\r
+        buf_ptr = buf;\r
+        counter = nSamplesIn;\r
+        while( counter > 2 ) {\r
+            /* Inner product */\r
+            res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 5 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 ] );\r
+            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 4 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 3 ] );\r
+            res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[ 3 ] ), SKP_Silk_Resampler_1_3_COEFS_LQ[ 4 ] );\r
+\r
+            /* Scale down, saturate and store in output array */\r
+            *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
+\r
+            buf_ptr += 3;\r
+            counter -= 3;\r
+        }\r
+\r
+               in += nSamplesIn;\r
+               inLen -= nSamplesIn;\r
+\r
+               if( inLen > 0 ) {\r
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
+                       SKP_memcpy( buf, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
+               } else {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* Copy last part of filtered signal to the state for the next call */\r
+       SKP_memcpy( S, &buf[ nSamplesIn ], ORDER_FIR * sizeof( SKP_int32 ) );\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private.h b/libs/silk/src/SKP_Silk_resampler_private.h
new file mode 100644 (file)
index 0000000..0402b48
--- /dev/null
@@ -0,0 +1,131 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_structs.h                                                    *\r
+ *                                                                                                                                             *\r
+ * Description: Structs for IIR/FIR resamplers                                                 *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                                                                                             *\r
+ *                                                                      */\r
+\r
+#ifndef SKP_Silk_RESAMPLER_H\r
+#define SKP_Silk_RESAMPLER_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_structs.h"\r
+#include "SKP_Silk_resampler_rom.h"\r
+\r
+/* Number of input samples to process in the inner loop */\r
+#define RESAMPLER_MAX_BATCH_SIZE_IN             480\r
+\r
+/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */\r
+void SKP_Silk_resampler_private_IIR_FIR(\r
+       void                            *SS,                /* I/O: Resampler state                                             */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+);\r
+\r
+/* Description: Hybrid IIR/FIR polyphase implementation of resampling  */\r
+void SKP_Silk_resampler_private_down_FIR(\r
+       void                            *SS,                /* I/O: Resampler state                                             */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+);\r
+\r
+/* Copy */\r
+void SKP_Silk_resampler_private_copy(\r
+       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+);\r
+\r
+/* Upsample by a factor 2, high quality */\r
+void SKP_Silk_resampler_private_up2_HQ_wrapper(\r
+       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of input samples                 */\r
+);\r
+\r
+/* Upsample by a factor 2, high quality */\r
+void SKP_Silk_resampler_private_up2_HQ(\r
+       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of input samples                 */\r
+);\r
+\r
+/* Upsample 4x, low quality */\r
+void SKP_Silk_resampler_private_up4(\r
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 4 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of input samples                 */\r
+);\r
+\r
+/* Downsample 4x, low quality */\r
+void SKP_Silk_resampler_private_down4(\r
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
+    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       inLen           /* I:   Number of input samples                 */\r
+);\r
+\r
+/* Second order AR filter */\r
+void SKP_Silk_resampler_private_AR2(\r
+       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */\r
+       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */\r
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
+       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */\r
+       SKP_int32                                       len                             /* I:   Signal length                                           */\r
+);\r
+\r
+/* Fourth order ARMA filter */\r
+void SKP_Silk_resampler_private_ARMA4(\r
+       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */\r
+       SKP_int16                                           out[],                  /* O:       Output signal                                       */\r
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
+       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */\r
+       SKP_int32                                       len                             /* I:   Signal length                                           */\r
+);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif // SKP_Silk_RESAMPLER_H\r
+\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_AR2.c b/libs/silk/src/SKP_Silk_resampler_private_AR2.c
new file mode 100644 (file)
index 0000000..69f5043
--- /dev/null
@@ -0,0 +1,58 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * SKP_Silk_resampler_private_AR2. c                                  *\r
+ *                                                                                                                                             *\r
+ * Second order AR filter with single delay elements                   *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Second order AR filter with single delay elements */\r
+void SKP_Silk_resampler_private_AR2(\r
+       SKP_int32                                           S[],                    /* I/O: State vector [ 2 ]                              */\r
+       SKP_int32                                           out_Q8[],           /* O:   Output signal                                       */\r
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
+       const SKP_int16                             A_Q14[],            /* I:   AR coefficients, Q14                    */\r
+       SKP_int32                                       len                             /* I:   Signal length                                           */\r
+)\r
+{\r
+       SKP_int32       k;\r
+       SKP_int32       out32;\r
+\r
+       for( k = 0; k < len; k++ ) {\r
+               out32       = SKP_ADD_LSHIFT32( S[ 0 ], (SKP_int32)in[ k ], 8 );\r
+               out_Q8[ k ] = out32;\r
+               out32       = SKP_LSHIFT( out32, 2 );\r
+               S[ 0 ]      = SKP_SMLAWB( S[ 1 ], out32, A_Q14[ 0 ] );\r
+               S[ 1 ]      = SKP_SMULWB( out32, A_Q14[ 1 ] );\r
+       }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_ARMA4.c b/libs/silk/src/SKP_Silk_resampler_private_ARMA4.c
new file mode 100644 (file)
index 0000000..d0ca3a6
--- /dev/null
@@ -0,0 +1,77 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * SKP_Silk_resampler_private_ARMA4.c                                 *\r
+ *                                                                                                                                             *\r
+ * Fourth order ARMA filter, applies 64x gain                           *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Fourth order ARMA filter                                             */\r
+/* Internally operates as two biquad filters in sequence.               */\r
+\r
+/* Coeffients are stored in a packed format:                                                        */\r
+/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }            */\r
+/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                           */\r
+void SKP_Silk_resampler_private_ARMA4(\r
+       SKP_int32                                           S[],                    /* I/O: State vector [ 4 ]                              */\r
+       SKP_int16                                           out[],                  /* O:       Output signal                                       */\r
+       const SKP_int16                             in[],                       /* I:   Input signal                                        */\r
+       const SKP_int16                             Coef[],                 /* I:       ARMA coefficients [ 7 ]                 */\r
+       SKP_int32                                       len                             /* I:   Signal length                                           */\r
+)\r
+{\r
+       SKP_int32 k;\r
+       SKP_int32 in_Q8, out1_Q8, out2_Q8, X;\r
+\r
+       for( k = 0; k < len; k++ ) {\r
+        in_Q8  = SKP_LSHIFT32( (SKP_int32)in[ k ], 8 );\r
+\r
+        /* Outputs of first and second biquad */\r
+        out1_Q8 = SKP_ADD_LSHIFT32( in_Q8,   S[ 0 ], 2 );\r
+        out2_Q8 = SKP_ADD_LSHIFT32( out1_Q8, S[ 2 ], 2 );\r
+\r
+        /* Update states, which are stored in Q6. Coefficients are in Q14 here */\r
+        X      = SKP_SMLAWB( S[ 1 ], in_Q8,   Coef[ 0 ] );\r
+        S[ 0 ] = SKP_SMLAWB( X,      out1_Q8, Coef[ 2 ] );\r
+\r
+        X      = SKP_SMLAWB( S[ 3 ], out1_Q8, Coef[ 1 ] );\r
+        S[ 2 ] = SKP_SMLAWB( X,      out2_Q8, Coef[ 4 ] );\r
+\r
+        S[ 1 ] = SKP_SMLAWB( SKP_RSHIFT32( in_Q8,   2 ), out1_Q8, Coef[ 3 ] );\r
+        S[ 3 ] = SKP_SMLAWB( SKP_RSHIFT32( out1_Q8, 2 ), out2_Q8, Coef[ 5 ] );\r
+\r
+        /* Apply gain and store to output. The coefficient is in Q16 */\r
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( SKP_SMLAWB( 128, out2_Q8, Coef[ 6 ] ), 8 ) );\r
+       }\r
+}\r
+\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_IIR_FIR.c b/libs/silk/src/SKP_Silk_resampler_private_IIR_FIR.c
new file mode 100644 (file)
index 0000000..df9a031
--- /dev/null
@@ -0,0 +1,105 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_private_IIR_FIR.c                        *\r
+ *                                                                                                                                             *\r
+ * Description: Hybrid IIR/FIR polyphase implementation of resampling  *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_IIR_FIR_INTERPOL( \r
+                       SKP_int16 * out, SKP_int16 * buf, SKP_int32 max_index_Q16 , SKP_int32 index_increment_Q16 ){\r
+       SKP_int32 index_Q16, res_Q15;\r
+       SKP_int16 *buf_ptr;\r
+       SKP_int32 table_index;\r
+       /* Interpolate upsampled signal and store in output array */\r
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
+        table_index = SKP_SMULWB( index_Q16 & 0xFFFF, 144 );\r
+        buf_ptr = &buf[ index_Q16 >> 16 ];\r
+            \r
+        res_Q15 = SKP_SMULBB(          buf_ptr[ 0 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 0 ] );\r
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 1 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 1 ] );\r
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 2 ], SKP_Silk_resampler_frac_FIR_144[       table_index ][ 2 ] );\r
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 3 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 2 ] );\r
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 4 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 1 ] );\r
+        res_Q15 = SKP_SMLABB( res_Q15, buf_ptr[ 5 ], SKP_Silk_resampler_frac_FIR_144[ 143 - table_index ][ 0 ] );          \r
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q15, 15 ) );\r
+       }\r
+       return out;     \r
+}\r
+/* Upsample using a combination of allpass-based 2x upsampling and FIR interpolation */\r
+void SKP_Silk_resampler_private_IIR_FIR(\r
+       void                            *SS,                /* I/O: Resampler state                                             */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+)\r
+{\r
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
+       SKP_int32 nSamplesIn;\r
+       SKP_int32 max_index_Q16, index_increment_Q16;\r
+       SKP_int16 buf[ 2 * RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_144 ];\r
+    \r
+\r
+       /* Copy buffered samples to start of buffer */  \r
+       SKP_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
+\r
+       /* Iterate over blocks of frameSizeIn input samples */\r
+    index_increment_Q16 = S->invRatio_Q16;\r
+       while( 1 ) {\r
+               nSamplesIn = SKP_min( inLen, S->batchSize );\r
+\r
+        if( S->input2x == 1 ) {\r
+                   /* Upsample 2x */\r
+            S->up2_function( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, nSamplesIn );\r
+        } else {\r
+                   /* Fourth-order ARMA filter */\r
+            SKP_Silk_resampler_private_ARMA4( S->sIIR, &buf[ RESAMPLER_ORDER_FIR_144 ], in, S->Coefs, nSamplesIn );\r
+        }\r
+\r
+        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 + S->input2x );         /* +1 if 2x upsampling */\r
+               out = SKP_Silk_resampler_private_IIR_FIR_INTERPOL(out, buf, max_index_Q16, index_increment_Q16);    \r
+               in += nSamplesIn;\r
+               inLen -= nSamplesIn;\r
+\r
+               if( inLen > 0 ) {\r
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
+                       SKP_memcpy( buf, &buf[ nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
+               } else {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* Copy last part of filtered signal to the state for the next call */\r
+       SKP_memcpy( S->sFIR, &buf[nSamplesIn << S->input2x ], RESAMPLER_ORDER_FIR_144 * sizeof( SKP_int32 ) );\r
+}\r
+\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_copy.c b/libs/silk/src/SKP_Silk_resampler_private_copy.c
new file mode 100644 (file)
index 0000000..7c5b031
--- /dev/null
@@ -0,0 +1,49 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_private_copy.c                     *\r
+ *                                                                                                                                             *\r
+ * Description: Copy.                                                   *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Copy */\r
+void SKP_Silk_resampler_private_copy(\r
+       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+)\r
+{\r
+    SKP_memcpy( out, in, inLen * sizeof( SKP_int16 ) );\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_down4.c b/libs/silk/src/SKP_Silk_resampler_private_down4.c
new file mode 100644 (file)
index 0000000..0d327c7
--- /dev/null
@@ -0,0 +1,77 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_private_down4.c                                 *\r
+ *                                                                      *\r
+ * Downsample by a factor 4                                             *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Downsample by a factor 4. Note: very low quality, only use with input sampling rates above 96 kHz. */\r
+void SKP_Silk_resampler_private_down4(\r
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
+    SKP_int16                       *out,           /* O:   Output signal [ floor(len/2) ]          */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       inLen           /* I:   Number of input samples                 */\r
+)\r
+{\r
+    SKP_int32 k, len4 = SKP_RSHIFT32( inLen, 2 );\r
+    SKP_int32 in32, out32, Y, X;\r
+\r
+    SKP_assert( SKP_Silk_resampler_down2_0 > 0 );\r
+    SKP_assert( SKP_Silk_resampler_down2_1 < 0 );\r
+\r
+    /* Internal variables and state are in Q10 format */\r
+    for( k = 0; k < len4; k++ ) {\r
+        /* Add two input samples and convert to Q10 */\r
+        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k ], (SKP_int32)in[ 4 * k + 1 ] ), 9 );\r
+\r
+        /* All-pass section for even input sample */\r
+        Y      = SKP_SUB32( in32, S[ 0 ] );\r
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_down2_1 );\r
+        out32  = SKP_ADD32( S[ 0 ], X );\r
+        S[ 0 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Add two input samples and convert to Q10 */\r
+        in32 = SKP_LSHIFT( SKP_ADD32( (SKP_int32)in[ 4 * k + 2 ], (SKP_int32)in[ 4 * k + 3 ] ), 9 );\r
+\r
+        /* All-pass section for odd input sample */\r
+        Y      = SKP_SUB32( in32, S[ 1 ] );\r
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_down2_0 );\r
+        out32  = SKP_ADD32( out32, S[ 1 ] );\r
+        out32  = SKP_ADD32( out32, X );\r
+        S[ 1 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Add, convert back to int16 and store to output */\r
+        out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 11 ) );\r
+    }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_down_FIR.c b/libs/silk/src/SKP_Silk_resampler_private_down_FIR.c
new file mode 100644 (file)
index 0000000..f84357b
--- /dev/null
@@ -0,0 +1,160 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_private_down_FIR.c                 *\r
+ *                                                                                                                                             *\r
+ * Description: Hybrid IIR/FIR polyphase implementation of resampling  *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL0(\r
+       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16){\r
+       \r
+       SKP_int32 index_Q16, res_Q6;\r
+       SKP_int32 *buf_ptr;\r
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
+               /* Integer part gives pointer to buffered input */\r
+               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );\r
+\r
+               /* Inner product */\r
+               res_Q6 = SKP_SMULWB(         SKP_ADD32( buf_ptr[ 0 ], buf_ptr[ 11 ] ), FIR_Coefs[ 0 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 1 ], buf_ptr[ 10 ] ), FIR_Coefs[ 1 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 2 ], buf_ptr[  9 ] ), FIR_Coefs[ 2 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 3 ], buf_ptr[  8 ] ), FIR_Coefs[ 3 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 4 ], buf_ptr[  7 ] ), FIR_Coefs[ 4 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, SKP_ADD32( buf_ptr[ 5 ], buf_ptr[  6 ] ), FIR_Coefs[ 5 ] );\r
+\r
+                           /* Scale down, saturate and store in output array */\r
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
+       }\r
+       return out;\r
+}\r
+\r
+SKP_INLINE SKP_int16 *SKP_Silk_resampler_private_down_FIR_INTERPOL1(\r
+       SKP_int16 *out, SKP_int32 *buf2, const SKP_int16 *FIR_Coefs, SKP_int32 max_index_Q16, SKP_int32 index_increment_Q16, SKP_int32 FIR_Fracs){\r
+       \r
+       SKP_int32 index_Q16, res_Q6;\r
+       SKP_int32 *buf_ptr;\r
+       SKP_int32 interpol_ind;\r
+       const SKP_int16 *interpol_ptr;\r
+       for( index_Q16 = 0; index_Q16 < max_index_Q16; index_Q16 += index_increment_Q16 ) {\r
+               /* Integer part gives pointer to buffered input */\r
+               buf_ptr = buf2 + SKP_RSHIFT( index_Q16, 16 );\r
+\r
+               /* Fractional part gives interpolation coefficients */\r
+               interpol_ind = SKP_SMULWB( index_Q16 & 0xFFFF, FIR_Fracs );\r
+\r
+               /* Inner product */\r
+               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * interpol_ind ];\r
+               res_Q6 = SKP_SMULWB(         buf_ptr[ 0 ], interpol_ptr[ 0 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 1 ], interpol_ptr[ 1 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 2 ], interpol_ptr[ 2 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 3 ], interpol_ptr[ 3 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 4 ], interpol_ptr[ 4 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 5 ], interpol_ptr[ 5 ] );\r
+               interpol_ptr = &FIR_Coefs[ RESAMPLER_DOWN_ORDER_FIR / 2 * ( FIR_Fracs - 1 - interpol_ind ) ];\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 11 ], interpol_ptr[ 0 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[ 10 ], interpol_ptr[ 1 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  9 ], interpol_ptr[ 2 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  8 ], interpol_ptr[ 3 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  7 ], interpol_ptr[ 4 ] );\r
+               res_Q6 = SKP_SMLAWB( res_Q6, buf_ptr[  6 ], interpol_ptr[ 5 ] );\r
+\r
+               /* Scale down, saturate and store in output array */\r
+               *out++ = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( res_Q6, 6 ) );\r
+       }\r
+       return out;\r
+}\r
+\r
+\r
+/* Resample with a 2x downsampler (optional), a 2nd order AR filter followed by FIR interpolation */\r
+void SKP_Silk_resampler_private_down_FIR(\r
+       void                            *SS,                /* I/O: Resampler state                                             */\r
+       SKP_int16                                               out[],              /* O:       Output signal                                                   */\r
+       const SKP_int16                                 in[],               /* I:       Input signal                                                    */\r
+       SKP_int32                                           inLen                   /* I:       Number of input samples                                 */\r
+)\r
+{\r
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
+       SKP_int32 nSamplesIn;\r
+       SKP_int32 max_index_Q16, index_increment_Q16;\r
+       SKP_int16 buf1[ RESAMPLER_MAX_BATCH_SIZE_IN / 2 ];\r
+       SKP_int32 buf2[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_DOWN_ORDER_FIR ];\r
+       const SKP_int16 *FIR_Coefs;\r
+\r
+       /* Copy buffered samples to start of buffer */  \r
+       SKP_memcpy( buf2, S->sFIR, RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
+\r
+    FIR_Coefs = &S->Coefs[ 2 ];\r
+\r
+       /* Iterate over blocks of frameSizeIn input samples */\r
+    index_increment_Q16 = S->invRatio_Q16;\r
+       while( 1 ) {\r
+               nSamplesIn = SKP_min( inLen, S->batchSize );\r
+\r
+        if( S->input2x == 1 ) {\r
+            /* Downsample 2x */\r
+            SKP_Silk_resampler_down2( S->sDown2, buf1, in, nSamplesIn );\r
+\r
+            nSamplesIn = SKP_RSHIFT32( nSamplesIn, 1 );\r
+\r
+                   /* Second-order AR filter (output in Q8) */\r
+                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], buf1, S->Coefs, nSamplesIn );\r
+        } else {\r
+                   /* Second-order AR filter (output in Q8) */\r
+                   SKP_Silk_resampler_private_AR2( S->sIIR, &buf2[ RESAMPLER_DOWN_ORDER_FIR ], in, S->Coefs, nSamplesIn );\r
+        }\r
+\r
+        max_index_Q16 = SKP_LSHIFT32( nSamplesIn, 16 );\r
+\r
+               /* Interpolate filtered signal */\r
+        if( S->FIR_Fracs == 1 ) {\r
+               out = SKP_Silk_resampler_private_down_FIR_INTERPOL0(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16);\r
+        } else {\r
+               out = SKP_Silk_resampler_private_down_FIR_INTERPOL1(out, buf2, FIR_Coefs, max_index_Q16, index_increment_Q16, S->FIR_Fracs);\r
+        }\r
+        \r
+               in += nSamplesIn << S->input2x;\r
+               inLen -= nSamplesIn << S->input2x;\r
+\r
+               if( inLen > S->input2x ) {\r
+                       /* More iterations to do; copy last part of filtered signal to beginning of buffer */\r
+                       SKP_memcpy( buf2, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
+               } else {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* Copy last part of filtered signal to the state for the next call */\r
+       SKP_memcpy( S->sFIR, &buf2[ nSamplesIn ], RESAMPLER_DOWN_ORDER_FIR * sizeof( SKP_int32 ) );\r
+}\r
+\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_up2_HQ.c b/libs/silk/src/SKP_Silk_resampler_private_up2_HQ.c
new file mode 100644 (file)
index 0000000..8ae2548
--- /dev/null
@@ -0,0 +1,118 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_private_up2_HQ.c                                *\r
+ *                                                                      *\r
+ * Upsample by a factor 2, high quality                                 *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Upsample by a factor 2, high quality */\r
+/* Uses 2nd order allpass filters for the 2x upsampling, followed by a      */\r
+/* notch filter just above Nyquist.                                         */\r
+void SKP_Silk_resampler_private_up2_HQ(\r
+       SKP_int32                           *S,                     /* I/O: Resampler state [ 6 ]                                       */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of INPUT samples                 */\r
+)\r
+{\r
+    SKP_int32 k;\r
+    SKP_int32 in32, out32_1, out32_2, Y, X;\r
+\r
+    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 0 ] > 0 );\r
+    SKP_assert( SKP_Silk_resampler_up2_hq_0[ 1 ] < 0 );\r
+    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 0 ] > 0 );\r
+    SKP_assert( SKP_Silk_resampler_up2_hq_1[ 1 ] < 0 );\r
+    \r
+    /* Internal variables and state are in Q10 format */\r
+    for( k = 0; k < len; k++ ) {\r
+        /* Convert to Q10 */\r
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
+\r
+        /* First all-pass section for even output sample */\r
+        Y       = SKP_SUB32( in32, S[ 0 ] );\r
+        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_0[ 0 ] );\r
+        out32_1 = SKP_ADD32( S[ 0 ], X );\r
+        S[ 0 ]  = SKP_ADD32( in32, X );\r
+\r
+        /* Second all-pass section for even output sample */\r
+        Y       = SKP_SUB32( out32_1, S[ 1 ] );\r
+        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_0[ 1 ] );\r
+        out32_2 = SKP_ADD32( S[ 1 ], X );\r
+        S[ 1 ]  = SKP_ADD32( out32_1, X );\r
+\r
+        /* Biquad notch filter */\r
+        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );\r
+        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );\r
+        out32_1 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );\r
+        S[ 5 ]  = SKP_SUB32(  out32_2, S[ 5 ] );\r
+        \r
+        /* Apply gain in Q15, convert back to int16 and store to output */\r
+        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( \r
+            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );\r
+\r
+        /* First all-pass section for odd output sample */\r
+        Y       = SKP_SUB32( in32, S[ 2 ] );\r
+        X       = SKP_SMULWB( Y, SKP_Silk_resampler_up2_hq_1[ 0 ] );\r
+        out32_1 = SKP_ADD32( S[ 2 ], X );\r
+        S[ 2 ]  = SKP_ADD32( in32, X );\r
+\r
+        /* Second all-pass section for odd output sample */\r
+        Y       = SKP_SUB32( out32_1, S[ 3 ] );\r
+        X       = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_hq_1[ 1 ] );\r
+        out32_2 = SKP_ADD32( S[ 3 ], X );\r
+        S[ 3 ]  = SKP_ADD32( out32_1, X );\r
+\r
+        /* Biquad notch filter */\r
+        out32_2 = SKP_SMLAWB( out32_2, S[ 4 ], SKP_Silk_resampler_up2_hq_notch[ 2 ] );\r
+        out32_2 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 1 ] );\r
+        out32_1 = SKP_SMLAWB( out32_2, S[ 5 ], SKP_Silk_resampler_up2_hq_notch[ 0 ] );\r
+        S[ 4 ]  = SKP_SUB32(  out32_2, S[ 4 ] );\r
+        \r
+        /* Apply gain in Q15, convert back to int16 and store to output */\r
+        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT32( \r
+            SKP_SMLAWB( 256, out32_1, SKP_Silk_resampler_up2_hq_notch[ 3 ] ), 9 ) );\r
+    }\r
+}\r
+\r
+\r
+void SKP_Silk_resampler_private_up2_HQ_wrapper(\r
+       void                            *SS,                /* I/O: Resampler state (unused)                            */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 2 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of input samples                 */\r
+)\r
+{\r
+    SKP_Silk_resampler_state_struct *S = (SKP_Silk_resampler_state_struct *)SS;\r
+    SKP_Silk_resampler_private_up2_HQ( S->sIIR, out, in, len );\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_private_up4.c b/libs/silk/src/SKP_Silk_resampler_private_up4.c
new file mode 100644 (file)
index 0000000..9c63d40
--- /dev/null
@@ -0,0 +1,81 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_private_up4.c                                   *\r
+ *                                                                      *\r
+ * Upsample by a factor 4, low quality                                  *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Upsample by a factor 4, Note: very low quality, only use with output sampling rates above 96 kHz. */\r
+void SKP_Silk_resampler_private_up4(\r
+    SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
+    SKP_int16                       *out,           /* O:   Output signal [ 4 * len ]               */\r
+    const SKP_int16                 *in,            /* I:   Input signal [ len ]                    */\r
+    SKP_int32                       len             /* I:   Number of INPUT samples                 */\r
+)\r
+{\r
+    SKP_int32 k;\r
+    SKP_int32 in32, out32, Y, X;\r
+    SKP_int16 out16;\r
+\r
+    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );\r
+    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );\r
+\r
+    /* Internal variables and state are in Q10 format */\r
+    for( k = 0; k < len; k++ ) {\r
+        /* Convert to Q10 */\r
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
+\r
+        /* All-pass section for even output sample */\r
+        Y      = SKP_SUB32( in32, S[ 0 ] );\r
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );\r
+        out32  = SKP_ADD32( S[ 0 ], X );\r
+        S[ 0 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Convert back to int16 and store to output */\r
+        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
+        out[ 4 * k ]     = out16;\r
+        out[ 4 * k + 1 ] = out16;\r
+\r
+        /* All-pass section for odd output sample */\r
+        Y      = SKP_SUB32( in32, S[ 1 ] );\r
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );\r
+        out32  = SKP_ADD32( S[ 1 ], X );\r
+        S[ 1 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Convert back to int16 and store to output */\r
+        out16 = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
+        out[ 4 * k + 2 ] = out16;\r
+        out[ 4 * k + 3 ] = out16;\r
+    }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_resampler_rom.c b/libs/silk/src/SKP_Silk_resampler_rom.c
new file mode 100644 (file)
index 0000000..96ecde3
--- /dev/null
@@ -0,0 +1,269 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_rom.c                                                                *\r
+ *                                                                                                                                             *\r
+ * Description: Filter coefficients for IIR/FIR polyphase resampling   *\r
+ * Total size: 550 Words (1.1 kB)                                      *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_resampler_private.h"\r
+\r
+/* Tables for 2x downsampler */\r
+const SKP_int16 SKP_Silk_resampler_down2_0 = 9872;\r
+const SKP_int16 SKP_Silk_resampler_down2_1 = 39809 - 65536;\r
+\r
+/* Tables for 2x upsampler, low quality */\r
+const SKP_int16 SKP_Silk_resampler_up2_lq_0 = 8102;\r
+const SKP_int16 SKP_Silk_resampler_up2_lq_1 = 36783 - 65536;\r
+\r
+/* Tables for 2x upsampler, high quality */\r
+const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ] = {  4280, 33727 - 65536 };\r
+const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ] = { 16295, 54015 - 65536 };\r
+/* Matlab code for the notch filter coefficients: */\r
+/* B = [1, 0.12, 1];  A = [1, 0.055, 0.8]; G = 0.87; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]);  */\r
+/* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */\r
+const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ] = { 7864,  -3604,  13107,  28508 };\r
+\r
+\r
+/* Tables with IIR and FIR coefficients for fractional downsamplers (70 Words) */\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
+       -18249, -12532,\r
+          -97,    284,   -495,    309,  10268,  20317,\r
+          -94,    156,    -48,   -720,   5984,  18278,\r
+          -45,     -4,    237,   -847,   2540,  14662,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
+       -11891, -12486,\r
+           20,    211,   -657,    688,   8423,  15911,\r
+          -44,    197,   -152,   -653,   3855,  13015,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
+         2415, -13101,\r
+          158,   -295,   -400,   1265,   4832,   7968,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
+        13270, -13738,\r
+         -294,   -123,    747,   2043,   3339,   3995,\r
+         -151,   -311,    414,   1583,   2947,   3877,\r
+          -33,   -389,    143,   1141,   2503,   3653,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 + RESAMPLER_DOWN_ORDER_FIR / 2 ] = {\r
+        16643, -14000,\r
+         -331,     19,    581,   1421,   2290,   2845,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ] = {\r
+        -2797,  -6507,\r
+         4697,  10739,\r
+         1567,   8276,\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ] = {\r
+        16777,  -9792,\r
+          890,   1614,   2148,\r
+};\r
+\r
+\r
+/* Tables with coefficients for 4th order ARMA filter (35 Words), in a packed format:       */\r
+/*    { B1_Q14[1], B2_Q14[1], -A1_Q14[1], -A1_Q14[2], -A2_Q14[1], -A2_Q14[2], gain_Q16 }    */\r
+/* where it is assumed that B*_Q14[0], B*_Q14[2], A*_Q14[0] are all 16384                   */\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ] = {\r
+        31454,  24746,  -9706,  -3386, -17911, -13243,  24797\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ] = {\r
+        28721,  11254,   3189,  -2546,  -1495, -12618,  11562\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ] = {\r
+        23492,  -6457,  14358,  -4856,  14654, -13008,   4456\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ] = {\r
+        19311, -15569,  19489,  -6950,  21441, -13559,   2370\r
+};\r
+\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ] = {\r
+        13248, -23849,  24126,  -9486,  26806, -14286,   1065\r
+};\r
+\r
+/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */\r
+SKP_DWORD_ALIGN const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ] = {\r
+       { -647,  1884, 30078},\r
+       { -625,  1736, 30044},\r
+       { -603,  1591, 30005},\r
+       { -581,  1448, 29963},\r
+       { -559,  1308, 29917},\r
+       { -537,  1169, 29867},\r
+       { -515,  1032, 29813},\r
+       { -494,   898, 29755},\r
+       { -473,   766, 29693},\r
+       { -452,   636, 29627},\r
+       { -431,   508, 29558},\r
+       { -410,   383, 29484},\r
+       { -390,   260, 29407},\r
+       { -369,   139, 29327},\r
+       { -349,    20, 29242},\r
+       { -330,   -97, 29154},\r
+       { -310,  -211, 29062},\r
+       { -291,  -324, 28967},\r
+       { -271,  -434, 28868},\r
+       { -253,  -542, 28765},\r
+       { -234,  -647, 28659},\r
+       { -215,  -751, 28550},\r
+       { -197,  -852, 28436},\r
+       { -179,  -951, 28320},\r
+       { -162, -1048, 28200},\r
+       { -144, -1143, 28077},\r
+       { -127, -1235, 27950},\r
+       { -110, -1326, 27820},\r
+       {  -94, -1414, 27687},\r
+       {  -77, -1500, 27550},\r
+       {  -61, -1584, 27410},\r
+       {  -45, -1665, 27268},\r
+       {  -30, -1745, 27122},\r
+       {  -15, -1822, 26972},\r
+       {    0, -1897, 26820},\r
+       {   15, -1970, 26665},\r
+       {   29, -2041, 26507},\r
+       {   44, -2110, 26346},\r
+       {   57, -2177, 26182},\r
+       {   71, -2242, 26015},\r
+       {   84, -2305, 25845},\r
+       {   97, -2365, 25673},\r
+       {  110, -2424, 25498},\r
+       {  122, -2480, 25320},\r
+       {  134, -2534, 25140},\r
+       {  146, -2587, 24956},\r
+       {  157, -2637, 24771},\r
+       {  168, -2685, 24583},\r
+       {  179, -2732, 24392},\r
+       {  190, -2776, 24199},\r
+       {  200, -2819, 24003},\r
+       {  210, -2859, 23805},\r
+       {  220, -2898, 23605},\r
+       {  229, -2934, 23403},\r
+       {  238, -2969, 23198},\r
+       {  247, -3002, 22992},\r
+       {  255, -3033, 22783},\r
+       {  263, -3062, 22572},\r
+       {  271, -3089, 22359},\r
+       {  279, -3114, 22144},\r
+       {  286, -3138, 21927},\r
+       {  293, -3160, 21709},\r
+       {  300, -3180, 21488},\r
+       {  306, -3198, 21266},\r
+       {  312, -3215, 21042},\r
+       {  318, -3229, 20816},\r
+       {  323, -3242, 20589},\r
+       {  328, -3254, 20360},\r
+       {  333, -3263, 20130},\r
+       {  338, -3272, 19898},\r
+       {  342, -3278, 19665},\r
+       {  346, -3283, 19430},\r
+       {  350, -3286, 19194},\r
+       {  353, -3288, 18957},\r
+       {  356, -3288, 18718},\r
+       {  359, -3286, 18478},\r
+       {  362, -3283, 18238},\r
+       {  364, -3279, 17996},\r
+       {  366, -3273, 17753},\r
+       {  368, -3266, 17509},\r
+       {  369, -3257, 17264},\r
+       {  371, -3247, 17018},\r
+       {  372, -3235, 16772},\r
+       {  372, -3222, 16525},\r
+       {  373, -3208, 16277},\r
+       {  373, -3192, 16028},\r
+       {  373, -3175, 15779},\r
+       {  373, -3157, 15529},\r
+       {  372, -3138, 15279},\r
+       {  371, -3117, 15028},\r
+       {  370, -3095, 14777},\r
+       {  369, -3072, 14526},\r
+       {  368, -3048, 14274},\r
+       {  366, -3022, 14022},\r
+       {  364, -2996, 13770},\r
+       {  362, -2968, 13517},\r
+       {  359, -2940, 13265},\r
+       {  357, -2910, 13012},\r
+       {  354, -2880, 12760},\r
+       {  351, -2848, 12508},\r
+       {  348, -2815, 12255},\r
+       {  344, -2782, 12003},\r
+       {  341, -2747, 11751},\r
+       {  337, -2712, 11500},\r
+       {  333, -2676, 11248},\r
+       {  328, -2639, 10997},\r
+       {  324, -2601, 10747},\r
+       {  320, -2562, 10497},\r
+       {  315, -2523, 10247},\r
+       {  310, -2482,  9998},\r
+       {  305, -2442,  9750},\r
+       {  300, -2400,  9502},\r
+       {  294, -2358,  9255},\r
+       {  289, -2315,  9009},\r
+       {  283, -2271,  8763},\r
+       {  277, -2227,  8519},\r
+       {  271, -2182,  8275},\r
+       {  265, -2137,  8032},\r
+       {  259, -2091,  7791},\r
+       {  252, -2045,  7550},\r
+       {  246, -1998,  7311},\r
+       {  239, -1951,  7072},\r
+       {  232, -1904,  6835},\r
+       {  226, -1856,  6599},\r
+       {  219, -1807,  6364},\r
+       {  212, -1758,  6131},\r
+       {  204, -1709,  5899},\r
+       {  197, -1660,  5668},\r
+       {  190, -1611,  5439},\r
+       {  183, -1561,  5212},\r
+       {  175, -1511,  4986},\r
+       {  168, -1460,  4761},\r
+       {  160, -1410,  4538},\r
+       {  152, -1359,  4317},\r
+       {  145, -1309,  4098},\r
+       {  137, -1258,  3880},\r
+       {  129, -1207,  3664},\r
+       {  121, -1156,  3450},\r
+       {  113, -1105,  3238},\r
+       {  105, -1054,  3028},\r
+       {   97, -1003,  2820},\r
+       {   89,  -952,  2614},\r
+       {   81,  -901,  2409},\r
+       {   73,  -851,  2207},\r
+};\r
diff --git a/libs/silk/src/SKP_Silk_resampler_rom.h b/libs/silk/src/SKP_Silk_resampler_rom.h
new file mode 100644 (file)
index 0000000..3369cb7
--- /dev/null
@@ -0,0 +1,91 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * File Name:    SKP_Silk_resample_rom.h                              *\r
+ *                                                                      *\r
+ * Description: Header file for FIR resampling of                       *\r
+ *                32 and 44 kHz input                                   *\r
+ *                                                                      *\r
+ * Copyright 2007 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                 *\r
+ *                                                                      *\r
+ * Date: 070807                                                         *\r
+ *                                                                      */\r
+\r
+#ifndef _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
+#define _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
+\r
+#ifdef  __cplusplus\r
+extern "C"\r
+{\r
+#endif\r
+\r
+#include "SKP_Silk_typedef.h"\r
+#include "SKP_Silk_resampler_structs.h"\r
+\r
+#define RESAMPLER_DOWN_ORDER_FIR                12\r
+#define RESAMPLER_ORDER_FIR_144                 6\r
+\r
+\r
+/* Tables for 2x downsampler. Values above 32767 intentionally wrap to a negative value. */\r
+extern const SKP_int16 SKP_Silk_resampler_down2_0;\r
+extern const SKP_int16 SKP_Silk_resampler_down2_1;\r
+\r
+/* Tables for 2x upsampler, low quality. Values above 32767 intentionally wrap to a negative value. */\r
+extern const SKP_int16 SKP_Silk_resampler_up2_lq_0;\r
+extern const SKP_int16 SKP_Silk_resampler_up2_lq_1;\r
+\r
+/* Tables for 2x upsampler, high quality. Values above 32767 intentionally wrap to a negative value. */\r
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_0[ 2 ];\r
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_1[ 2 ];\r
+extern const SKP_int16 SKP_Silk_resampler_up2_hq_notch[ 4 ];\r
+\r
+/* Tables with IIR and FIR coefficients for fractional downsamplers */\r
+extern const SKP_int16 SKP_Silk_Resampler_3_4_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS[ 2 + 2 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_1_2_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_3_8_COEFS[ 2 + 3 * RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS[ 2 +     RESAMPLER_DOWN_ORDER_FIR / 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_2_3_COEFS_LQ[ 2 + 2 * 2 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_1_3_COEFS_LQ[ 2 + 3 ];\r
+\r
+/* Tables with coefficients for 4th order ARMA filter */\r
+extern const SKP_int16 SKP_Silk_Resampler_320_441_ARMA4_COEFS[ 7 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_240_441_ARMA4_COEFS[ 7 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_160_441_ARMA4_COEFS[ 7 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_120_441_ARMA4_COEFS[ 7 ];\r
+extern const SKP_int16 SKP_Silk_Resampler_80_441_ARMA4_COEFS[ 7 ];\r
+\r
+/* Table with interplation fractions of 1/288 : 2/288 : 287/288 (432 Words) */\r
+extern const SKP_int16 SKP_Silk_resampler_frac_FIR_144[ 144 ][ RESAMPLER_ORDER_FIR_144 / 2 ];\r
+\r
+#ifdef  __cplusplus\r
+}\r
+#endif\r
+\r
+#endif // _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
diff --git a/libs/silk/src/SKP_Silk_resampler_structs.h b/libs/silk/src/SKP_Silk_resampler_structs.h
new file mode 100644 (file)
index 0000000..48c3269
--- /dev/null
@@ -0,0 +1,80 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                                                                                             *\r
+ * File Name:  SKP_Silk_resampler_structs.h                                                    *\r
+ *                                                                                                                                             *\r
+ * Description: Structs for IIR/FIR resamplers                                                 *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ * All rights reserved.                                                                                                        *\r
+ *                                                                                                                                             *\r
+ *                                                                      */\r
+\r
+#ifndef SKP_Silk_RESAMPLER_STRUCTS_H\r
+#define SKP_Silk_RESAMPLER_STRUCTS_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Flag to enable support for input/output sampling rates above 48 kHz. Turn off for embedded devices */\r
+#define RESAMPLER_SUPPORT_ABOVE_48KHZ                   1\r
+\r
+#define SKP_Silk_RESAMPLER_MAX_FIR_ORDER                 16\r
+#define SKP_Silk_RESAMPLER_MAX_IIR_ORDER                 6\r
+\r
+\r
+typedef struct _SKP_Silk_resampler_state_struct{\r
+       SKP_int32       sIIR[ SKP_Silk_RESAMPLER_MAX_IIR_ORDER ];        /* this must be the first element of this struct */\r
+       SKP_int32       sFIR[ SKP_Silk_RESAMPLER_MAX_FIR_ORDER ];\r
+       SKP_int32       sDown2[ 2 ];\r
+       void            (*resampler_function)( void *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
+       void            (*up2_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
+    SKP_int32       batchSize;\r
+       SKP_int32       invRatio_Q16;\r
+       SKP_int32       FIR_Fracs;\r
+    SKP_int32       input2x;\r
+       const SKP_int16 *Coefs;\r
+#if RESAMPLER_SUPPORT_ABOVE_48KHZ\r
+       SKP_int32       sDownPre[ 2 ];\r
+       SKP_int32       sUpPost[ 2 ];\r
+       void            (*down_pre_function)( SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
+       void            (*up_post_function)(  SKP_int32 *, SKP_int16 *, const SKP_int16 *, SKP_int32 );\r
+       SKP_int32       batchSizePrePost;\r
+       SKP_int32       ratio_Q16;\r
+       SKP_int32       nPreDownsamplers;\r
+       SKP_int32       nPostUpsamplers;\r
+#endif\r
+       SKP_int32 magic_number;\r
+} SKP_Silk_resampler_state_struct;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* SKP_Silk_RESAMPLER_STRUCTS_H */\r
+\r
diff --git a/libs/silk/src/SKP_Silk_resampler_up2.c b/libs/silk/src/SKP_Silk_resampler_up2.c
new file mode 100644 (file)
index 0000000..718b274
--- /dev/null
@@ -0,0 +1,75 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+/*                                                                      *\r
+ * SKP_Silk_resampler_up2.c                                           *\r
+ *                                                                      *\r
+ * Upsample by a factor 2, low quality                                  *\r
+ *                                                                      *\r
+ * Copyright 2010 (c), Skype Limited                                    *\r
+ *                                                                      */\r
+\r
+#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_resampler_rom.h"\r
+\r
+/* Upsample by a factor 2, low quality */\r
+void SKP_Silk_resampler_up2(\r
+    SKP_int32                           *S,         /* I/O: State vector [ 2 ]                  */\r
+    SKP_int16                           *out,       /* O:   Output signal [ 2 * len ]           */\r
+    const SKP_int16                     *in,        /* I:   Input signal [ len ]                */\r
+    SKP_int32                           len         /* I:   Number of input samples             */\r
+)\r
+{\r
+    SKP_int32 k;\r
+    SKP_int32 in32, out32, Y, X;\r
+\r
+    SKP_assert( SKP_Silk_resampler_up2_lq_0 > 0 );\r
+    SKP_assert( SKP_Silk_resampler_up2_lq_1 < 0 );\r
+    /* Internal variables and state are in Q10 format */\r
+    for( k = 0; k < len; k++ ) {\r
+        /* Convert to Q10 */\r
+        in32 = SKP_LSHIFT( (SKP_int32)in[ k ], 10 );\r
+\r
+        /* All-pass section for even output sample */\r
+        Y      = SKP_SUB32( in32, S[ 0 ] );\r
+        X      = SKP_SMULWB( Y, SKP_Silk_resampler_up2_lq_0 );\r
+        out32  = SKP_ADD32( S[ 0 ], X );\r
+        S[ 0 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Convert back to int16 and store to output */\r
+        out[ 2 * k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
+\r
+        /* All-pass section for odd output sample */\r
+        Y      = SKP_SUB32( in32, S[ 1 ] );\r
+        X      = SKP_SMLAWB( Y, Y, SKP_Silk_resampler_up2_lq_1 );\r
+        out32  = SKP_ADD32( S[ 1 ], X );\r
+        S[ 1 ] = SKP_ADD32( in32, X );\r
+\r
+        /* Convert back to int16 and store to output */\r
+        out[ 2 * k + 1 ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out32, 10 ) );\r
+    }\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_setup_complexity.h b/libs/silk/src/SKP_Silk_setup_complexity.h
new file mode 100644 (file)
index 0000000..b6933ae
--- /dev/null
@@ -0,0 +1,99 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main.h"\r
+#include "SKP_Silk_tuning_parameters.h"\r
+\r
+SKP_INLINE SKP_int SKP_Silk_setup_complexity(\r
+    SKP_Silk_encoder_state          *psEncC,            /* I/O  Pointer to Silk encoder state           */\r
+    SKP_int                         Complexity          /* I    Complexity (0->low; 1->medium; 2->high) */\r
+)\r
+{\r
+    SKP_int ret = SKP_SILK_NO_ERROR;\r
+\r
+    /* Check that settings are valid */\r
+    if( LOW_COMPLEXITY_ONLY && Complexity != 0 ) { \r
+        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;\r
+    }\r
+\r
+    /* Set encoding complexity */\r
+    if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) {\r
+        /* Low complexity */\r
+        psEncC->Complexity                      = 0;\r
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_LC_MODE;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 6;\r
+        psEncC->shapingLPCOrder                 = 8;\r
+        psEncC->la_shape                        = 3 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 1;\r
+        psEncC->useInterpolatedNLSFs            = 0;\r
+        psEncC->LTPQuantLowComplexity           = 1;\r
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE;\r
+        psEncC->warping_Q16                     = 0;\r
+    } else if( Complexity == 1 ) {\r
+        /* Medium complexity */\r
+        psEncC->Complexity                      = 1;\r
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_MC_MODE;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 12;\r
+        psEncC->shapingLPCOrder                 = 12;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 2;\r
+        psEncC->useInterpolatedNLSFs            = 0;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE;\r
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
+    } else if( Complexity == 2 ) {\r
+        /* High complexity */\r
+        psEncC->Complexity                      = 2;\r
+        psEncC->pitchEstimationComplexity       = PITCH_EST_COMPLEXITY_HC_MODE;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 16;\r
+        psEncC->shapingLPCOrder                 = 16;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = MAX_DEL_DEC_STATES;\r
+        psEncC->useInterpolatedNLSFs            = 1;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = MAX_NLSF_MSVQ_SURVIVORS;\r
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
+    } else {\r
+        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;\r
+    }\r
+\r
+    /* Do not allow higher pitch estimation LPC order than predict LPC order */\r
+    psEncC->pitchEstimationLPCOrder             = SKP_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder );\r
+    psEncC->shapeWinLength                      = 5 * psEncC->fs_kHz + 2 * psEncC->la_shape;\r
+\r
+    SKP_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER );\r
+    SKP_assert( psEncC->shapingLPCOrder         <= MAX_SHAPE_LPC_ORDER      );\r
+    SKP_assert( psEncC->nStatesDelayedDecision  <= MAX_DEL_DEC_STATES       );\r
+    SKP_assert( psEncC->warping_Q16             <= 32767                    );\r
+    SKP_assert( psEncC->la_shape                <= LA_SHAPE_MAX             );\r
+    SKP_assert( psEncC->shapeWinLength          <= SHAPE_LPC_WIN_MAX        );\r
+\r
+    return( ret );\r
+}\r
diff --git a/libs/silk/src/SKP_Silk_tuning_parameters.h b/libs/silk/src/SKP_Silk_tuning_parameters.h
new file mode 100644 (file)
index 0000000..e98272d
--- /dev/null
@@ -0,0 +1,183 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#ifndef SKP_SILK_TUNING_PARAMETERS_H\r
+#define SKP_SILK_TUNING_PARAMETERS_H\r
+\r
+#ifdef __cplusplus\r
+extern "C"\r
+{\r
+#endif\r
+\r
+/*******************/\r
+/* Pitch estimator */\r
+/*******************/\r
+\r
+/* Level of noise floor for whitening filter LPC analysis in pitch analysis */\r
+#define FIND_PITCH_WHITE_NOISE_FRACTION                 1e-3f\r
+\r
+/* Bandwidth expansion for whitening filter in pitch analysis */\r
+#define FIND_PITCH_BANDWITH_EXPANSION                   0.99f\r
+\r
+/* Threshold used by pitch estimator for early escape */\r
+#define FIND_PITCH_CORRELATION_THRESHOLD_HC_MODE        0.7f\r
+#define FIND_PITCH_CORRELATION_THRESHOLD_MC_MODE        0.75f\r
+#define FIND_PITCH_CORRELATION_THRESHOLD_LC_MODE        0.8f\r
+\r
+/*********************/\r
+/* Linear prediction */\r
+/*********************/\r
+\r
+/* LPC analysis defines: regularization and bandwidth expansion */\r
+#define FIND_LPC_COND_FAC                               2.5e-5f\r
+#define FIND_LPC_CHIRP                                  0.99995f\r
+\r
+/* LTP analysis defines */\r
+#define FIND_LTP_COND_FAC                               1e-5f\r
+#define LTP_DAMPING                                     0.01f\r
+#define LTP_SMOOTHING                                   0.1f\r
+\r
+/* LTP quantization settings */\r
+#define MU_LTP_QUANT_NB                                 0.03f\r
+#define MU_LTP_QUANT_MB                                 0.025f\r
+#define MU_LTP_QUANT_WB                                 0.02f\r
+#define MU_LTP_QUANT_SWB                                0.016f\r
+\r
+/***********************/\r
+/* High pass filtering */\r
+/***********************/\r
+\r
+/* Smoothing parameters for low end of pitch frequency range estimation */\r
+#define VARIABLE_HP_SMTH_COEF1                          0.1f\r
+#define VARIABLE_HP_SMTH_COEF2                          0.015f\r
+\r
+/* Min and max values for low end of pitch frequency range estimation */\r
+#define VARIABLE_HP_MIN_FREQ                            80.0f\r
+#define VARIABLE_HP_MAX_FREQ                            150.0f\r
+\r
+/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */\r
+#define VARIABLE_HP_MAX_DELTA_FREQ                      0.4f\r
+\r
+/***********/\r
+/* Various */\r
+/***********/\r
+\r
+/* Required speech activity for counting frame as active */\r
+#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES             0.7f        \r
+\r
+#define SPEECH_ACTIVITY_DTX_THRES                       0.1f\r
+\r
+/* Speech Activity LBRR enable threshold (needs tuning) */\r
+#define LBRR_SPEECH_ACTIVITY_THRES                      0.5f        \r
+\r
+/*************************/\r
+/* Perceptual parameters */\r
+/*************************/\r
+\r
+/* reduction in coding SNR during low speech activity */\r
+#define BG_SNR_DECR_dB                                  4.0f\r
+\r
+/* factor for reducing quantization noise during voiced speech */\r
+#define HARM_SNR_INCR_dB                                2.0f\r
+\r
+/* factor for reducing quantization noise for unvoiced sparse signals */\r
+#define SPARSE_SNR_INCR_dB                              2.0f\r
+\r
+/* threshold for sparseness measure above which to use lower quantization offset during unvoiced */\r
+#define SPARSENESS_THRESHOLD_QNT_OFFSET                 0.75f\r
+\r
+/* warping control */\r
+#define WARPING_MULTIPLIER                              0.015f\r
+\r
+/* fraction added to first autocorrelation value */\r
+#define SHAPE_WHITE_NOISE_FRACTION                      1e-5f\r
+\r
+/* noise shaping filter chirp factor */\r
+#define BANDWIDTH_EXPANSION                             0.95f\r
+\r
+/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */\r
+#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA              0.01f\r
+\r
+/* gain reduction for fricatives */\r
+#define DE_ESSER_COEF_SWB_dB                            2.0f\r
+#define DE_ESSER_COEF_WB_dB                             1.0f\r
+\r
+/* extra harmonic boosting (signal shaping) at low bitrates */\r
+#define LOW_RATE_HARMONIC_BOOST                         0.1f\r
+\r
+/* extra harmonic boosting (signal shaping) for noisy input signals */\r
+#define LOW_INPUT_QUALITY_HARMONIC_BOOST                0.1f\r
+\r
+/* harmonic noise shaping */\r
+#define HARMONIC_SHAPING                                0.3f\r
+\r
+/* extra harmonic noise shaping for high bitrates or noisy input */\r
+#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING       0.2f\r
+\r
+/* parameter for shaping noise towards higher frequencies */\r
+#define HP_NOISE_COEF                                   0.3f\r
+\r
+/* parameter for shaping noise even more towards higher frequencies during voiced speech */\r
+#define HARM_HP_NOISE_COEF                              0.35f\r
+\r
+/* parameter for applying a high-pass tilt to the input signal */\r
+#define INPUT_TILT                                      0.05f\r
+\r
+/* parameter for extra high-pass tilt to the input signal at high rates */\r
+#define HIGH_RATE_INPUT_TILT                            0.1f\r
+\r
+/* parameter for reducing noise at the very low frequencies */\r
+#define LOW_FREQ_SHAPING                                3.0f\r
+\r
+/* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */\r
+#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR               0.5f\r
+\r
+/* noise floor to put a lower limit on the quantization step size */\r
+#define NOISE_FLOOR_dB                                  4.0f\r
+\r
+/* noise floor relative to active speech gain level */\r
+#define RELATIVE_MIN_GAIN_dB                            -50.0f\r
+\r
+/* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */\r
+#define GAIN_SMOOTHING_COEF                             1e-3f\r
+\r
+/* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */\r
+#define SUBFR_SMTH_COEF                                 0.4f\r
+\r
+/* parameters defining the R/D tradeoff in the residual quantizer */\r
+#define LAMBDA_OFFSET                                   1.2f\r
+#define LAMBDA_SPEECH_ACT                               -0.3f\r
+#define LAMBDA_DELAYED_DECISIONS                        -0.05f\r
+#define LAMBDA_INPUT_QUALITY                            -0.2f\r
+#define LAMBDA_CODING_QUALITY                           -0.1f\r
+#define LAMBDA_QUANT_OFFSET                             1.5f\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif // SKP_SILK_TUNING_PARAMETERS_H\r
diff --git a/libs/silk/src/SKP_Silk_warped_autocorrelation_FIX.c b/libs/silk/src/SKP_Silk_warped_autocorrelation_FIX.c
new file mode 100644 (file)
index 0000000..9a8d80d
--- /dev/null
@@ -0,0 +1,86 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main_FIX.h"\r
+\r
+#define QC  10\r
+#define QS  14\r
+\r
+\r
+/* Autocorrelations for a warped frequency axis */\r
+void SKP_Silk_warped_autocorrelation_FIX(\r
+          SKP_int32                 *corr,              /* O    Result [order + 1]                      */\r
+          SKP_int                   *scale,             /* O    Scaling of the correlation vector       */\r
+    const SKP_int16                 *input,             /* I    Input data to correlate                 */\r
+    const SKP_int16                 warping_Q16,        /* I    Warping coefficient                     */\r
+    const SKP_int                   length,             /* I    Length of input                         */\r
+    const SKP_int                   order               /* I    Correlation order (even)                */\r
+)\r
+{\r
+    SKP_int   n, i, lsh;\r
+    SKP_int32 tmp1_QS, tmp2_QS;\r
+    SKP_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };\r
+    SKP_int64 corr_QC[  MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };\r
+\r
+    /* Order must be even */\r
+    SKP_assert( ( order & 1 ) == 0 );\r
+    SKP_assert( 2 * QS - QC >= 0 );\r
+\r
+    /* Loop over samples */\r
+    for( n = 0; n < length; n++ ) {\r
+        tmp1_QS = SKP_LSHIFT32( ( SKP_int32 )input[ n ], QS );\r
+        /* Loop over allpass sections */\r
+        for( i = 0; i < order; i += 2 ) {\r
+            /* Output of allpass section */\r
+            tmp2_QS = SKP_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 );\r
+            state_QS[ i ]  = tmp1_QS;\r
+            corr_QC[  i ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
+            /* Output of allpass section */\r
+            tmp1_QS = SKP_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 );\r
+            state_QS[ i + 1 ]  = tmp2_QS;\r
+            corr_QC[  i + 1 ] += SKP_RSHIFT64( SKP_SMULL( tmp2_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
+        }\r
+        state_QS[ order ] = tmp1_QS;\r
+        corr_QC[  order ] += SKP_RSHIFT64( SKP_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );\r
+    }\r
+\r
+    lsh = SKP_Silk_CLZ64( corr_QC[ 0 ] ) - 35;\r
+    lsh = SKP_LIMIT( lsh, -12 - QC, 30 - QC );\r
+    *scale = -( QC + lsh ); \r
+    SKP_assert( *scale >= -30 && *scale <= 12 );\r
+    if( lsh >= 0 ) {\r
+        for( i = 0; i < order + 1; i++ ) {\r
+            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_LSHIFT64( corr_QC[ i ], lsh ) );\r
+        }\r
+    } else {\r
+        for( i = 0; i < order + 1; i++ ) {\r
+            corr[ i ] = ( SKP_int32 )SKP_CHECK_FIT32( SKP_RSHIFT64( corr_QC[ i ], -lsh ) );\r
+        }    \r
+    }\r
+    SKP_assert( corr_QC[ 0 ] >= 0 ); // If breaking, decrease QC\r
+}\r
+\r
diff --git a/libs/silk/test_vectors/How to use the test vectors.txt b/libs/silk/test_vectors/How to use the test vectors.txt
new file mode 100644 (file)
index 0000000..8abf1ca
--- /dev/null
@@ -0,0 +1,24 @@
+Use the following scripts to verify the decoder implementation:\r
+\r
+o test_encoder.bat / test_encoder.sh\r
+\r
+  Make sure the encoder executable to be tested exists in the parent directory, and run \r
+  test_encoder.bat (win) or test_encoder.sh (linux/mac). This will run the encoder \r
+  and compare the output bitstream with the reference bitstream files. The result is \r
+  written to test_encoder_report.txt.\r
+  For each file, the bitstreams are either bit-exact or they differ. The compatibility \r
+  test is passed if each file is reported as "PASS".\r
+\r
+o test_decoder.bat / test_decoder.sh\r
+\r
+  Make sure the decoder executable to be tested exists in the parent directory, and run \r
+  test_decoder.bat (win) or test_decoder.sh (linux/mac). This will run the decoder \r
+  and compare the output audio file with the reference audio files. The result is \r
+  written to test_decoder_report.txt.\r
+  For each file, the bitstreams are either bit-exact or they match up to a certain\r
+  average weighted SNR. The compatibility test is passed if each file is reported as \r
+  "PASS".\r
+\r
+\r
+NOTE: When using the shell script, make sure it is marked as executable.\r
+      This can be done by: chmod +x *.sh\r
diff --git a/libs/silk/test_vectors/test_decoder.bat b/libs/silk/test_vectors/test_decoder.bat
new file mode 100644 (file)
index 0000000..ff10c9e
--- /dev/null
@@ -0,0 +1,143 @@
+@echo off\r
+\r
+SET BITSTREAMPATH=./test_vectors/bitstream/\r
+SET OUTPUTPATH=./test_vectors/output/\r
+SET DEC=Decoder.exe\r
+SET COMP=SignalCompare.exe\r
+\r
+cd ..\r
+\r
+:: 8 kHz\r
+\r
+:: 8 kHz, 60 ms, 8 kbps, complexity 0\r
+SET PARAMS=8_kHz_60_ms_8_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm -fs 24000 > test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 8000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_8_kHz_out.pcm tmp.pcm -fs 8000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 12000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_12_kHz_out.pcm tmp.pcm -fs 12000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 16000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt\r
+\r
+:: 8 kHz, 40 ms, 12 kbps, complexity 1\r
+SET PARAMS=8_kHz_40_ms_12_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+:: 8 kHz, 20 ms, 20 kbps, 10% packet loss, FEC\r
+SET PARAMS=8_kHz_20_ms_20_kbps_10_loss_FEC\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -loss 10\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+\r
+:: 12 kHz\r
+\r
+:: 12 kHz, 60 ms, 10 kbps, complexity 0\r
+SET PARAMS=12_kHz_60_ms_10_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 12000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_12_kHz_out.pcm tmp.pcm -fs 12000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 16000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 32000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_32_kHz_out.pcm tmp.pcm -fs 32000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 44100\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_44100_Hz_out.pcm tmp.pcm -fs 44100 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 48000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_48_kHz_out.pcm tmp.pcm -fs 48000 >> test_decoder_report.txt\r
+\r
+:: 12 kHz, 40 ms, 16 kbps, complexity 1\r
+SET PARAMS=12_kHz_40_ms_16_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+:: 12 kHz, 20 ms, 24 kbps, 10% packet loss, FEC\r
+SET PARAMS=12_kHz_20_ms_24_kbps_10_loss_FEC\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -loss 10\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+\r
+:: 16 kHz\r
+\r
+:: 16 kHz, 60 ms, 12 kbps, complexity 0\r
+SET PARAMS=16_kHz_60_ms_12_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 16000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt\r
+\r
+:: 16 kHz, 40 ms, 20 kbps, complexity 1\r
+SET PARAMS=16_kHz_40_ms_20_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+:: 16 kHz, 20 ms, 32 kbps, 10% packet loss, FEC\r
+SET PARAMS=16_kHz_20_ms_32_kbps_10_loss_FEC\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -loss 10\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+\r
+:: 24 kHz\r
+\r
+:: 24 kHz, 60 ms, 16 kbps, complexity 0\r
+SET PARAMS=24_kHz_60_ms_16_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+:: 24 kHz, 40 ms, 24 kbps, complexity 1\r
+SET PARAMS=24_kHz_40_ms_24_kbps\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm \r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+:: 24 kHz, 20 ms, 40 kbps, 10% packet loss, FEC\r
+SET PARAMS=24_kHz_20_ms_40_kbps_10_loss_FEC\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -loss 10\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+\r
+:: 32 kHz\r
+\r
+:: 32 kHz, 20 ms, 8 kbps, maxInternal 8kHz\r
+SET PARAMS=32_kHz_max_8_kHz_20_ms_8_kbps\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 32000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_32_kHz_out.pcm tmp.pcm -fs 32000 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 44100\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_44100_Hz_out.pcm tmp.pcm -fs 44100 >> test_decoder_report.txt\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm -Fs_API 48000\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%_48_kHz_out.pcm tmp.pcm -fs 48000 >> test_decoder_report.txt\r
+\r
+\r
+:: 44100 Hz\r
+\r
+:: 44100 Hz, 20 ms, 40 kbps\r
+SET PARAMS=44100_Hz_20_ms_7_kbps\r
+\r
+%DEC% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.pcm\r
+%COMP% %OUTPUTPATH%testvector_output_%PARAMS%.pcm tmp.pcm >> test_decoder_report.txt\r
+\r
+\r
+del tmp.pcm\r
+move test_decoder_report.txt ./test_vectors/test_decoder_report.txt\r
+\r
+echo.\r
+echo The results have been saved as test_decoder_report.txt\r
+echo.\r
+\r
+pause\r
diff --git a/libs/silk/test_vectors/test_decoder.sh b/libs/silk/test_vectors/test_decoder.sh
new file mode 100644 (file)
index 0000000..08e61fa
--- /dev/null
@@ -0,0 +1,142 @@
+#!/bin/bash
+
+BITSTREAMPATH=./test_vectors/bitstream/
+OUTPUTPATH=./test_vectors/output/
+DEC=decoder
+COMP=signalcompare
+
+cd ..
+
+
+# 8 kHz
+
+# 8 kHz, 60 ms, 8 kbps, complexity 0
+PARAMS=8_kHz_60_ms_8_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm -fs 24000 > test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 8000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_8_kHz_out.pcm tmp.pcm -fs 8000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 12000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_12_kHz_out.pcm tmp.pcm -fs 12000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 16000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt
+
+# 8 kHz, 40 ms, 12 kbps, complexity 1
+PARAMS=8_kHz_40_ms_12_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+# 8 kHz, 20 ms, 20 kbps, 10% packet loss, FEC
+PARAMS=8_kHz_20_ms_20_kbps_10_loss_FEC
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -loss 10
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+
+# 12 kHz
+
+# 12 kHz, 60 ms, 10 kbps, complexity 0
+PARAMS=12_kHz_60_ms_10_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 12000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_12_kHz_out.pcm tmp.pcm -fs 12000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 16000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 32000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_32_kHz_out.pcm tmp.pcm -fs 32000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 44100
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_44100_Hz_out.pcm tmp.pcm -fs 44100 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 48000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_48_kHz_out.pcm tmp.pcm -fs 48000 >> test_decoder_report.txt
+
+# 12 kHz, 40 ms, 16 kbps, complexity 1
+PARAMS=12_kHz_40_ms_16_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+# 12 kHz, 20 ms, 24 kbps, 10% packet loss, FEC
+PARAMS=12_kHz_20_ms_24_kbps_10_loss_FEC
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -loss 10
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+
+# 16 kHz
+
+# 16 kHz, 60 ms, 12 kbps, complexity 0
+PARAMS=16_kHz_60_ms_12_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 16000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_16_kHz_out.pcm tmp.pcm -fs 16000 >> test_decoder_report.txt
+
+# 16 kHz, 40 ms, 20 kbps, complexity 1
+PARAMS=16_kHz_40_ms_20_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+# 16 kHz, 20 ms, 32 kbps, 10% packet loss, FEC
+PARAMS=16_kHz_20_ms_32_kbps_10_loss_FEC
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -loss 10
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+
+# 24 kHz
+
+# 24 kHz, 60 ms, 16 kbps, complexity 0
+PARAMS=24_kHz_60_ms_16_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+# 24 kHz, 40 ms, 24 kbps, complexity 1
+PARAMS=24_kHz_40_ms_24_kbps
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+# 24 kHz, 20 ms, 40 kbps, 10% packet loss, FEC
+PARAMS=24_kHz_20_ms_40_kbps_10_loss_FEC
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -loss 10
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+
+# 32 kHz
+
+# 32 kHz, 20 ms, 8 kbps, maxInternal 8kHz
+PARAMS=32_kHz_max_8_kHz_20_ms_8_kbps
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 32000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_32_kHz_out.pcm tmp.pcm -fs 32000 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 44100
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_44100_Hz_out.pcm tmp.pcm -fs 44100 >> test_decoder_report.txt
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm -Fs_API 48000
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}_48_kHz_out.pcm tmp.pcm -fs 48000 >> test_decoder_report.txt
+
+
+# 44100 Hz
+
+# 44100 Hz, 20 ms, 40 kbps
+PARAMS=44100_Hz_20_ms_7_kbps
+
+./${DEC} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.pcm
+./${COMP} ${OUTPUTPATH}testvector_output_${PARAMS}.pcm tmp.pcm >> test_decoder_report.txt
+
+
+rm tmp.pcm
+mv test_decoder_report.txt ./test_vectors/test_decoder_report.txt
+
+echo ""
+echo "The results have been saved as test_decoder_report.txt"
+echo ""
\ No newline at end of file
diff --git a/libs/silk/test_vectors/test_encoder.bat b/libs/silk/test_vectors/test_encoder.bat
new file mode 100644 (file)
index 0000000..2799696
--- /dev/null
@@ -0,0 +1,111 @@
+@echo off\r
+\r
+SET INPUTPATH=./test_vectors/input/\r
+SET BITSTREAMPATH=./test_vectors/bitstream/\r
+SET ENC=Encoder.exe\r
+SET COMP=SignalCompare.exe\r
+\r
+cd ..\r
+\r
+:: 8 kHz\r
+SET INPUTFILE=testvector_input_8_kHz.pcm\r
+\r
+:: 8 kHz, 60 ms, 8 kbps, complexity 0\r
+SET PARAMS=8_kHz_60_ms_8_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 8000 -packetlength 60 -rate 8000 -complexity 0\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff > test_encoder_report.txt\r
+\r
+:: 8 kHz, 40 ms, 12 kbps, complexity 1\r
+SET PARAMS=8_kHz_40_ms_12_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 8000 -packetlength 40 -rate 12000 -complexity 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 8 kHz, 20 ms, 20 kbps, 10% packet loss, FEC\r
+SET PARAMS=8_kHz_20_ms_20_kbps_10_loss_FEC\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 8000 -packetlength 20 -rate 20000 -loss 10 -inbandFEC 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+:: 12 kHz\r
+SET INPUTFILE=testvector_input_12_kHz.pcm\r
+\r
+:: 12 kHz, 60 ms, 10 kbps, complexity 0\r
+SET PARAMS=12_kHz_60_ms_10_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 12000 -packetlength 60 -rate 10000 -complexity 0\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 12 kHz, 40 ms, 16 kbps, complexity 1\r
+SET PARAMS=12_kHz_40_ms_16_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 12000 -packetlength 40 -rate 16000 -complexity 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 12 kHz, 20 ms, 24 kbps, 10% packet loss, FEC\r
+SET PARAMS=12_kHz_20_ms_24_kbps_10_loss_FEC\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 12000 -packetlength 20 -rate 24000 -loss 10 -inbandFEC 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+:: 16 kHz\r
+SET INPUTFILE=testvector_input_16_kHz.pcm\r
+\r
+:: 16 kHz, 60 ms, 12 kbps, complexity 0\r
+SET PARAMS=16_kHz_60_ms_12_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 16000 -packetlength 60 -rate 12000 -complexity 0\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 16 kHz, 40 ms, 20 kbps, complexity 1\r
+SET PARAMS=16_kHz_40_ms_20_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 16000 -packetlength 40 -rate 20000 -complexity 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 16 kHz, 20 ms, 32 kbps, 10% packet loss, FEC\r
+SET PARAMS=16_kHz_20_ms_32_kbps_10_loss_FEC\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 16000 -packetlength 20 -rate 32000 -loss 10 -inbandFEC 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+:: 24 kHz\r
+SET INPUTFILE=testvector_input_24_kHz.pcm\r
+\r
+:: 24 kHz, 60 ms, 16 kbps, complexity 0\r
+SET PARAMS=24_kHz_60_ms_16_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 24000 -packetlength 60 -rate 16000 -complexity 0\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 24 kHz, 40 ms, 24 kbps, complexity 1\r
+SET PARAMS=24_kHz_40_ms_24_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 24000 -packetlength 40 -rate 24000 -complexity 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+:: 24 kHz, 20 ms, 40 kbps, 10% packet loss, FEC\r
+SET PARAMS=24_kHz_20_ms_40_kbps_10_loss_FEC\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 24000 -packetlength 20 -rate 40000 -loss 10 -inbandFEC 1\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+:: 32 kHz\r
+SET INPUTFILE=testvector_input_32_kHz.pcm\r
+\r
+:: 32 kHz, 20 ms, 8 kbps, maxInternal 8kHz\r
+SET PARAMS=32_kHz_max_8_kHz_20_ms_8_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 32000 -Fs_maxInternal 8000 -packetlength 20 -rate 8000\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+:: 44100 Hz\r
+SET INPUTFILE=testvector_input_44100_Hz.pcm\r
+\r
+:: 44100 Hz, 20 ms, 40 kbps\r
+SET PARAMS=44100_Hz_20_ms_7_kbps\r
+%ENC% %INPUTPATH%%INPUTFILE% tmp.bit -Fs_API 44100 -packetlength 20 -rate 7000\r
+%COMP% %BITSTREAMPATH%payload_%PARAMS%.bit tmp.bit -diff >> test_encoder_report.txt\r
+\r
+\r
+del tmp.bit\r
+move test_encoder_report.txt ./test_vectors/test_encoder_report.txt\r
+\r
+echo.\r
+echo The results have been saved as test_encoder_report.txt\r
+echo.\r
+\r
+pause\r
diff --git a/libs/silk/test_vectors/test_encoder.sh b/libs/silk/test_vectors/test_encoder.sh
new file mode 100644 (file)
index 0000000..b25e3a5
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+INPUTPATH=./test_vectors/input/
+BITSTREAMPATH=./test_vectors/bitstream/
+ENC=encoder
+COMP=signalcompare
+
+cd ..
+
+# 8 kHz
+INPUTFILE=testvector_input_8_kHz.pcm
+
+# 8 kHz, 60 ms, 8 kbps, complexity 0
+PARAMS=8_kHz_60_ms_8_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 8000 -packetlength 60 -rate 8000 -complexity 0
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff > test_encoder_report.txt
+
+# 8 kHz, 40 ms, 12 kbps, complexity 1
+PARAMS=8_kHz_40_ms_12_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 8000 -packetlength 40 -rate 12000 -complexity 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 8 kHz, 20 ms, 20 kbps, 10% packet loss, FEC
+PARAMS=8_kHz_20_ms_20_kbps_10_loss_FEC
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 8000 -packetlength 20 -rate 20000 -loss 10 -inbandFEC 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+# 12 kHz
+INPUTFILE=testvector_input_12_kHz.pcm
+
+# 12 kHz, 60 ms, 10 kbps, complexity 0
+PARAMS=12_kHz_60_ms_10_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 12000 -packetlength 60 -rate 10000 -complexity 0
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 12 kHz, 40 ms, 16 kbps, complexity 1
+PARAMS=12_kHz_40_ms_16_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 12000 -packetlength 40 -rate 16000 -complexity 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 12 kHz, 20 ms, 24 kbps, 10% packet loss, FEC
+PARAMS=12_kHz_20_ms_24_kbps_10_loss_FEC
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 12000 -packetlength 20 -rate 24000 -loss 10 -inbandFEC 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+# 16 kHz
+INPUTFILE=testvector_input_16_kHz.pcm
+
+# 16 kHz, 60 ms, 12 kbps, complexity 0
+PARAMS=16_kHz_60_ms_12_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 16000 -packetlength 60 -rate 12000 -complexity 0
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 16 kHz, 40 ms, 20 kbps, complexity 1
+PARAMS=16_kHz_40_ms_20_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 16000 -packetlength 40 -rate 20000 -complexity 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 16 kHz, 20 ms, 32 kbps, 10% packet loss, FEC
+PARAMS=16_kHz_20_ms_32_kbps_10_loss_FEC
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 16000 -packetlength 20 -rate 32000 -loss 10 -inbandFEC 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+# 24 kHz
+INPUTFILE=testvector_input_24_kHz.pcm
+
+# 24 kHz, 60 ms, 16 kbps, complexity 0
+PARAMS=24_kHz_60_ms_16_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 24000 -packetlength 60 -rate 16000 -complexity 0
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 24 kHz, 40 ms, 24 kbps, complexity 1
+PARAMS=24_kHz_40_ms_24_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 24000 -packetlength 40 -rate 24000 -complexity 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+# 24 kHz, 20 ms, 40 kbps, 10% packet loss, FEC
+PARAMS=24_kHz_20_ms_40_kbps_10_loss_FEC
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 24000 -packetlength 20 -rate 40000 -loss 10 -inbandFEC 1
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+# 32 kHz
+INPUTFILE=testvector_input_32_kHz.pcm
+
+# 32 kHz, 20 ms, 8 kbps, maxInternal 8kHz
+PARAMS=32_kHz_max_8_kHz_20_ms_8_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 32000 -Fs_maxInternal 8000 -packetlength 20 -rate 8000
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+# 44100 Hz
+INPUTFILE=testvector_input_44100_Hz.pcm
+
+# 44100 Hz, 20 ms, 40 kbps
+PARAMS=44100_Hz_20_ms_7_kbps
+./${ENC} ${INPUTPATH}${INPUTFILE} tmp.bit -Fs_API 44100 -packetlength 20 -rate 7000
+./${COMP} ${BITSTREAMPATH}payload_${PARAMS}.bit tmp.bit -diff >> test_encoder_report.txt
+
+
+rm tmp.bit
+mv test_encoder_report.txt ./test_vectors/test_encoder_report.txt
+
+echo ""
+echo "The results have been saved as test_encoder_report.txt"
+echo ""
\ No newline at end of file
index 934c9ebe32534473630a4ea4f8cd4c66960ae25c..7e2ba0afd3ceee8e29ab86d79db9e6346069f240 100644 (file)
@@ -192,7 +192,9 @@ static switch_status_t switch_silk_init(switch_codec_t *codec,
                        return SWITCH_STATUS_FALSE;
                }
                
-               context->encoder_object.sampleRate = codec->implementation->actual_samples_per_second;
+
+               context->encoder_object.API_sampleRate = codec->implementation->actual_samples_per_second;
+               context->encoder_object.maxInternalSampleRate = codec->implementation->actual_samples_per_second;
                context->encoder_object.packetSize = codec->implementation->samples_per_packet;
                context->encoder_object.useInBandFEC = silk_codec_settings.useinbandfec;
                context->encoder_object.complexity = 0;
@@ -210,7 +212,7 @@ static switch_status_t switch_silk_init(switch_codec_t *codec,
                if (SKP_Silk_SDK_InitDecoder(context->dec_state)) {
                        return SWITCH_STATUS_FALSE;
                }
-               context->decoder_object.sampleRate = codec->implementation->actual_samples_per_second;
+               context->decoder_object.API_sampleRate = codec->implementation->actual_samples_per_second;
        }
 
        codec->private_info = context;
@@ -241,22 +243,22 @@ void printSilkError(SKP_int16 ret){
                case SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT: 
                        message = "Allocated payload buffer too short";
                        break;
-               case SKP_SILK_ENC_WRONG_LOSS_RATE: 
+               case SKP_SILK_ENC_INVALID_LOSS_RATE: 
                        message = " Loss rate not between  0 and 100 % ";
                        break;
-               case SKP_SILK_ENC_WRONG_COMPLEXITY_SETTING:
+               case SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING:
                        message = "Complexity setting not valid, use 0 ,1 or 2";
                        break;
-               case SKP_SILK_ENC_WRONG_INBAND_FEC_SETTING: 
+               case SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING: 
                        message = "Inband FEC setting not valid, use 0 or 1     ";
                        break;
-               case SKP_SILK_ENC_WRONG_DTX_SETTING:
+               case SKP_SILK_ENC_INVALID_DTX_SETTING:
                        message = "DTX setting not valid, use 0 or 1";
                        break;
                case SKP_SILK_ENC_INTERNAL_ERROR:
                        message = "Internal Encoder Error ";
                        break;
-               case SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY:
+               case SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY:
                        message = "Output sampling frequency lower than internal decoded sampling frequency";
                        break;
                case SKP_SILK_DEC_PAYLOAD_TOO_LARGE: