entdec.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2001-2011 Timothy B. Terriberry
  2. Copyright (c) 2008-2009 Xiph.Org Foundation */
  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. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #if !defined(_entdec_H)
  25. # define _entdec_H (1)
  26. # include <limits.h>
  27. # include "entcode.h"
  28. /*Initializes the decoder.
  29. _buf: The input buffer to use.
  30. Return: 0 on success, or a negative value on error.*/
  31. void ec_dec_init(ec_dec *_this,unsigned char *_buf,opus_uint32 _storage);
  32. /*Calculates the cumulative frequency for the next symbol.
  33. This can then be fed into the probability model to determine what that
  34. symbol is, and the additional frequency information required to advance to
  35. the next symbol.
  36. This function cannot be called more than once without a corresponding call to
  37. ec_dec_update(), or decoding will not proceed correctly.
  38. _ft: The total frequency of the symbols in the alphabet the next symbol was
  39. encoded with.
  40. Return: A cumulative frequency representing the encoded symbol.
  41. If the cumulative frequency of all the symbols before the one that
  42. was encoded was fl, and the cumulative frequency of all the symbols
  43. up to and including the one encoded is fh, then the returned value
  44. will fall in the range [fl,fh).*/
  45. unsigned ec_decode(ec_dec *_this,unsigned _ft);
  46. /*Equivalent to ec_decode() with _ft==1<<_bits.*/
  47. unsigned ec_decode_bin(ec_dec *_this,unsigned _bits);
  48. /*Advance the decoder past the next symbol using the frequency information the
  49. symbol was encoded with.
  50. Exactly one call to ec_decode() must have been made so that all necessary
  51. intermediate calculations are performed.
  52. _fl: The cumulative frequency of all symbols that come before the symbol
  53. decoded.
  54. _fh: The cumulative frequency of all symbols up to and including the symbol
  55. decoded.
  56. Together with _fl, this defines the range [_fl,_fh) in which the value
  57. returned above must fall.
  58. _ft: The total frequency of the symbols in the alphabet the symbol decoded
  59. was encoded in.
  60. This must be the same as passed to the preceding call to ec_decode().*/
  61. void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft);
  62. /* Decode a bit that has a 1/(1<<_logp) probability of being a one */
  63. int ec_dec_bit_logp(ec_dec *_this,unsigned _logp);
  64. /*Decodes a symbol given an "inverse" CDF table.
  65. No call to ec_dec_update() is necessary after this call.
  66. _icdf: The "inverse" CDF, such that symbol s falls in the range
  67. [s>0?ft-_icdf[s-1]:0,ft-_icdf[s]), where ft=1<<_ftb.
  68. The values must be monotonically non-increasing, and the last value
  69. must be 0.
  70. _ftb: The number of bits of precision in the cumulative distribution.
  71. Return: The decoded symbol s.*/
  72. int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb);
  73. /*Extracts a raw unsigned integer with a non-power-of-2 range from the stream.
  74. The bits must have been encoded with ec_enc_uint().
  75. No call to ec_dec_update() is necessary after this call.
  76. _ft: The number of integers that can be decoded (one more than the max).
  77. This must be at least one, and no more than 2**32-1.
  78. Return: The decoded bits.*/
  79. opus_uint32 ec_dec_uint(ec_dec *_this,opus_uint32 _ft);
  80. /*Extracts a sequence of raw bits from the stream.
  81. The bits must have been encoded with ec_enc_bits().
  82. No call to ec_dec_update() is necessary after this call.
  83. _ftb: The number of bits to extract.
  84. This must be between 0 and 25, inclusive.
  85. Return: The decoded bits.*/
  86. opus_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
  87. #endif