summaryrefslogtreecommitdiffstats
path: root/libAACenc/src/bit_cnt.h
blob: 6baf7dff0de02a22915eaed4a8b284473664d67d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/******************************** MPEG Audio Encoder **************************

                     (C) Copyright Fraunhofer IIS (1999)
                               All Rights Reserved

    Please be advised that this software and/or program delivery is
    Confidential Information of Fraunhofer and subject to and covered by the

    Fraunhofer IIS Software Evaluation Agreement
    between Google Inc. and  Fraunhofer
    effective and in full force since March 1, 2012.

    You may use this software and/or program only under the terms and
    conditions described in the above mentioned Fraunhofer IIS Software
    Evaluation Agreement. Any other and/or further use requires a separate agreement.


   This software and/or program is protected by copyright law and international
   treaties. Any reproduction or distribution of this software and/or program,
   or any portion of it, may result in severe civil and criminal penalties, and
   will be prosecuted to the maximum extent possible under law.

   $Id$
   Initial author:       M.Werner
   contents/description: Huffman Bitcounter & coder

******************************************************************************/
#ifndef __BITCOUNT_H
#define __BITCOUNT_H


#include "common_fix.h"
#include "FDK_bitstream.h"
#include "aacEnc_rom.h"

#define INVALID_BITCOUNT (FDK_INT_MAX/4)

/*
  code book number table
*/

enum codeBookNo{
 CODE_BOOK_ZERO_NO=               0,
 CODE_BOOK_1_NO=                  1,
 CODE_BOOK_2_NO=                  2,
 CODE_BOOK_3_NO=                  3,
 CODE_BOOK_4_NO=                  4,
 CODE_BOOK_5_NO=                  5,
 CODE_BOOK_6_NO=                  6,
 CODE_BOOK_7_NO=                  7,
 CODE_BOOK_8_NO=                  8,
 CODE_BOOK_9_NO=                  9,
 CODE_BOOK_10_NO=                10,
 CODE_BOOK_ESC_NO=               11,
 CODE_BOOK_RES_NO=               12,
 CODE_BOOK_PNS_NO=               13,
 CODE_BOOK_IS_OUT_OF_PHASE_NO=   14,
 CODE_BOOK_IS_IN_PHASE_NO=       15

};

/*
  code book index table
*/

enum codeBookNdx{
 CODE_BOOK_ZERO_NDX,
 CODE_BOOK_1_NDX,
 CODE_BOOK_2_NDX,
 CODE_BOOK_3_NDX,
 CODE_BOOK_4_NDX,
 CODE_BOOK_5_NDX,
 CODE_BOOK_6_NDX,
 CODE_BOOK_7_NDX,
 CODE_BOOK_8_NDX,
 CODE_BOOK_9_NDX,
 CODE_BOOK_10_NDX,
 CODE_BOOK_ESC_NDX,
 CODE_BOOK_RES_NDX,
 CODE_BOOK_PNS_NDX,
 CODE_BOOK_IS_OUT_OF_PHASE_NDX,
 CODE_BOOK_IS_IN_PHASE_NDX,
 NUMBER_OF_CODE_BOOKS
};

/*
  code book lav table
*/

enum codeBookLav{
 CODE_BOOK_ZERO_LAV=0,
 CODE_BOOK_1_LAV=1,
 CODE_BOOK_2_LAV=1,
 CODE_BOOK_3_LAV=2,
 CODE_BOOK_4_LAV=2,
 CODE_BOOK_5_LAV=4,
 CODE_BOOK_6_LAV=4,
 CODE_BOOK_7_LAV=7,
 CODE_BOOK_8_LAV=7,
 CODE_BOOK_9_LAV=12,
 CODE_BOOK_10_LAV=12,
 CODE_BOOK_ESC_LAV=16,
 CODE_BOOK_SCF_LAV=60,
 CODE_BOOK_PNS_LAV=60
 };

INT    FDKaacEnc_bitCount(const SHORT *aQuantSpectrum,
                          const INT   noOfSpecLines,
                          INT         maxVal,
                          INT        *bitCountLut);

INT    FDKaacEnc_countValues(SHORT *values, INT width, INT codeBook);

INT    FDKaacEnc_codeValues(SHORT *values, INT width, INT codeBook, HANDLE_FDK_BITSTREAM hBitstream);

INT    FDKaacEnc_codeScalefactorDelta(INT scalefactor, HANDLE_FDK_BITSTREAM hBitstream);

inline INT FDKaacEnc_bitCountScalefactorDelta(const INT delta)
{
  FDK_ASSERT( (0 <= (delta+CODE_BOOK_SCF_LAV)) &&  ((delta+CODE_BOOK_SCF_LAV)<(int)(sizeof(FDKaacEnc_huff_ltabscf)/sizeof((FDKaacEnc_huff_ltabscf[0])))) );
  return((INT)FDKaacEnc_huff_ltabscf[delta+CODE_BOOK_SCF_LAV]);
}

#endif