@@ -2787,66 +2787,6 @@ void SilkDecoder::silk_PLC_glue_frames(uint8_t n, int16_t frame[], int32_t lengt
27872787 }
27882788}
27892789// ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
2790- /* Downsample by a factor 2/3, low quality */
2791- void SilkDecoder::silk_resampler_down2_3 (int32_t * S, /* I/O State vector [ 6 ] */
2792- int16_t * out, /* O Output signal [ floor(2*inLen/3) ] */
2793- const int16_t * in, /* I Input signal [ inLen ] */
2794- int32_t inLen /* I Number of input samples */
2795- ) {
2796- int32_t nSamplesIn, counter, res_Q6;
2797- int32_t * buf_ptr;
2798-
2799- ps_ptr<int32_t >buf; buf.alloc_array (RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR);
2800-
2801- /* Copy buffered samples to start of buffer */
2802- memcpy (buf.get (), S, ORDER_FIR * sizeof (int32_t ));
2803-
2804- /* Iterate over blocks of frameSizeIn input samples */
2805- while (1 ) {
2806- nSamplesIn = silk_min (inLen, RESAMPLER_MAX_BATCH_SIZE_IN);
2807-
2808- /* Second-order AR filter (output in Q8) */
2809- silk_resampler_private_AR2 (&S[ORDER_FIR], &buf[ORDER_FIR], in, silk_Resampler_2_3_COEFS_LQ, nSamplesIn);
2810-
2811- /* Interpolate filtered signal */
2812- buf_ptr = buf.get ();
2813- counter = nSamplesIn;
2814- while (counter > 2 ) {
2815- /* Inner product */
2816- res_Q6 = silk_SMULWB (buf_ptr[0 ], silk_Resampler_2_3_COEFS_LQ[2 ]);
2817- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[1 ], silk_Resampler_2_3_COEFS_LQ[3 ]);
2818- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[2 ], silk_Resampler_2_3_COEFS_LQ[5 ]);
2819- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[3 ], silk_Resampler_2_3_COEFS_LQ[4 ]);
2820-
2821- /* Scale down, saturate and store in output array */
2822- *out++ = (int16_t )silk_SAT16 (silk_RSHIFT_ROUND (res_Q6, 6 ));
2823-
2824- res_Q6 = silk_SMULWB (buf_ptr[1 ], silk_Resampler_2_3_COEFS_LQ[4 ]);
2825- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[2 ], silk_Resampler_2_3_COEFS_LQ[5 ]);
2826- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[3 ], silk_Resampler_2_3_COEFS_LQ[3 ]);
2827- res_Q6 = silk_SMLAWB (res_Q6, buf_ptr[4 ], silk_Resampler_2_3_COEFS_LQ[2 ]);
2828-
2829- /* Scale down, saturate and store in output array */
2830- *out++ = (int16_t )silk_SAT16 (silk_RSHIFT_ROUND (res_Q6, 6 ));
2831-
2832- buf_ptr += 3 ;
2833- counter -= 3 ;
2834- }
2835-
2836- in += nSamplesIn;
2837- inLen -= nSamplesIn;
2838-
2839- if (inLen > 0 ) {
2840- /* More iterations to do; copy last part of filtered signal to beginning of buffer */
2841- memcpy (buf.get (), &buf[nSamplesIn], ORDER_FIR * sizeof (int32_t ));
2842- }
2843- else { break ; }
2844- }
2845-
2846- /* Copy last part of filtered signal to the state for the next call */
2847- memcpy (S, &buf[nSamplesIn], ORDER_FIR * sizeof (int32_t ));
2848- }
2849- // ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
28502790/* Downsample by a factor 2 */
28512791void SilkDecoder::silk_resampler_down2 (int32_t * S, /* I/O State vector [ 2 ] */
28522792 int16_t * out, /* O Output signal [ floor(len/2) ] */
@@ -3084,7 +3024,11 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30843024 int32_t nSamplesIn;
30853025 int32_t max_index_Q16, index_increment_Q16;
30863026
3087- ps_ptr<int16_t >buf; buf.alloc_array (2 * S->batchSize + RESAMPLER_ORDER_FIR_12);
3027+ ps_ptr<int16_t > buf;
3028+ int32_t buf_size = 2 * S->batchSize + RESAMPLER_ORDER_FIR_12;
3029+ if (!buf.alloc_array (buf_size)) {
3030+ return ; // Allocation failed
3031+ }
30883032
30893033 /* Copy buffered samples to start of buffer */
30903034 memcpy (buf.get (), S->sFIR .i16 , RESAMPLER_ORDER_FIR_12 * sizeof (int16_t ));
@@ -3095,7 +3039,7 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30953039 nSamplesIn = silk_min (inLen, S->batchSize );
30963040
30973041 /* Upsample 2x */
3098- silk_resampler_private_up2_HQ (S->sIIR , & buf[ RESAMPLER_ORDER_FIR_12] , in, nSamplesIn);
3042+ silk_resampler_private_up2_HQ (S->sIIR , buf. get () + RESAMPLER_ORDER_FIR_12, in, nSamplesIn);
30993043
31003044 max_index_Q16 = silk_LSHIFT32 (nSamplesIn, 16 + 1 ); /* + 1 because 2x upsampling */
31013045 out = silk_resampler_private_IIR_FIR_INTERPOL (out, buf.get (), max_index_Q16, index_increment_Q16);
@@ -3104,13 +3048,19 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
31043048
31053049 if (inLen > 0 ) {
31063050 /* More iterations to do; copy last part of filtered signal to beginning of buffer */
3107- memcpy (buf.get (), &buf[nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof (int16_t ));
3051+ int32_t src_offset = nSamplesIn << 1 ;
3052+ if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3053+ memcpy (buf.get (), buf.get () + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof (int16_t ));
3054+ }
31083055 }
31093056 else { break ; }
31103057 }
31113058
31123059 /* Copy last part of filtered signal to the state for the next call */
3113- memcpy (S->sFIR .i16 , &buf[nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof (int16_t ));
3060+ int32_t src_offset = nSamplesIn << 1 ;
3061+ if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3062+ memcpy (S->sFIR .i16 , buf.get () + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof (int16_t ));
3063+ }
31143064}
31153065// ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
31163066/* Upsample by a factor 2, high quality. Uses 2nd order allpass filters for the 2x upsampling, followed by a */
0 commit comments