|
@ -40,16 +40,6 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
% Declares constant window type |
|
|
% Declares constant window type |
|
|
WINDOW_TYPE = 'SIN'; |
|
|
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 |
|
|
% Reads the audio file |
|
|
[originalAudioData, ~] = audioread(fNameIn); |
|
|
[originalAudioData, ~] = audioread(fNameIn); |
|
|
|
|
|
|
|
@ -74,8 +64,6 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
% Encodes audio file |
|
|
% Encodes audio file |
|
|
huffLUT = loadLUT(); |
|
|
huffLUT = loadLUT(); |
|
|
AACSeq3(length(frameTypes)) = struct; |
|
|
AACSeq3(length(frameTypes)) = struct; |
|
|
TL(LONG_WINDOW_NUMBER_OF_BANDS) = 0; |
|
|
|
|
|
TR(LONG_WINDOW_NUMBER_OF_BANDS) = 0; |
|
|
|
|
|
for i = 0:length(frameTypes) - 1 |
|
|
for i = 0:length(frameTypes) - 1 |
|
|
currFrameStart = i * 1024 + 1; |
|
|
currFrameStart = i * 1024 + 1; |
|
|
currFrameStop = currFrameStart + 2047; |
|
|
currFrameStop = currFrameStart + 2047; |
|
@ -103,20 +91,11 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
frameTypes{i+1}, ... |
|
|
frameTypes{i+1}, ... |
|
|
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ... |
|
|
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ... |
|
|
originalAudioData(prev2FrameStart:prev2FrameStop, 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; |
|
|
continue; |
|
|
[SL, sfcL, GL] = AACquantizer(frameF, frameTypes{i+1}, SMRL); |
|
|
|
|
|
[SR, sfcR, GR] = AACquantizer(frameF, frameTypes{i+1}, SMRR); |
|
|
|
|
|
end |
|
|
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); |
|
|
[streamL, huffcodebookL] = encodeHuff(SL, huffLUT); |
|
|
[streamR, huffcodebookR] = encodeHuff(SR, huffLUT); |
|
|
[streamR, huffcodebookR] = encodeHuff(SR, huffLUT); |
|
|
[sfcL, ~] = encodeHuff(sfcL, huffLUT, 12); |
|
|
[sfcL, ~] = encodeHuff(sfcL, huffLUT, 12); |
|
@ -136,6 +115,8 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) |
|
|
AACSeq3(i + 1).chr.stream = streamR; |
|
|
AACSeq3(i + 1).chr.stream = streamR; |
|
|
AACSeq3(i + 1).chl.codebook = huffcodebookL; |
|
|
AACSeq3(i + 1).chl.codebook = huffcodebookL; |
|
|
AACSeq3(i + 1).chr.codebook = huffcodebookR; |
|
|
AACSeq3(i + 1).chr.codebook = huffcodebookR; |
|
|
|
|
|
|
|
|
|
|
|
clearvars TL TR; |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
save(fnameAACoded,AACSeq3); |
|
|
save(fnameAACoded,AACSeq3); |
|
|