Browse Source

Add Huffman encoding to level 3

master
Apostolos Fanakis 6 years ago
parent
commit
de88edcb11
  1. 6
      Level_2/TNS.m
  2. 25
      Level_3/AACoder3.m
  3. BIN
      Level_3/decoded3.wav
  4. BIN
      Level_3/encoded.mat
  5. 40
      Level_3/iAACoder3.m

6
Level_2/TNS.m

@ -60,7 +60,8 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType)
[linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER);
% Quantizes these coefficients % Quantizes these coefficients
quantizedLinPredCoeff = round(linPredCoeff, COEF_RES); quantizedLinPredCoeff = quantiz(linPredCoeff(2:end), -0.7:0.1:0.7);
quantizedLinPredCoeff = [1 -0.75 + 0.1 * quantizedLinPredCoeff];
% Filters MDCT coefficients % Filters MDCT coefficients
if ~isstable(1, quantizedLinPredCoeff) if ~isstable(1, quantizedLinPredCoeff)
@ -104,7 +105,8 @@ function [frameFout, TNScoeffs] = TNS(frameFin, frameType)
[linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER); [linPredCoeff, ~] = lpc(normalizedFrameFin, LPF_ORDER);
% Quantizes these coefficients % Quantizes these coefficients
quantizedLinPredCoeff = round(linPredCoeff, COEF_RES); quantizedLinPredCoeff = quantiz(linPredCoeff(2:end), -0.7:0.1:0.7);
quantizedLinPredCoeff = [1 -0.75 + 0.1 * quantizedLinPredCoeff];
% Filters MDCT coefficients % Filters MDCT coefficients
if ~isstable(1, quantizedLinPredCoeff) if ~isstable(1, quantizedLinPredCoeff)

25
Level_3/AACoder3.m

@ -79,6 +79,7 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
GR = 0; GR = 0;
sfcL = 0; sfcL = 0;
sfcR = 0; sfcR = 0;
continue;
else else
prev1FrameStart = (i - 1) * 1024 + 1; prev1FrameStart = (i - 1) * 1024 + 1;
prev1FrameStop = prev1FrameStart + 2047; prev1FrameStop = prev1FrameStart + 2047;
@ -100,15 +101,19 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
TL = 0; TL = 0;
TR = 0; TR = 0;
streamL = SL;
huffcodebookL = 0;
streamR = SR;
huffcodebookR = 0;
% [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);
% [sfcR, ~] = encodeHuff(sfcR, huffLUT, 12); if strcmp(frameTypes(i+1), 'ESH')
[sfcHuffL, ~] = encodeHuff(reshape(sfcL(2:end, :), 1, [])', ...
huffLUT, 12);
[sfcHuffR, ~] = encodeHuff(reshape(sfcR(2:end, :), 1, [])', ...
huffLUT, 12);
else
[sfcHuffL, ~] = encodeHuff(sfcL(2:end), huffLUT, 12);
[sfcHuffR, ~] = encodeHuff(sfcR(2:end), huffLUT, 12);
end
AACSeq3(i + 1).frameType = frameTypes(i + 1); AACSeq3(i + 1).frameType = frameTypes(i + 1);
AACSeq3(i + 1).winType = WINDOW_TYPE; AACSeq3(i + 1).winType = WINDOW_TYPE;
@ -118,8 +123,8 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
AACSeq3(i + 1).chr.T = TR; AACSeq3(i + 1).chr.T = TR;
AACSeq3(i + 1).chl.G = GL; AACSeq3(i + 1).chl.G = GL;
AACSeq3(i + 1).chr.G = GR; AACSeq3(i + 1).chr.G = GR;
AACSeq3(i + 1).chl.sfc = sfcL; AACSeq3(i + 1).chl.sfc = sfcHuffL;
AACSeq3(i + 1).chr.sfc = sfcR; AACSeq3(i + 1).chr.sfc = sfcHuffR;
AACSeq3(i + 1).chl.stream = streamL; AACSeq3(i + 1).chl.stream = streamL;
AACSeq3(i + 1).chr.stream = streamR; AACSeq3(i + 1).chr.stream = streamR;
AACSeq3(i + 1).chl.codebook = huffcodebookL; AACSeq3(i + 1).chl.codebook = huffcodebookL;

BIN
Level_3/decoded3.wav

Binary file not shown.

