|
|
@ -39,16 +39,6 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
|
|
|
|
|
% Declares constant window type |
|
|
|
WINDOW_TYPE = 'SIN'; |
|
|
|
|
|
|
|
% Declares constant numbers of bands for long and short windows |
|
|
|
LONG_WINDOW_NUMBER_OF_BANDS = 69; |
|
|
|
SHORT_WINDOW_NUMBER_OF_BANDS = 42; |
|
|
|
|
|
|
|
% Declares persistent variable holding the TNS tables and initializes if empty |
|
|
|
persistent TNSTables; |
|
|
|
if isempty(TNSTables) |
|
|
|
TNSTables = load('TableB219.mat'); |
|
|
|
end |
|
|
|
|
|
|
|
% Reads the audio file |
|
|
|
[originalAudioData, ~] = audioread(fNameIn); |
|
|
@ -74,8 +64,6 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
|
% Encodes audio file |
|
|
|
huffLUT = loadLUT(); |
|
|
|
AACSeq3(length(frameTypes)) = struct; |
|
|
|
TL(LONG_WINDOW_NUMBER_OF_BANDS) = 0; |
|
|
|
TR(LONG_WINDOW_NUMBER_OF_BANDS) = 0; |
|
|
|
for i = 0:length(frameTypes) - 1 |
|
|
|
currFrameStart = i * 1024 + 1; |
|
|
|
currFrameStop = currFrameStart + 2047; |
|
|
@ -103,19 +91,10 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
|
frameTypes{i+1}, ... |
|
|
|
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ... |
|
|
|
originalAudioData(prev2FrameStart:prev2FrameStop, 2)); |
|
|
|
[SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL); |
|
|
|
[SR, sfcR, GR] = AACquantizer(frameF(:, 2), frameTypes{i+1}, SMRR); |
|
|
|
continue; |
|
|
|
[SL, sfcL, GL] = AACquantizer(frameF, frameTypes{i+1}, SMRL); |
|
|
|
[SR, sfcR, GR] = AACquantizer(frameF, frameTypes{i+1}, SMRR); |
|
|
|
end |
|
|
|
|
|
|
|
for band = 1:LONG_WINDOW_NUMBER_OF_BANDS |
|
|
|
TL(band) = sumsqr(frameF((TNSTables.B219a(band, 2) + 1: ... |
|
|
|
TNSTables.B219a(band, 3) + 1), 1)); |
|
|
|
TR(band) = sumsqr(frameF((TNSTables.B219a(band, 2) + 1: ... |
|
|
|
TNSTables.B219a(band, 3) + 1), 2)); |
|
|
|
end |
|
|
|
TL = TL ./ SMRL; |
|
|
|
TR = TR ./ SMRR; |
|
|
|
|
|
|
|
[streamL, huffcodebookL] = encodeHuff(SL, huffLUT); |
|
|
|
[streamR, huffcodebookR] = encodeHuff(SR, huffLUT); |
|
|
@ -136,6 +115,8 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
|
AACSeq3(i + 1).chr.stream = streamR; |
|
|
|
AACSeq3(i + 1).chl.codebook = huffcodebookL; |
|
|
|
AACSeq3(i + 1).chr.codebook = huffcodebookR; |
|
|
|
|
|
|
|
clearvars TL TR; |
|
|
|
end |
|
|
|
|
|
|
|
save(fnameAACoded,AACSeq3); |
|
|
|