cannam@154: /* Copyright (c) 2011 Xiph.Org Foundation cannam@154: Written by Gregory Maxwell */ cannam@154: /* cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: cannam@154: - Redistributions of source code must retain the above copyright cannam@154: notice, this list of conditions and the following disclaimer. cannam@154: cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@154: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@154: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@154: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER cannam@154: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@154: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@154: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@154: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@154: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@154: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@154: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@154: */ cannam@154: cannam@154: static OPUS_INLINE void deb2_impl(unsigned char *_t,unsigned char **_p,int _k,int _x,int _y) cannam@154: { cannam@154: int i; cannam@154: if(_x>2){ cannam@154: if(_y<3)for(i=0;i<_y;i++)*(--*_p)=_t[i+1]; cannam@154: }else{ cannam@154: _t[_x]=_t[_x-_y]; cannam@154: deb2_impl(_t,_p,_k,_x+1,_y); cannam@154: for(i=_t[_x-_y]+1;i<_k;i++){ cannam@154: _t[_x]=i; cannam@154: deb2_impl(_t,_p,_k,_x+1,_x); cannam@154: } cannam@154: } cannam@154: } cannam@154: cannam@154: /*Generates a De Bruijn sequence (k,2) with length k^2*/ cannam@154: static OPUS_INLINE void debruijn2(int _k, unsigned char *_res) cannam@154: { cannam@154: unsigned char *p; cannam@154: unsigned char *t; cannam@154: t=malloc(sizeof(unsigned char)*_k*2); cannam@154: memset(t,0,sizeof(unsigned char)*_k*2); cannam@154: p=&_res[_k*_k]; cannam@154: deb2_impl(t,&p,_k,1,1); cannam@154: free(t); cannam@154: } cannam@154: cannam@154: /*MWC RNG of George Marsaglia*/ cannam@154: static opus_uint32 Rz, Rw; cannam@154: static OPUS_INLINE opus_uint32 fast_rand(void) cannam@154: { cannam@154: Rz=36969*(Rz&65535)+(Rz>>16); cannam@154: Rw=18000*(Rw&65535)+(Rw>>16); cannam@154: return (Rz<<16)+Rw; cannam@154: } cannam@154: static opus_uint32 iseed; cannam@154: cannam@154: #ifdef __GNUC__ cannam@154: __attribute__((noreturn)) cannam@154: #elif defined(_MSC_VER) cannam@154: __declspec(noreturn) cannam@154: #endif cannam@154: static OPUS_INLINE void _test_failed(const char *file, int line) cannam@154: { cannam@154: fprintf(stderr,"\n ***************************************************\n"); cannam@154: fprintf(stderr," *** A fatal error was detected. ***\n"); cannam@154: fprintf(stderr," ***************************************************\n"); cannam@154: fprintf(stderr,"Please report this failure and include\n"); cannam@154: fprintf(stderr,"'make check SEED=%u fails %s at line %d for %s'\n",iseed,file,line,opus_get_version_string()); cannam@154: fprintf(stderr,"and any relevant details about your system.\n\n"); cannam@154: abort(); cannam@154: } cannam@154: #define test_failed() _test_failed(__FILE__, __LINE__); cannam@154: cannam@154: void regression_test(void);