BIN
Level_3/encoded.mat

Binary file not shown.

40
Level_3/iAACoder3.m

@ -49,6 +49,7 @@ function x = iAACoder3(AACSeq3, fNameOut)
currFrameStop = currFrameStart + 2047; currFrameStop = currFrameStart + 2047;
if i < 2 if i < 2
continue;
frameF(:, 1) = iTNS(AACSeq3(i + 1).chl.stream, ... frameF(:, 1) = iTNS(AACSeq3(i + 1).chl.stream, ...
AACSeq3(i+1).frameType, ... AACSeq3(i+1).frameType, ...
AACSeq3(i + 1).chl.TNScoeffs); AACSeq3(i + 1).chl.TNScoeffs);
@ -58,22 +59,29 @@ function x = iAACoder3(AACSeq3, fNameOut)
frameT = iFilterbank(frameF, AACSeq3(i+1).frameType, AACSeq3(i+1).winType); frameT = iFilterbank(frameF, AACSeq3(i+1).frameType, AACSeq3(i+1).winType);
else else
% SL = decodeHuff(AACSeq3(i + 1).chl.stream, ... SL = decodeHuff(AACSeq3(i + 1).chl.stream, ...
% AACSeq3(i + 1).chl.codebook, huffLUT); AACSeq3(i + 1).chl.codebook, huffLUT);
% SR = decodeHuff(AACSeq3(i + 1).chr.stream, ... SR = decodeHuff(AACSeq3(i + 1).chr.stream, ...
% AACSeq3(i + 1).chr.codebook, huffLUT); AACSeq3(i + 1).chr.codebook, huffLUT);
%
% sfcL = decodeHuff(AACSeq3(i + 1).chl.sfc, 12, huffLUT);
% sfcR = decodeHuff(AACSeq3(i + 1).chr.sfc, 12, huffLUT);
frameF(:, 1) = iAACquantizer(AACSeq3(i + 1).chl.stream, ... sfcL = decodeHuff(AACSeq3(i + 1).chl.sfc, 12, huffLUT)';
AACSeq3(i + 1).chl.sfc, ... sfcR = decodeHuff(AACSeq3(i + 1).chr.sfc, 12, huffLUT)';
AACSeq3(i + 1).chl.G, ... if strcmp(AACSeq3(i+1).frameType, 'ESH')
AACSeq3(i+1).frameType); sfcDeHuffL(42, 8) = 0;
frameF(:, 2) = iAACquantizer(AACSeq3(i + 1).chr.stream, ... sfcDeHuffR(42, 8) = 0;
AACSeq3(i + 1).chr.sfc, ... sfcDeHuffL(2:end, :) = reshape(sfcL, [41 8]);
AACSeq3(i + 1).chr.G, ... sfcDeHuffR(2:end, :) = reshape(sfcR, [41 8]);
AACSeq3(i+1).frameType); sfcDeHuffL(1, :) = AACSeq3(i+1).chl.G;
sfcDeHuffR(1, :) = AACSeq3(i+1).chr.G;
else
sfcDeHuffL = [AACSeq3(i+1).chl.G; sfcL];
sfcDeHuffR = [AACSeq3(i+1).chr.G; sfcR];
end
frameF(:, 1) = iAACquantizer(SL, sfcDeHuffL, ...
AACSeq3(i + 1).chl.G, AACSeq3(i+1).frameType);
frameF(:, 2) = iAACquantizer(SR, sfcDeHuffR, ...
AACSeq3(i + 1).chr.G, AACSeq3(i+1).frameType);
frameF(:, 1) = iTNS(frameF(:, 1), ... frameF(:, 1) = iTNS(frameF(:, 1), ...
AACSeq3(i+1).frameType, ... AACSeq3(i+1).frameType, ...
@ -86,6 +94,8 @@ function x = iAACoder3(AACSeq3, fNameOut)
end end
decodedAudio(currFrameStart:currFrameStop, :) = decodedAudio(currFrameStart:currFrameStop, :) + frameT; decodedAudio(currFrameStart:currFrameStop, :) = decodedAudio(currFrameStart:currFrameStop, :) + frameT;
clearvars sfcDeHuffL sfcDeHuffR
end end
audiowrite(fNameOut, decodedAudio, 48000); audiowrite(fNameOut, decodedAudio, 48000);

Loading…
Cancel
Save