Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoen Vos <koen.vos@skype.net>2011-12-13 23:47:31 +0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2011-12-13 23:47:31 +0400
commitbf75c8ec4d0dded188bc7793de6da56c7ff0be1c (patch)
treec21bb05faf0a203b73e8f8aae90fc63dac27625d /silk/resampler.c
parent6619a736376221f2782cecff55d051c3ecfc2ff7 (diff)
SILK fixes following last codec WG meeting
decoder: - fixed incorrect scaling of filter states for the smallest quantization step sizes - NLSF2A now limits the prediction gain of LPC filters encoder: - increased damping of LTP coefficients in LTP analysis - increased white noise fraction in noise shaping LPC analysis - introduced maximum total prediction gain. Used by Burg's method to exit early if prediction gain is exceeded. This improves packet loss robustness and numerical robustness in Burg's method - Prefiltered signal is now in int32 Q10 domain, from int16 Q0 - Increased max number of iterations in CBR gain control loop from 5 to 6 - Removed useless code from LTP scaling control - Optimization: smarter LPC loop unrolling - Switched default win32 compile mode to be floating-point resampler: - made resampler have constant delay of 0.75 ms; removed delay compensation from silk code. - removed obsolete table entries (~850 Bytes) - increased downsampling filter order from 16 to 18/24/36 (depending on frequency ratio) - reoptimized filter coefficients
Diffstat (limited to 'silk/resampler.c')
-rw-r--r--silk/resampler.c132
1 files changed, 90 insertions, 42 deletions
diff --git a/silk/resampler.c b/silk/resampler.c
index eeda054a..9055c813 100644
--- a/silk/resampler.c
+++ b/silk/resampler.c
@@ -29,30 +29,46 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "config.h"
#endif
-/* Matrix of resampling methods used:
+/*
+ * Matrix of resampling methods used:
* Fs_out (kHz)
- * 8 12 16 24 48
+ * 8 12 16 24 48
*
* 8 C UF U UF UF
* 12 AF C UF U UF
* Fs_in (kHz) 16 D AF C UF UF
- * 24 AIF D AF C U
- * 48 DAF DAF AF D C
- *
- * default method: UF
+ * 24 AF D AF C U
+ * 48 AF AF AF D C
*
* C -> Copy (no resampling)
* D -> Allpass-based 2x downsampling
* U -> Allpass-based 2x upsampling
- * DAF -> Allpass-based 2x downsampling followed by AR2 filter followed by FIR interpolation
* UF -> Allpass-based 2x upsampling followed by FIR interpolation
* AF -> AR2 filter followed by FIR interpolation
- *
- * Signals sampled above 48 kHz are not supported.
*/
#include "resampler_private.h"
+/* Tables with delay compensation values to equalize total delay for different modes */
+static const opus_int8 delay_matrix_enc[ 5 ][ 3 ] = {
+/* in \ out 8 12 16 */
+/* 8 */ { 6, 0, 3 },
+/* 12 */ { 0, 7, 3 },
+/* 16 */ { 0, 1, 10 },
+/* 24 */ { 0, 2, 6 },
+/* 48 */ { 18, 10, 12 }
+};
+
+static const opus_int8 delay_matrix_dec[ 3 ][ 5 ] = {
+/* in \ out 8 12 16 24 48 */
+/* 8 */ { 4, 0, 2, 0, 0 },
+/* 12 */ { 0, 9, 4, 7, 4 },
+/* 16 */ { 0, 3, 12, 7, 7 }
+};
+
+/* Simple way to make [8000, 12000, 16000, 24000, 48000] to [0, 1, 2, 3, 4] */
+#define rateID(R) ( ( ( ((R)>>12) - ((R)>16000) ) >> ((R)>24000) ) - 1 )
+
#define USE_silk_resampler_copy (0)
#define USE_silk_resampler_private_up2_HQ_wrapper (1)
#define USE_silk_resampler_private_IIR_FIR (2)
@@ -60,27 +76,42 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Initialize/reset the resampler state for a given pair of input/output sampling rates */
opus_int silk_resampler_init(
- silk_resampler_state_struct *S, /* I/O Resampler state */
- opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
- opus_int32 Fs_Hz_out /* I Output sampling rate (Hz) */
+ silk_resampler_state_struct *S, /* I/O Resampler state */
+ opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
+ opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
+ opus_int forEnc /* I If 1: encoder; if 0: decoder */
)
{
- opus_int32 up2 = 0, down2 = 0;
+ opus_int up2x;
/* Clear state */
silk_memset( S, 0, sizeof( silk_resampler_state_struct ) );
/* Input checking */
- if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000 ) ||
- ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000 ) ) {
- silk_assert( 0 );
- return -1;
+ if( forEnc ) {
+ if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000 ) ||
+ ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 ) ) {
+ silk_assert( 0 );
+ return -1;
+ }
+ S->inputDelay = delay_matrix_enc[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
+ } else {
+ if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 ) ||
+ ( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000 ) ) {
+ silk_assert( 0 );
+ return -1;
+ }
+ S->inputDelay = delay_matrix_dec[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
}
+ S->Fs_in_kHz = silk_DIV32_16( Fs_Hz_in, 1000 );
+ S->Fs_out_kHz = silk_DIV32_16( Fs_Hz_out, 1000 );
+
/* Number of samples processed per batch */
- S->batchSize = silk_DIV32_16( Fs_Hz_in, 100 );
+ S->batchSize = S->Fs_in_kHz * RESAMPLER_MAX_BATCH_SIZE_MS;
/* Find resampler with the right sampling ratio */
+ up2x = 0;
if( Fs_Hz_out > Fs_Hz_in ) {
/* Upsample */
if( Fs_Hz_out == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 1 */
@@ -89,36 +120,35 @@ opus_int silk_resampler_init(
} else {
/* Default resampler */
S->resampler_function = USE_silk_resampler_private_IIR_FIR;
- up2 = 1;
+ up2x = 1;
}
} else if ( Fs_Hz_out < Fs_Hz_in ) {
/* Downsample */
+ S->resampler_function = USE_silk_resampler_private_down_FIR;
if( silk_MUL( Fs_Hz_out, 4 ) == silk_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 4 */
S->FIR_Fracs = 3;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
S->Coefs = silk_Resampler_3_4_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
} else if( silk_MUL( Fs_Hz_out, 3 ) == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 3 */
S->FIR_Fracs = 2;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
S->Coefs = silk_Resampler_2_3_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
} else if( silk_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 2 */
S->FIR_Fracs = 1;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR1;
S->Coefs = silk_Resampler_1_2_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
} else if( silk_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 3 */
S->FIR_Fracs = 1;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
S->Coefs = silk_Resampler_1_3_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
} else if( silk_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 4 */
S->FIR_Fracs = 1;
- down2 = 1;
- S->Coefs = silk_Resampler_1_2_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
+ S->Coefs = silk_Resampler_1_4_COEFS;
} else if( silk_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 6 */
S->FIR_Fracs = 1;
- down2 = 1;
- S->Coefs = silk_Resampler_1_3_COEFS;
- S->resampler_function = USE_silk_resampler_private_down_FIR;
+ S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
+ S->Coefs = silk_Resampler_1_6_COEFS;
} else {
/* None available */
silk_assert( 0 );
@@ -129,12 +159,10 @@ opus_int silk_resampler_init(
S->resampler_function = USE_silk_resampler_copy;
}
- S->input2x = up2 | down2;
-
/* Ratio of input/output samples */
- S->invRatio_Q16 = silk_LSHIFT32( silk_DIV32( silk_LSHIFT32( Fs_Hz_in, 14 + up2 - down2 ), Fs_Hz_out ), 2 );
+ S->invRatio_Q16 = silk_LSHIFT32( silk_DIV32( silk_LSHIFT32( Fs_Hz_in, 14 + up2x ), Fs_Hz_out ), 2 );
/* Make sure the ratio is rounded up */
- while( silk_SMULWW( S->invRatio_Q16, silk_LSHIFT32( Fs_Hz_out, down2 ) ) < silk_LSHIFT32( Fs_Hz_in, up2 ) ) {
+ while( silk_SMULWW( S->invRatio_Q16, Fs_Hz_out ) < silk_LSHIFT32( Fs_Hz_in, up2x ) ) {
S->invRatio_Q16++;
}
@@ -142,26 +170,46 @@ opus_int silk_resampler_init(
}
/* Resampler: convert from one sampling rate to another */
+/* Input and output sampling rate are at most 48000 Hz */
opus_int silk_resampler(
- silk_resampler_state_struct *S, /* I/O Resampler state */
- opus_int16 out[], /* O Output signal */
- const opus_int16 in[], /* I Input signal */
- opus_int32 inLen /* I Number of input samples */
+ silk_resampler_state_struct *S, /* I/O Resampler state */
+ opus_int16 out[], /* O Output signal */
+ const opus_int16 in[], /* I Input signal */
+ opus_int32 inLen /* I Number of input samples */
)
{
- /* Input and output sampling rate are at most 48000 Hz */
+ opus_int nSamples;
+
+ /* Need at least 1 ms of input data */
+ silk_assert( inLen >= S->Fs_in_kHz );
+ /* Delay can't exceed the 1 ms of buffering */
+ silk_assert( S->inputDelay <= S->Fs_in_kHz );
+
+ nSamples = S->Fs_in_kHz - S->inputDelay;
+
+ /* Copy to delay buffer */
+ silk_memcpy( &S->delayBuf[ S->inputDelay ], in, nSamples * sizeof( opus_int16 ) );
+
switch( S->resampler_function ) {
case USE_silk_resampler_private_up2_HQ_wrapper:
- silk_resampler_private_up2_HQ_wrapper( S, out, in, inLen );
+ silk_resampler_private_up2_HQ_wrapper( S, out, S->delayBuf, S->Fs_in_kHz );
+ silk_resampler_private_up2_HQ_wrapper( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
break;
case USE_silk_resampler_private_IIR_FIR:
- silk_resampler_private_IIR_FIR( S, out, in, inLen );
+ silk_resampler_private_IIR_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
+ silk_resampler_private_IIR_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
break;
case USE_silk_resampler_private_down_FIR:
- silk_resampler_private_down_FIR( S, out, in, inLen );
+ silk_resampler_private_down_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
+ silk_resampler_private_down_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
break;
default:
- silk_memcpy( out, in, inLen * sizeof( opus_int16 ) );
+ silk_memcpy( out, S->delayBuf, S->Fs_in_kHz * sizeof( opus_int16 ) );
+ silk_memcpy( &out[ S->Fs_out_kHz ], &in[ nSamples ], ( inLen - S->Fs_in_kHz ) * sizeof( opus_int16 ) );
}
+
+ /* Copy to delay buffer */
+ silk_memcpy( S->delayBuf, &in[ inLen - S->inputDelay ], S->inputDelay * sizeof( opus_int16 ) );
+
return 0;
}