Home | History | Annotate | Download | only in source
      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 /*
     13  * This file contains implementations of the randomization functions
     14  * WebRtcSpl_IncreaseSeed()
     15  * WebRtcSpl_RandU()
     16  * WebRtcSpl_RandN()
     17  * WebRtcSpl_RandUArray()
     18  *
     19  * The description header can be found in signal_processing_library.h
     20  *
     21  */
     22 
     23 #include "signal_processing_library.h"
     24 
     25 WebRtc_UWord32 WebRtcSpl_IncreaseSeed(WebRtc_UWord32 *seed)
     26 {
     27     seed[0] = (seed[0] * ((WebRtc_Word32)69069) + 1) & (WEBRTC_SPL_MAX_SEED_USED - 1);
     28     return seed[0];
     29 }
     30 
     31 WebRtc_Word16 WebRtcSpl_RandU(WebRtc_UWord32 *seed)
     32 {
     33     return (WebRtc_Word16)(WebRtcSpl_IncreaseSeed(seed) >> 16);
     34 }
     35 
     36 WebRtc_Word16 WebRtcSpl_RandN(WebRtc_UWord32 *seed)
     37 {
     38     return WebRtcSpl_kRandNTable[WebRtcSpl_IncreaseSeed(seed) >> 23];
     39 }
     40 
     41 // Creates an array of uniformly distributed variables
     42 WebRtc_Word16 WebRtcSpl_RandUArray(WebRtc_Word16* vector,
     43                                    WebRtc_Word16 vector_length,
     44                                    WebRtc_UWord32* seed)
     45 {
     46     int i;
     47     for (i = 0; i < vector_length; i++)
     48     {
     49         vector[i] = WebRtcSpl_RandU(seed);
     50     }
     51     return vector_length;
     52 }
     53