LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/common_audio/signal_processing - complex_bit_reverse.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 30 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 1 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             : #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
      12             : 
      13             : /* Tables for data buffer indexes that are bit reversed and thus need to be
      14             :  * swapped. Note that, index_7[{0, 2, 4, ...}] are for the left side of the swap
      15             :  * operations, while index_7[{1, 3, 5, ...}] are for the right side of the
      16             :  * operation. Same for index_8.
      17             :  */
      18             : 
      19             : /* Indexes for the case of stages == 7. */
      20             : static const int16_t index_7[112] = {
      21             :   1, 64, 2, 32, 3, 96, 4, 16, 5, 80, 6, 48, 7, 112, 9, 72, 10, 40, 11, 104,
      22             :   12, 24, 13, 88, 14, 56, 15, 120, 17, 68, 18, 36, 19, 100, 21, 84, 22, 52,
      23             :   23, 116, 25, 76, 26, 44, 27, 108, 29, 92, 30, 60, 31, 124, 33, 66, 35, 98,
      24             :   37, 82, 38, 50, 39, 114, 41, 74, 43, 106, 45, 90, 46, 58, 47, 122, 49, 70,
      25             :   51, 102, 53, 86, 55, 118, 57, 78, 59, 110, 61, 94, 63, 126, 67, 97, 69,
      26             :   81, 71, 113, 75, 105, 77, 89, 79, 121, 83, 101, 87, 117, 91, 109, 95, 125,
      27             :   103, 115, 111, 123
      28             : };
      29             : 
      30             : /* Indexes for the case of stages == 8. */
      31             : static const int16_t index_8[240] = {
      32             :   1, 128, 2, 64, 3, 192, 4, 32, 5, 160, 6, 96, 7, 224, 8, 16, 9, 144, 10, 80,
      33             :   11, 208, 12, 48, 13, 176, 14, 112, 15, 240, 17, 136, 18, 72, 19, 200, 20,
      34             :   40, 21, 168, 22, 104, 23, 232, 25, 152, 26, 88, 27, 216, 28, 56, 29, 184,
      35             :   30, 120, 31, 248, 33, 132, 34, 68, 35, 196, 37, 164, 38, 100, 39, 228, 41,
      36             :   148, 42, 84, 43, 212, 44, 52, 45, 180, 46, 116, 47, 244, 49, 140, 50, 76,
      37             :   51, 204, 53, 172, 54, 108, 55, 236, 57, 156, 58, 92, 59, 220, 61, 188, 62,
      38             :   124, 63, 252, 65, 130, 67, 194, 69, 162, 70, 98, 71, 226, 73, 146, 74, 82,
      39             :   75, 210, 77, 178, 78, 114, 79, 242, 81, 138, 83, 202, 85, 170, 86, 106, 87,
      40             :   234, 89, 154, 91, 218, 93, 186, 94, 122, 95, 250, 97, 134, 99, 198, 101,
      41             :   166, 103, 230, 105, 150, 107, 214, 109, 182, 110, 118, 111, 246, 113, 142,
      42             :   115, 206, 117, 174, 119, 238, 121, 158, 123, 222, 125, 190, 127, 254, 131,
      43             :   193, 133, 161, 135, 225, 137, 145, 139, 209, 141, 177, 143, 241, 147, 201,
      44             :   149, 169, 151, 233, 155, 217, 157, 185, 159, 249, 163, 197, 167, 229, 171,
      45             :   213, 173, 181, 175, 245, 179, 205, 183, 237, 187, 221, 191, 253, 199, 227,
      46             :   203, 211, 207, 243, 215, 235, 223, 251, 239, 247
      47             : };
      48             : 
      49           0 : void WebRtcSpl_ComplexBitReverse(int16_t* __restrict complex_data, int stages) {
      50             :   /* For any specific value of stages, we know exactly the indexes that are
      51             :    * bit reversed. Currently (Feb. 2012) in WebRTC the only possible values of
      52             :    * stages are 7 and 8, so we use tables to save unnecessary iterations and
      53             :    * calculations for these two cases.
      54             :    */
      55           0 :   if (stages == 7 || stages == 8) {
      56           0 :     int m = 0;
      57           0 :     int length = 112;
      58           0 :     const int16_t* index = index_7;
      59             : 
      60           0 :     if (stages == 8) {
      61           0 :       length = 240;
      62           0 :       index = index_8;
      63             :     }
      64             : 
      65             :     /* Decimation in time. Swap the elements with bit-reversed indexes. */
      66           0 :     for (m = 0; m < length; m += 2) {
      67             :       /* We declare a int32_t* type pointer, to load both the 16-bit real
      68             :        * and imaginary elements from complex_data in one instruction, reducing
      69             :        * complexity.
      70             :        */
      71           0 :       int32_t* complex_data_ptr = (int32_t*)complex_data;
      72           0 :       int32_t temp = 0;
      73             : 
      74           0 :       temp = complex_data_ptr[index[m]];  /* Real and imaginary */
      75           0 :       complex_data_ptr[index[m]] = complex_data_ptr[index[m + 1]];
      76           0 :       complex_data_ptr[index[m + 1]] = temp;
      77             :     }
      78             :   }
      79             :   else {
      80           0 :     int m = 0, mr = 0, l = 0;
      81           0 :     int n = 1 << stages;
      82           0 :     int nn = n - 1;
      83             : 
      84             :     /* Decimation in time - re-order data */
      85           0 :     for (m = 1; m <= nn; ++m) {
      86           0 :       int32_t* complex_data_ptr = (int32_t*)complex_data;
      87           0 :       int32_t temp = 0;
      88             : 
      89             :       /* Find out indexes that are bit-reversed. */
      90           0 :       l = n;
      91             :       do {
      92           0 :         l >>= 1;
      93           0 :       } while (l > nn - mr);
      94           0 :       mr = (mr & (l - 1)) + l;
      95             : 
      96           0 :       if (mr <= m) {
      97           0 :         continue;
      98             :       }
      99             : 
     100             :       /* Swap the elements with bit-reversed indexes.
     101             :        * This is similar to the loop in the stages == 7 or 8 cases.
     102             :        */
     103           0 :       temp = complex_data_ptr[m];  /* Real and imaginary */
     104           0 :       complex_data_ptr[m] = complex_data_ptr[mr];
     105           0 :       complex_data_ptr[mr] = temp;
     106             :     }
     107             :   }
     108           0 : }

Generated by: LCOV version 1.13