|
|
@ -35,6 +35,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
T(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; |
|
|
|
quantCoeff(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; |
|
|
|
sfc(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; |
|
|
|
initialQuantCoeff = 16 * log2(max(frameF) ^ (3 / 4) / 8191) / 3; |
|
|
|
for band = 1:LONG_WINDOW_NUMBER_OF_BANDS |
|
|
|
frameWlow = TNSTables.B219a(band, 2) + 1; |
|
|
|
frameWhigh = TNSTables.B219a(band, 3) + 1; |
|
|
@ -44,7 +45,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
|
|
|
|
% Calculates an initial quantization coefficient and attempts |
|
|
|
% quantization |
|
|
|
quantCoeff(band) = 16 * log2(max(frameF) ^ (3 / 4) / 8191) / 3; |
|
|
|
quantCoeff(band) = initialQuantCoeff; |
|
|
|
S(frameWlow:frameWhigh, 1) = sign(subFrameF) .* floor(( ... |
|
|
|
abs(subFrameF) .* 2 ^ (-quantCoeff(band) / 4)) ... |
|
|
|
.^ (3 / 4) + 0.4054); |
|
|
@ -61,7 +62,6 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
while quantErr < T(band) && (band < 2 || ... |
|
|
|
(quantCoeff(band) - quantCoeff(band - 1) + 1) <= 60) |
|
|
|
quantCoeff(band) = quantCoeff(band) + 1; |
|
|
|
|
|
|
|
S(frameWlow:frameWhigh) = sign(subFrameF) .* round(( ... |
|
|
|
abs(subFrameF) .* 2 ^ (-quantCoeff(band) / 4)) ... |
|
|
|
.^ (3 / 4) + 0.4054); |
|
|
@ -72,6 +72,13 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
|
|
|
|
quantErr = sumsqr(subFrameF - frameFDequant); |
|
|
|
end |
|
|
|
|
|
|
|
if quantCoeff(band) ~= initialQuantCoeff |
|
|
|
quantCoeff(band) = quantCoeff(band) - 1; |
|
|
|
S(frameWlow:frameWhigh) = sign(subFrameF) .* round(( ... |
|
|
|
abs(subFrameF) .* 2 ^ (-quantCoeff(band) / 4)) ... |
|
|
|
.^ (3 / 4) + 0.4054); |
|
|
|
end |
|
|
|
|
|
|
|
if band == 1 |
|
|
|
sfc(band) = quantCoeff(band); |
|
|
@ -89,6 +96,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
currFrameStart = (subFrameIndex - 1) * 128 + 1; |
|
|
|
currFrameStop = currFrameStart + 127; |
|
|
|
subFrame = frameF(currFrameStart:currFrameStop); |
|
|
|
initialQuantCoeff = 16 * log2(max(subFrame) ^ (3 / 4) / 8191) / 3; |
|
|
|
for band = 1:SHORT_WINDOW_NUMBER_OF_BANDS |
|
|
|
frameWlow = TNSTables.B219b(band, 2); |
|
|
|
frameWhigh = TNSTables.B219b(band, 3); |
|
|
@ -98,7 +106,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
|
|
|
|
% Calculates an initial quantization coefficient and attempts |
|
|
|
% quantization |
|
|
|
quantCoeff(band) = 16 * log2(max(subFrame) ^ (3 / 4) / 8191) / 3; |
|
|
|
quantCoeff(band) = initialQuantCoeff; |
|
|
|
S(currFrameStart + frameWlow:currFrameStart + frameWhigh, 1) = sign(subFrameF) .* floor(( ... |
|
|
|
abs(subFrameF) .* 2 ^ (-quantCoeff(band) / 4)) ... |
|
|
|
.^ (3 / 4) + 0.4054); |
|
|
@ -124,10 +132,17 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR) |
|
|
|
currFrameStart + frameWhigh, 1)) .* abs(S( ... |
|
|
|
currFrameStart + frameWlow:currFrameStart + frameWhigh, 1) ... |
|
|
|
) .^ (4 / 3) .* 2 ^ (quantCoeff(band) / 4); |
|
|
|
|
|
|
|
|
|
|
|
quantErr = sumsqr(subFrameF - frameFDequant); |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if quantCoeff(band) ~= initialQuantCoeff |
|
|
|
quantCoeff(band) = quantCoeff(band) - 1; |
|
|
|
S(currFrameStart + frameWlow:currFrameStart + frameWhigh) = sign(subFrameF) .* round(( ... |
|
|
|
abs(subFrameF) .* 2 ^ (-quantCoeff(band) / 4)) ... |
|
|
|
.^ (3 / 4) + 0.4054); |
|
|
|
end |
|
|
|
|
|
|
|
if band == 1 |
|
|
|
sfc(band, subFrameIndex) = quantCoeff(band); |
|
|
|
else |
|
|
|