misc/winutils/include/libavutil/lfg.h
author Wuzzy <Wuzzy2@mail.ru>
Fri, 31 Aug 2018 20:35:13 +0200
changeset 13725 ade61b4eb63f
parent 7813 7ac83d79b897
permissions -rw-r--r--
Don't load locale Lua script if LOCALE == "en"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     1
/*
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     2
 * Lagged Fibonacci PRNG
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     3
 * Copyright (c) 2008 Michael Niedermayer
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     4
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     5
 * This file is part of Libav.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     6
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     7
 * Libav is free software; you can redistribute it and/or
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     8
 * modify it under the terms of the GNU Lesser General Public
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
     9
 * License as published by the Free Software Foundation; either
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    10
 * version 2.1 of the License, or (at your option) any later version.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    11
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    12
 * Libav is distributed in the hope that it will be useful,
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    15
 * Lesser General Public License for more details.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    16
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    17
 * You should have received a copy of the GNU Lesser General Public
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    18
 * License along with Libav; if not, write to the Free Software
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    20
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    21
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    22
#ifndef AVUTIL_LFG_H
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    23
#define AVUTIL_LFG_H
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    24
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    25
typedef struct AVLFG {
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    26
    unsigned int state[64];
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    27
    int index;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    28
} AVLFG;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    29
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    30
void av_lfg_init(AVLFG *c, unsigned int seed);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    31
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    32
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    33
 * Get the next random unsigned 32-bit number using an ALFG.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    34
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    35
 * Please also consider a simple LCG like state= state*1664525+1013904223,
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    36
 * it may be good enough and faster for your specific use case.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    37
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    38
static inline unsigned int av_lfg_get(AVLFG *c){
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    39
    c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    40
    return c->state[c->index++ & 63];
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    41
}
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    42
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    43
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    44
 * Get the next random unsigned 32-bit number using a MLFG.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    45
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    46
 * Please also consider av_lfg_get() above, it is faster.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    47
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    48
static inline unsigned int av_mlfg_get(AVLFG *c){
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    49
    unsigned int a= c->state[(c->index-55) & 63];
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    50
    unsigned int b= c->state[(c->index-24) & 63];
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    51
    return c->state[c->index++ & 63] = 2*a*b+a+b;
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    52
}
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    53
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    54
/**
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    55
 * Get the next two numbers generated by a Box-Muller Gaussian
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    56
 * generator using the random numbers issued by lfg.
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    57
 *
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    58
 * @param out array where the two generated numbers are placed
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    59
 */
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    60
void av_bmg_get(AVLFG *lfg, double out[2]);
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    61
7ac83d79b897 support video recording on windows with automation and headers
koda
parents:
diff changeset
    62
#endif /* AVUTIL_LFG_H */