Scale Factors

Stores Scale factors for subbands and subframes.

Member of Audio Frame

The task is to encode up to 96 scale factors for the current frame. These are SCF0 . . . 2 (0 . . . 31) in the following diagram:

previous Frame current Frame
 Subframe 0 Subframe 1 Subframe 2 SCF-3 ( 0) SCF-2 ( 0) SCF-1 ( 0) SCF-3 ( 1) SCF-2 ( 1) SCF-1 ( 1) SCF-3 ( 2) SCF-2 ( 2) SCF-1 ( 2) . . . . . . . . . SCF-3 (29) SCF-2 (29) SCF-1 (29) SCF-3 (30) SCF-2 (30) SCF-1 (30) SCF-3 (31) SCF-2 (31) SCF-1 (31)
 Subframe 0 Subframe 1 Subframe 2 SCF0 ( 0) SCF1 ( 0) SCF2 ( 0) SCF0 ( 1) SCF1 ( 1) SCF2 ( 1) SCF0 ( 2) SCF1 ( 2) SCF2 ( 2) . . . . . . . . . SCF0 (29) SCF1 (29) SCF2 (29) SCF0 (30) SCF1 (30) SCF2 (30) SCF0 (31) SCF1 (31) SCF2 (31)

Only SCF's for subbands which can carry subband samples != 0 due to the allocation field are transmitted.

First step is decode a value via a huffman table. The result with select the prediction strategy:

• 0 . . . 63:
non-stationary frame, for each of the 3 subframes you can choose one of three prediction strategies:
• spectral prediction
• mixed spectral + temporal prediction
• temporal prediction
• temporal prediction + LPC (linear prediction of subband samples)
• 64:
stationary frame, only temporal prediction with prediction corrections of +/- 2 SCF's is possible.
• 65:
stationary frame, only temporal prediction with prediction corrections of +/- 2 SCF's is possible.
Also LPC (linear prediction of subband samples) is possible.

 c = DecodeHuffman (table11) if (c < 64) on (c % 4) Subframe 0 Scalefactors SCF0 () encoded using . . . 0 spectral prediction 1 mixed prediction 2 temporal prediction 3 temporal prediction + LPC on (c / 4 % 4) Subframe 1 Scalefactors SCF1 () encoded using . . . 0 spectral prediction 1 mixed prediction 2 temporal prediction 3 temporal prediction + LPC on (c / 16) Subframe 2 Scalefactors SCF2 () encoded using . . . 0 spectral prediction 1 mixed prediction 2 temporal prediction 3 temporal prediction + LPC if c == 64 for each subband Vector book coded Scalefactors SCF0 . . . 2 () encoded using . . .       temporal prediction if c == 65 for each subband Vector book coded Scalefactors SCF0 . . . 2 () encoded using . . .       temporal prediction + LPC

Stationary Frame:

 0 1 bit for each subband n:         Subband Scalefactors SCF(n) ? bit

Non-stationary Frame:

 1 1 bit Subframe Scalefactors SCF0() ? bit Subframe Scalefactors SCF1() ? bit Subframe Scalefactors SCF2() ? bit

previous Frame current Frame
 Subframe 0 Subframe 1 Subframe 2 SCF-3 ( ) SCF-2 ( ) SCF-1 ( )
 Subframe 0 Subframe 1 Subframe 2 SCF0 ( ) SCF1 ( ) SCF2 ( )

int   code;

code = Decode_Huffman (table1);
if ( code < 125 ) {                                       // 3 differential SCFs using a vector codebook
SCF  [0] [band] = SCF_last [band] + code % 5 - 2;
SCF  [1] [band] = SCF  [0] [band] + code / 5 % 5 - 2;
SCF  [2] [band] = SCF  [1] [band] + code /25 - 2;
SCF_last [band] = SCF  [2] [band];
predict  [band] = false;
}
else if ( code < 134 ) {                                  // 1 differential SCF-block using a vector codebook, prediction
SCF  [0] [band] = SCF_last [band] + code % 5 - 4;
SCF  [1] [band] = SCF  [0] [band];
SCF  [2] [band] = SCF  [1] [band];
SCF_last [band] = SCF  [2] [band];
predict  [band] = true;
}
else {                                                       // 3 differential SCFs using normal huffman coding
SCF  [0] [band] = SCF_last [band] + Decode_Huffman (table2);
SCF  [1] [band] = SCF  [0] [band] + Decode_Huffman (table2);
SCF  [2] [band] = SCF  [1] [band] + Decode_Huffman (table2);
SCF_last [band] = SCF  [2] [band];
predict  [band] = true;
}

 Last Subframe Current Subframe SCFprev ( 0) SCFcurr ( 0) SCFprev ( 1) SCFcurr ( 1) SCFprev ( 2) SCFcurr ( 2) SCFprev ( 3) SCFcurr ( 3) SCFprev ( 4) SCFcurr ( 4) SCFprev ( 5) SCFcurr ( 5) SCFprev ( 6) SCFcurr ( 6) SCFprev ( 7) SCFcurr ( 7) SCFprev ( 8) SCFcurr ( 8) SCFprev ( 9) SCFcurr ( 9) SCFprev (10) SCFcurr (10) SCFprev (11) SCFcurr (11) SCFprev (12) SCFcurr (12) SCFprev (13) SCFcurr (13) SCFprev (14) SCFcurr (14) SCFprev (15) SCFcurr (15) SCFprev (16) SCFcurr (16) SCFprev (17) SCFcurr (17) SCFprev (18) SCFcurr (18) SCFprev (19) SCFcurr (19) SCFprev (20) SCFcurr (20) SCFprev (21) SCFcurr (21) SCFprev (22) SCFcurr (22) SCFprev (23) SCFcurr (23) SCFprev (24) SCFcurr (24) SCFprev (25) SCFcurr (25) SCFprev (26) SCFcurr (26) SCFprev (27) SCFcurr (27) SCFprev (28) SCFcurr (28) SCFprev (29) SCFcurr (29) SCFprev (30) SCFcurr (30) SCFprev (31) SCFcurr (31)

Spectral Predictor:

static signed char  Tab  [32] = { ?, -5, -2, -1, -1, -1, -1, -1, -1 };
Huffman_Table*      Huff [32] = { ?, tab1, tab2, tab2, tab2, tab3, tab3, tab3, tab3, tab3, tab3, tab3, tab4, ... };
int                 code;
int                 band;
int                 tmp;

tmp       = Read_Bits (7);
SCF [][0] = tmp;
for ( band = 1; band <= Max_Band; band++ ) {
SCF [][band] = tmp += Decode_Huffman (Huff[band]) + Tab [band];
}

Mixed Spectral + Temporal Predictor:

int                 code;
int                 band;

SCF [][0] = SCF_last [0] + Decode_Huffman (table);   // ???
for ( band = 1; band <= Max_Band; band++ ) {
SCF [][band] =  ( ( SCF_last [band] + SCF [][band-1] ) >> 1 ) + Decode_Huffman (table);
}

Temporal Predictor:

int                 code;
int                 band;

for ( band = 0; band <= Max_Band; band++ ) {
SCF [][band] =  SCF_last [band] + Decode_Huffman (table);
}