diff --git a/Level_3/AACoder3.m b/Level_3/AACoder3.m index 74fa922..827ad6b 100644 --- a/Level_3/AACoder3.m +++ b/Level_3/AACoder3.m @@ -39,6 +39,15 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) % Declares constant window type WINDOW_TYPE = 'KBD'; + % 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); @@ -111,8 +120,34 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded) [SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL); [SR, sfcR, GR] = AACquantizer(frameF(:, 2), frameTypes{i+1}, SMRR); - TL = 0; - TR = 0; + if ~strcmp(frameTypes{i+1}, 'ESH') + TL(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; + TR(LONG_WINDOW_NUMBER_OF_BANDS, 1) = 0; + for band = 1:LONG_WINDOW_NUMBER_OF_BANDS + frameWlow = TNSTables.B219a(band, 2) + 1; + frameWhigh = TNSTables.B219a(band, 3) + 1; + subFrameF = frameF(frameWlow:frameWhigh); + TL(band) = sumsqr(subFrameF) ./ SMRL(band); + TR(band) = sumsqr(subFrameF) ./ SMRR(band); + end + plot(TL); + else + TL(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; + TR(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; + for subFrameIndex = 1:8 + currFrameStart = (subFrameIndex - 1) * 128 + 1; + currFrameStop = currFrameStart + 127; + subFrame = frameF(currFrameStart:currFrameStop); + for band = 1:SHORT_WINDOW_NUMBER_OF_BANDS + frameWlow = TNSTables.B219b(band, 2); + frameWhigh = TNSTables.B219b(band, 3); + subFrameF = subFrame(frameWlow + 1:frameWhigh + 1); + + TL(band, subFrameIndex) = sumsqr(subFrameF) ./ SMRL(band); + TR(band, subFrameIndex) = sumsqr(subFrameF) ./ SMRR(band); + end + end + end [streamL, huffcodebookL] = encodeHuff(SL, huffLUT); [streamR, huffcodebookR] = encodeHuff(SR, huffLUT); diff --git a/Level_3/encoded.mat b/Level_3/encoded.mat index bfa719c..c62b9bc 100644 Binary files a/Level_3/encoded.mat and b/Level_3/encoded.mat differ