blob: 4eb126941ebab74394d9208939c9e8cb9ec07cb5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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/*
13 * This file contains the function WebRtcSpl_GetScalingSquare().
14 * The description header can be found in signal_processing_library.h
15 *
16 */
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
bjornv@webrtc.org3cbd6c22014-09-04 13:21:44 +000020int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
Peter Kastingdce40cf2015-08-24 14:52:23 -070021 size_t in_vector_length,
22 size_t times)
niklase@google.com470e71d2011-07-07 08:21:25 +000023{
Peter Kastingb7e50542015-06-11 12:55:50 -070024 int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times);
Peter Kastingdce40cf2015-08-24 14:52:23 -070025 size_t i;
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000026 int16_t smax = -1;
27 int16_t sabs;
28 int16_t *sptr = in_vector;
bjornv@webrtc.org3cbd6c22014-09-04 13:21:44 +000029 int16_t t;
Peter Kastingdce40cf2015-08-24 14:52:23 -070030 size_t looptimes = in_vector_length;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
32 for (i = looptimes; i > 0; i--)
33 {
34 sabs = (*sptr > 0 ? *sptr++ : -*sptr++);
35 smax = (sabs > smax ? sabs : smax);
36 }
37 t = WebRtcSpl_NormW32(WEBRTC_SPL_MUL(smax, smax));
38
39 if (smax == 0)
40 {
41 return 0; // Since norm(0) returns 0
42 } else
43 {
44 return (t > nbits) ? 0 : nbits - t;
45 }
46}