annotate lib/libavutil/lfg.h @ 2406:33659ef7fbac

Слияние
author Ritor1
date Fri, 04 Jul 2014 23:18:36 +0600
parents 992d2e6f907d
children
rev   line source
2134
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
1 /*
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
2 * Lagged Fibonacci PRNG
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
3 * Copyright (c) 2008 Michael Niedermayer
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
4 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
5 * This file is part of FFmpeg.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
6 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
11 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
15 * Lesser General Public License for more details.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
16 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
20 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
21
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
22 #ifndef AVUTIL_LFG_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
23 #define AVUTIL_LFG_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
24
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
25 typedef struct AVLFG {
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
26 unsigned int state[64];
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
27 int index;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
28 } AVLFG;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
29
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
30 void av_lfg_init(AVLFG *c, unsigned int seed);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
31
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
32 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
33 * Get the next random unsigned 32-bit number using an ALFG.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
34 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
35 * Please also consider a simple LCG like state= state*1664525+1013904223,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
36 * it may be good enough and faster for your specific use case.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
37 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
38 static inline unsigned int av_lfg_get(AVLFG *c){
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
39 c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
40 return c->state[c->index++ & 63];
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
41 }
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
42
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
43 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
44 * Get the next random unsigned 32-bit number using a MLFG.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
45 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
46 * Please also consider av_lfg_get() above, it is faster.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
47 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
48 static inline unsigned int av_mlfg_get(AVLFG *c){
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
49 unsigned int a= c->state[(c->index-55) & 63];
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
50 unsigned int b= c->state[(c->index-24) & 63];
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
51 return c->state[c->index++ & 63] = 2*a*b+a+b;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
52 }
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
53
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
54 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
55 * Get the next two numbers generated by a Box-Muller Gaussian
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
56 * generator using the random numbers issued by lfg.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
57 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
58 * @param out array where the two generated numbers are placed
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
59 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
60 void av_bmg_get(AVLFG *lfg, double out[2]);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
61
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
62 #endif /* AVUTIL_LFG_H */