get_scaling_square.c (1293B)
1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 /* 12 * This file contains the function WebRtcSpl_GetScalingSquare(). 13 * The description header can be found in signal_processing_library.h 14 * 15 */ 16 17 #include "common_audio/signal_processing/include/signal_processing_library.h" 18 19 int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector, 20 size_t in_vector_length, 21 size_t times) { 22 int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times); 23 size_t i; 24 int16_t smax = -1; 25 int16_t sabs; 26 int16_t* sptr = in_vector; 27 int16_t t; 28 size_t looptimes = in_vector_length; 29 30 for (i = looptimes; i > 0; i--) { 31 sabs = (*sptr > 0 ? *sptr++ : -*sptr++); 32 smax = (sabs > smax ? sabs : smax); 33 } 34 t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax)); 35 36 if (smax == 0) { 37 return 0; // Since norm(0) returns 0 38 } else { 39 return (t > nbits) ? 0 : nbits - t; 40 } 41 }