1818 * If not, see <http://www.gnu.org/licenses/>.
1919 */
2020
21- var CCEElement = ( function ( ) {
22-
23- // Channel Coupling Element
24- function CCEElement ( config ) {
25- this . ics = new ICStream ( config ) ;
26- this . channelPair = new Array ( 8 ) ;
27- this . idSelect = new Int32Array ( 8 ) ;
28- this . chSelect = new Int32Array ( 8 ) ;
29- this . gain = new Array ( 16 ) ;
30- }
31-
32- CCEElement . BEFORE_TNS = 0 ;
33- CCEElement . AFTER_TNS = 1 ;
34- CCEElement . AFTER_IMDCT = 2 ;
35-
36- const CCE_SCALE = new Float32Array ( [
37- 1.09050773266525765921 ,
38- 1.18920711500272106672 ,
39- 1.4142135623730950488016887 ,
40- 2.0
41- ] ) ;
42-
43- CCEElement . prototype = {
44- decode : function ( stream , config ) {
45- var channelPair = this . channelPair ,
46- idSelect = this . idSelect ,
47- chSelect = this . chSelect ;
48-
49- this . couplingPoint = 2 * stream . read ( 1 ) ;
50- this . coupledCount = stream . read ( 3 ) ;
51-
52- var gainCount = 0 ;
53- for ( var i = 0 ; i <= this . coupledCount ; i ++ ) {
54- gainCount ++ ;
55- channelPair [ i ] = stream . read ( 1 ) ;
56- idSelect [ i ] = stream . read ( 4 ) ;
57-
58- if ( channelPair [ i ] ) {
59- chSelect [ i ] = stream . read ( 2 ) ;
60- if ( chSelect [ i ] === 3 )
61- gainCount ++ ;
62-
63- } else {
64- chSelect [ i ] = 2 ;
65- }
21+ var ICStream = require ( './ics' ) ;
22+ var Huffman = require ( './huffman' ) ;
23+
24+ // Channel Coupling Element
25+ function CCEElement ( config ) {
26+ this . ics = new ICStream ( config ) ;
27+ this . channelPair = new Array ( 8 ) ;
28+ this . idSelect = new Int32Array ( 8 ) ;
29+ this . chSelect = new Int32Array ( 8 ) ;
30+ this . gain = new Array ( 16 ) ;
31+ }
32+
33+ CCEElement . BEFORE_TNS = 0 ;
34+ CCEElement . AFTER_TNS = 1 ;
35+ CCEElement . AFTER_IMDCT = 2 ;
36+
37+ const CCE_SCALE = new Float32Array ( [
38+ 1.09050773266525765921 ,
39+ 1.18920711500272106672 ,
40+ 1.4142135623730950488016887 ,
41+ 2.0
42+ ] ) ;
43+
44+ CCEElement . prototype = {
45+ decode : function ( stream , config ) {
46+ var channelPair = this . channelPair ,
47+ idSelect = this . idSelect ,
48+ chSelect = this . chSelect ;
49+
50+ this . couplingPoint = 2 * stream . read ( 1 ) ;
51+ this . coupledCount = stream . read ( 3 ) ;
52+
53+ var gainCount = 0 ;
54+ for ( var i = 0 ; i <= this . coupledCount ; i ++ ) {
55+ gainCount ++ ;
56+ channelPair [ i ] = stream . read ( 1 ) ;
57+ idSelect [ i ] = stream . read ( 4 ) ;
58+
59+ if ( channelPair [ i ] ) {
60+ chSelect [ i ] = stream . read ( 2 ) ;
61+ if ( chSelect [ i ] === 3 )
62+ gainCount ++ ;
63+
64+ } else {
65+ chSelect [ i ] = 2 ;
6666 }
67-
68- this . couplingPoint += stream . read ( 1 ) ;
69- this . couplingPoint |= ( this . couplingPoint >>> 1 ) ;
70-
71- var sign = stream . read ( 1 ) ,
72- scale = CCE_SCALE [ stream . read ( 2 ) ] ;
73-
74- this . ics . decode ( stream , config , false ) ;
75-
76- var groupCount = this . ics . info . groupCount ,
77- maxSFB = this . ics . info . maxSFB ,
78- bandTypes = this . ics . bandTypes ;
79-
80- for ( var i = 0 ; i < gainCount ; i ++ ) {
81- var idx = 0 ,
82- cge = 1 ,
83- gain = 0 ,
84- gainCache = 1 ;
85-
86- if ( i > 0 ) {
87- cge = this . couplingPoint === CCEElement . AFTER_IMDCT ? 1 : stream . read ( 1 ) ;
88- gain = cge ? Huffman . decodeScaleFactor ( stream ) - 60 : 0 ;
89- gainCache = Math . pow ( scale , - gain ) ;
90- }
91-
92- var gain_i = this . gain [ i ] = new Float32Array ( 120 ) ;
93-
94- if ( this . couplingPoint === CCEElement . AFTER_IMDCT ) {
95- gain_i [ 0 ] = gainCache ;
96- } else {
97- for ( var g = 0 ; g < groupCount ; g ++ ) {
98- for ( var sfb = 0 ; sfb < maxSFB ; sfb ++ ) {
99- if ( bandTypes [ idx ] !== ICStream . ZERO_BT ) {
100- if ( cge === 0 ) {
101- var t = Huffman . decodeScaleFactor ( stream ) - 60 ;
102- if ( t !== 0 ) {
103- var s = 1 ;
104- t = gain += t ;
105- if ( sign ) {
106- s -= 2 * ( t * 0x1 ) ;
107- t >>>= 1 ;
108- }
109- gainCache = Math . pow ( scale , - t ) * s ;
67+ }
68+
69+ this . couplingPoint += stream . read ( 1 ) ;
70+ this . couplingPoint |= ( this . couplingPoint >>> 1 ) ;
71+
72+ var sign = stream . read ( 1 ) ,
73+ scale = CCE_SCALE [ stream . read ( 2 ) ] ;
74+
75+ this . ics . decode ( stream , config , false ) ;
76+
77+ var groupCount = this . ics . info . groupCount ,
78+ maxSFB = this . ics . info . maxSFB ,
79+ bandTypes = this . ics . bandTypes ;
80+
81+ for ( var i = 0 ; i < gainCount ; i ++ ) {
82+ var idx = 0 ,
83+ cge = 1 ,
84+ gain = 0 ,
85+ gainCache = 1 ;
86+
87+ if ( i > 0 ) {
88+ cge = this . couplingPoint === CCEElement . AFTER_IMDCT ? 1 : stream . read ( 1 ) ;
89+ gain = cge ? Huffman . decodeScaleFactor ( stream ) - 60 : 0 ;
90+ gainCache = Math . pow ( scale , - gain ) ;
91+ }
92+
93+ var gain_i = this . gain [ i ] = new Float32Array ( 120 ) ;
94+
95+ if ( this . couplingPoint === CCEElement . AFTER_IMDCT ) {
96+ gain_i [ 0 ] = gainCache ;
97+ } else {
98+ for ( var g = 0 ; g < groupCount ; g ++ ) {
99+ for ( var sfb = 0 ; sfb < maxSFB ; sfb ++ ) {
100+ if ( bandTypes [ idx ] !== ICStream . ZERO_BT ) {
101+ if ( cge === 0 ) {
102+ var t = Huffman . decodeScaleFactor ( stream ) - 60 ;
103+ if ( t !== 0 ) {
104+ var s = 1 ;
105+ t = gain += t ;
106+ if ( sign ) {
107+ s -= 2 * ( t * 0x1 ) ;
108+ t >>>= 1 ;
110109 }
110+ gainCache = Math . pow ( scale , - t ) * s ;
111111 }
112- gain_i [ idx ++ ] = gainCache ;
113112 }
113+ gain_i [ idx ++ ] = gainCache ;
114114 }
115115 }
116116 }
117117 }
118- } ,
119-
120- applyIndependentCoupling : function ( index , data ) {
121- var gain = this . gain [ index ] [ 0 ] ,
122- iqData = this . ics . data ;
123-
124- for ( var i = 0 ; i < data . length ; i ++ ) {
125- data [ i ] += gain * iqData [ i ] ;
126- }
127- } ,
128-
129- applyDependentCoupling : function ( index , data ) {
130- var info = this . ics . info ,
131- swbOffsets = info . swbOffsets ,
132- groupCount = info . groupCount ,
133- maxSFB = info . maxSFB ,
134- bandTypes = this . ics . bandTypes ,
135- iqData = this . ics . data ;
136-
137- var idx = 0 ,
138- offset = 0 ,
139- gains = this . gain [ index ] ;
140-
141- for ( var g = 0 ; g < groupCount ; g ++ ) {
142- var len = info . groupLength [ g ] ;
143-
144- for ( var sfb = 0 ; sfb < maxSFB ; sfb ++ , idx ++ ) {
145- if ( bandTypes [ idx ] !== ICStream . ZERO_BT ) {
146- var gain = gains [ idx ] ;
147- for ( var group = 0 ; group < len ; group ++ ) {
148- for ( var k = swbOffsets [ sfb ] ; k < swbOffsets [ swb + 1 ] ; k ++ ) {
149- data [ offset + group * 128 + k ] += gain * iqData [ offset + group * 128 + k ] ;
150- }
118+ }
119+ } ,
120+
121+ applyIndependentCoupling : function ( index , data ) {
122+ var gain = this . gain [ index ] [ 0 ] ,
123+ iqData = this . ics . data ;
124+
125+ for ( var i = 0 ; i < data . length ; i ++ ) {
126+ data [ i ] += gain * iqData [ i ] ;
127+ }
128+ } ,
129+
130+ applyDependentCoupling : function ( index , data ) {
131+ var info = this . ics . info ,
132+ swbOffsets = info . swbOffsets ,
133+ groupCount = info . groupCount ,
134+ maxSFB = info . maxSFB ,
135+ bandTypes = this . ics . bandTypes ,
136+ iqData = this . ics . data ;
137+
138+ var idx = 0 ,
139+ offset = 0 ,
140+ gains = this . gain [ index ] ;
141+
142+ for ( var g = 0 ; g < groupCount ; g ++ ) {
143+ var len = info . groupLength [ g ] ;
144+
145+ for ( var sfb = 0 ; sfb < maxSFB ; sfb ++ , idx ++ ) {
146+ if ( bandTypes [ idx ] !== ICStream . ZERO_BT ) {
147+ var gain = gains [ idx ] ;
148+ for ( var group = 0 ; group < len ; group ++ ) {
149+ for ( var k = swbOffsets [ sfb ] ; k < swbOffsets [ swb + 1 ] ; k ++ ) {
150+ data [ offset + group * 128 + k ] += gain * iqData [ offset + group * 128 + k ] ;
151151 }
152152 }
153153 }
154-
155- offset += len * 128 ;
156154 }
155+
156+ offset += len * 128 ;
157157 }
158- } ;
159-
160- return CCEElement ;
161-
162- } ) ( ) ;
158+ }
159+ } ;
160+
161+ module . exports = CCEElement ;
0 commit comments