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