• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/lfg.c

Go to the documentation of this file.
00001 /*
00002  * Lagged Fibonacci PRNG
00003  * Copyright (c) 2008 Michael Niedermayer
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include <inttypes.h>
00023 #include "lfg.h"
00024 #include "md5.h"
00025 #include "intreadwrite.h"
00026 
00027 void av_cold av_lfg_init(AVLFG *c, unsigned int seed){
00028     uint8_t tmp[16]={0};
00029     int i;
00030 
00031     for(i=8; i<64; i+=4){
00032         AV_WL32(tmp, seed); tmp[4]=i;
00033         av_md5_sum(tmp, tmp,  16);
00034         c->state[i  ]= AV_RL32(tmp);
00035         c->state[i+1]= AV_RL32(tmp+4);
00036         c->state[i+2]= AV_RL32(tmp+8);
00037         c->state[i+3]= AV_RL32(tmp+12);
00038     }
00039     c->index=0;
00040 }
00041 
00042 #ifdef TEST
00043 #include "log.h"
00044 #include "common.h"
00045 
00046 int main(void)
00047 {
00048     int x=0;
00049     int i, j;
00050     AVLFG state;
00051 
00052     av_lfg_init(&state, 0xdeadbeef);
00053     for (j = 0; j < 10000; j++) {
00054         START_TIMER
00055         for (i = 0; i < 624; i++) {
00056 //            av_log(NULL,AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
00057             x+=av_lfg_get(&state);
00058         }
00059         STOP_TIMER("624 calls of av_random");
00060     }
00061     av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
00062     return 0;
00063 }
00064 #endif

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1