LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/common_audio/signal_processing - min_max_operations.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 99 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 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 implementation of functions
      13             :  * WebRtcSpl_MaxAbsValueW16C()
      14             :  * WebRtcSpl_MaxAbsValueW32C()
      15             :  * WebRtcSpl_MaxValueW16C()
      16             :  * WebRtcSpl_MaxValueW32C()
      17             :  * WebRtcSpl_MinValueW16C()
      18             :  * WebRtcSpl_MinValueW32C()
      19             :  * WebRtcSpl_MaxAbsIndexW16()
      20             :  * WebRtcSpl_MaxIndexW16()
      21             :  * WebRtcSpl_MaxIndexW32()
      22             :  * WebRtcSpl_MinIndexW16()
      23             :  * WebRtcSpl_MinIndexW32()
      24             :  *
      25             :  */
      26             : 
      27             : #include <stdlib.h>
      28             : 
      29             : #include "webrtc/base/checks.h"
      30             : #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
      31             : 
      32             : // TODO(bjorn/kma): Consolidate function pairs (e.g. combine
      33             : //   WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.)
      34             : // TODO(kma): Move the next six functions into min_max_operations_c.c.
      35             : 
      36             : // Maximum absolute value of word16 vector. C version for generic platforms.
      37           0 : int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
      38           0 :   size_t i = 0;
      39           0 :   int absolute = 0, maximum = 0;
      40             : 
      41           0 :   RTC_DCHECK_GT(length, 0);
      42             : 
      43           0 :   for (i = 0; i < length; i++) {
      44           0 :     absolute = abs((int)vector[i]);
      45             : 
      46           0 :     if (absolute > maximum) {
      47           0 :       maximum = absolute;
      48             :     }
      49             :   }
      50             : 
      51             :   // Guard the case for abs(-32768).
      52           0 :   if (maximum > WEBRTC_SPL_WORD16_MAX) {
      53           0 :     maximum = WEBRTC_SPL_WORD16_MAX;
      54             :   }
      55             : 
      56           0 :   return (int16_t)maximum;
      57             : }
      58             : 
      59             : // Maximum absolute value of word32 vector. C version for generic platforms.
      60           0 : int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
      61             :   // Use uint32_t for the local variables, to accommodate the return value
      62             :   // of abs(0x80000000), which is 0x80000000.
      63             : 
      64           0 :   uint32_t absolute = 0, maximum = 0;
      65           0 :   size_t i = 0;
      66             : 
      67           0 :   RTC_DCHECK_GT(length, 0);
      68             : 
      69           0 :   for (i = 0; i < length; i++) {
      70           0 :     absolute = abs((int)vector[i]);
      71           0 :     if (absolute > maximum) {
      72           0 :       maximum = absolute;
      73             :     }
      74             :   }
      75             : 
      76           0 :   maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);
      77             : 
      78           0 :   return (int32_t)maximum;
      79             : }
      80             : 
      81             : // Maximum value of word16 vector. C version for generic platforms.
      82           0 : int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
      83           0 :   int16_t maximum = WEBRTC_SPL_WORD16_MIN;
      84           0 :   size_t i = 0;
      85             : 
      86           0 :   RTC_DCHECK_GT(length, 0);
      87             : 
      88           0 :   for (i = 0; i < length; i++) {
      89           0 :     if (vector[i] > maximum)
      90           0 :       maximum = vector[i];
      91             :   }
      92           0 :   return maximum;
      93             : }
      94             : 
      95             : // Maximum value of word32 vector. C version for generic platforms.
      96           0 : int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
      97           0 :   int32_t maximum = WEBRTC_SPL_WORD32_MIN;
      98           0 :   size_t i = 0;
      99             : 
     100           0 :   RTC_DCHECK_GT(length, 0);
     101             : 
     102           0 :   for (i = 0; i < length; i++) {
     103           0 :     if (vector[i] > maximum)
     104           0 :       maximum = vector[i];
     105             :   }
     106           0 :   return maximum;
     107             : }
     108             : 
     109             : // Minimum value of word16 vector. C version for generic platforms.
     110           0 : int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
     111           0 :   int16_t minimum = WEBRTC_SPL_WORD16_MAX;
     112           0 :   size_t i = 0;
     113             : 
     114           0 :   RTC_DCHECK_GT(length, 0);
     115             : 
     116           0 :   for (i = 0; i < length; i++) {
     117           0 :     if (vector[i] < minimum)
     118           0 :       minimum = vector[i];
     119             :   }
     120           0 :   return minimum;
     121             : }
     122             : 
     123             : // Minimum value of word32 vector. C version for generic platforms.
     124           0 : int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
     125           0 :   int32_t minimum = WEBRTC_SPL_WORD32_MAX;
     126           0 :   size_t i = 0;
     127             : 
     128           0 :   RTC_DCHECK_GT(length, 0);
     129             : 
     130           0 :   for (i = 0; i < length; i++) {
     131           0 :     if (vector[i] < minimum)
     132           0 :       minimum = vector[i];
     133             :   }
     134           0 :   return minimum;
     135             : }
     136             : 
     137             : // Index of maximum absolute value in a word16 vector.
     138           0 : size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
     139             :   // Use type int for local variables, to accomodate the value of abs(-32768).
     140             : 
     141           0 :   size_t i = 0, index = 0;
     142           0 :   int absolute = 0, maximum = 0;
     143             : 
     144           0 :   RTC_DCHECK_GT(length, 0);
     145             : 
     146           0 :   for (i = 0; i < length; i++) {
     147           0 :     absolute = abs((int)vector[i]);
     148             : 
     149           0 :     if (absolute > maximum) {
     150           0 :       maximum = absolute;
     151           0 :       index = i;
     152             :     }
     153             :   }
     154             : 
     155           0 :   return index;
     156             : }
     157             : 
     158             : // Index of maximum value in a word16 vector.
     159           0 : size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
     160           0 :   size_t i = 0, index = 0;
     161           0 :   int16_t maximum = WEBRTC_SPL_WORD16_MIN;
     162             : 
     163           0 :   RTC_DCHECK_GT(length, 0);
     164             : 
     165           0 :   for (i = 0; i < length; i++) {
     166           0 :     if (vector[i] > maximum) {
     167           0 :       maximum = vector[i];
     168           0 :       index = i;
     169             :     }
     170             :   }
     171             : 
     172           0 :   return index;
     173             : }
     174             : 
     175             : // Index of maximum value in a word32 vector.
     176           0 : size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
     177           0 :   size_t i = 0, index = 0;
     178           0 :   int32_t maximum = WEBRTC_SPL_WORD32_MIN;
     179             : 
     180           0 :   RTC_DCHECK_GT(length, 0);
     181             : 
     182           0 :   for (i = 0; i < length; i++) {
     183           0 :     if (vector[i] > maximum) {
     184           0 :       maximum = vector[i];
     185           0 :       index = i;
     186             :     }
     187             :   }
     188             : 
     189           0 :   return index;
     190             : }
     191             : 
     192             : // Index of minimum value in a word16 vector.
     193           0 : size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
     194           0 :   size_t i = 0, index = 0;
     195           0 :   int16_t minimum = WEBRTC_SPL_WORD16_MAX;
     196             : 
     197           0 :   RTC_DCHECK_GT(length, 0);
     198             : 
     199           0 :   for (i = 0; i < length; i++) {
     200           0 :     if (vector[i] < minimum) {
     201           0 :       minimum = vector[i];
     202           0 :       index = i;
     203             :     }
     204             :   }
     205             : 
     206           0 :   return index;
     207             : }
     208             : 
     209             : // Index of minimum value in a word32 vector.
     210           0 : size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
     211           0 :   size_t i = 0, index = 0;
     212           0 :   int32_t minimum = WEBRTC_SPL_WORD32_MAX;
     213             : 
     214           0 :   RTC_DCHECK_GT(length, 0);
     215             : 
     216           0 :   for (i = 0; i < length; i++) {
     217           0 :     if (vector[i] < minimum) {
     218           0 :       minimum = vector[i];
     219           0 :       index = i;
     220             :     }
     221             :   }
     222             : 
     223           0 :   return index;
     224             : }

Generated by: LCOV version 1.13