1*600f14f4SXin Li /* libFLAC - Free Lossless Audio Codec library 2*600f14f4SXin Li * Copyright (C) 2004-2009 Josh Coalson 3*600f14f4SXin Li * Copyright (C) 2011-2023 Xiph.Org Foundation 4*600f14f4SXin Li * 5*600f14f4SXin Li * Redistribution and use in source and binary forms, with or without 6*600f14f4SXin Li * modification, are permitted provided that the following conditions 7*600f14f4SXin Li * are met: 8*600f14f4SXin Li * 9*600f14f4SXin Li * - Redistributions of source code must retain the above copyright 10*600f14f4SXin Li * notice, this list of conditions and the following disclaimer. 11*600f14f4SXin Li * 12*600f14f4SXin Li * - Redistributions in binary form must reproduce the above copyright 13*600f14f4SXin Li * notice, this list of conditions and the following disclaimer in the 14*600f14f4SXin Li * documentation and/or other materials provided with the distribution. 15*600f14f4SXin Li * 16*600f14f4SXin Li * - Neither the name of the Xiph.org Foundation nor the names of its 17*600f14f4SXin Li * contributors may be used to endorse or promote products derived from 18*600f14f4SXin Li * this software without specific prior written permission. 19*600f14f4SXin Li * 20*600f14f4SXin Li * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21*600f14f4SXin Li * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*600f14f4SXin Li * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23*600f14f4SXin Li * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 24*600f14f4SXin Li * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25*600f14f4SXin Li * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26*600f14f4SXin Li * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27*600f14f4SXin Li * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28*600f14f4SXin Li * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29*600f14f4SXin Li * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30*600f14f4SXin Li * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*600f14f4SXin Li */ 32*600f14f4SXin Li 33*600f14f4SXin Li #ifndef FLAC__PRIVATE__FLOAT_H 34*600f14f4SXin Li #define FLAC__PRIVATE__FLOAT_H 35*600f14f4SXin Li 36*600f14f4SXin Li #ifdef HAVE_CONFIG_H 37*600f14f4SXin Li #include <config.h> 38*600f14f4SXin Li #endif 39*600f14f4SXin Li 40*600f14f4SXin Li #include "FLAC/ordinals.h" 41*600f14f4SXin Li 42*600f14f4SXin Li /* 43*600f14f4SXin Li * All the code in libFLAC that uses float and double 44*600f14f4SXin Li * should be protected by checks of the macro 45*600f14f4SXin Li * FLAC__INTEGER_ONLY_LIBRARY. 46*600f14f4SXin Li * 47*600f14f4SXin Li */ 48*600f14f4SXin Li #ifndef FLAC__INTEGER_ONLY_LIBRARY 49*600f14f4SXin Li /* 50*600f14f4SXin Li * FLAC__real is the basic floating point type used in LPC analysis. 51*600f14f4SXin Li * 52*600f14f4SXin Li * WATCHOUT: changing FLAC__real will change the signatures of many 53*600f14f4SXin Li * functions that have assembly language equivalents and break them. 54*600f14f4SXin Li */ 55*600f14f4SXin Li typedef float FLAC__real; 56*600f14f4SXin Li #else 57*600f14f4SXin Li /* 58*600f14f4SXin Li * The convention for FLAC__fixedpoint is to use the upper 16 bits 59*600f14f4SXin Li * for the integer part and lower 16 bits for the fractional part. 60*600f14f4SXin Li */ 61*600f14f4SXin Li typedef FLAC__int32 FLAC__fixedpoint; 62*600f14f4SXin Li extern const FLAC__fixedpoint FLAC__FP_ZERO; 63*600f14f4SXin Li extern const FLAC__fixedpoint FLAC__FP_ONE_HALF; 64*600f14f4SXin Li extern const FLAC__fixedpoint FLAC__FP_ONE; 65*600f14f4SXin Li extern const FLAC__fixedpoint FLAC__FP_LN2; 66*600f14f4SXin Li extern const FLAC__fixedpoint FLAC__FP_E; 67*600f14f4SXin Li 68*600f14f4SXin Li #define FLAC__fixedpoint_trunc(x) ((x)>>16) 69*600f14f4SXin Li 70*600f14f4SXin Li #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) ) 71*600f14f4SXin Li 72*600f14f4SXin Li #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) ) 73*600f14f4SXin Li 74*600f14f4SXin Li /* 75*600f14f4SXin Li * FLAC__fixedpoint_log2() 76*600f14f4SXin Li * -------------------------------------------------------------------- 77*600f14f4SXin Li * Returns the base-2 logarithm of the fixed-point number 'x' using an 78*600f14f4SXin Li * algorithm by Knuth for x >= 1.0 79*600f14f4SXin Li * 80*600f14f4SXin Li * 'fracbits' is the number of fractional bits of 'x'. 'fracbits' must 81*600f14f4SXin Li * be < 32 and evenly divisible by 4 (0 is OK but not very precise). 82*600f14f4SXin Li * 83*600f14f4SXin Li * 'precision' roughly limits the number of iterations that are done; 84*600f14f4SXin Li * use (uint32_t)(-1) for maximum precision. 85*600f14f4SXin Li * 86*600f14f4SXin Li * If 'x' is less than one -- that is, x < (1<<fracbits) -- then this 87*600f14f4SXin Li * function will punt and return 0. 88*600f14f4SXin Li * 89*600f14f4SXin Li * The return value will also have 'fracbits' fractional bits. 90*600f14f4SXin Li */ 91*600f14f4SXin Li FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, uint32_t fracbits, uint32_t precision); 92*600f14f4SXin Li 93*600f14f4SXin Li #endif 94*600f14f4SXin Li 95*600f14f4SXin Li #endif 96