flac_private_float.h 3.7 KB

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