Browse Source

Add bitrate and compression calculation, Fixes

master
Apostolos Fanakis 6 years ago
parent
commit
cc350b8f39
  1. 3
      Level_3/AACoder3.m
  2. BIN
      Level_3/decoded3.wav
  3. 17
      Level_3/demoAAC3.m
  4. BIN
      Level_3/encoded.mat
  5. 65
      Level_3/iAACoder3.m

3
Level_3/AACoder3.m

@ -130,7 +130,6 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
TL(band) = sumsqr(subFrameF) ./ SMRL(band); TL(band) = sumsqr(subFrameF) ./ SMRL(band);
TR(band) = sumsqr(subFrameF) ./ SMRR(band); TR(band) = sumsqr(subFrameF) ./ SMRR(band);
end end
plot(TL);
else else
TL(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; TL(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0;
TR(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0; TR(SHORT_WINDOW_NUMBER_OF_BANDS, 1) = 0;
@ -176,6 +175,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');

BIN
Level_3/decoded3.wav

Binary file not shown.

17
Level_3/demoAAC3.m

@ -16,11 +16,26 @@ function [SNR, bitrate, compression] = demoAAC3(fNameIn, fNameOut, frameAACoded)
% the bitrate after it % the bitrate after it
AACSeq3 = AACoder3(fNameIn, frameAACoded); AACSeq3 = AACoder3(fNameIn, frameAACoded);
totalSize = 0;
for frameIndex = 1:length(AACSeq3)
totalSize = totalSize + 2; % frameType
totalSize = totalSize + 2 * 4; % TNS coefficients
totalSize = totalSize + length(AACSeq3(frameIndex).chl.G) * 4;
totalSize = totalSize + length(AACSeq3(frameIndex).chr.G) * 4;
totalSize = totalSize + length(AACSeq3(frameIndex).chl.sfc);
totalSize = totalSize + length(AACSeq3(frameIndex).chr.sfc);
totalSize = totalSize + length(AACSeq3(frameIndex).chl.stream);
totalSize = totalSize + length(AACSeq3(frameIndex).chr.stream);
end
decodedAudio = iAACoder3(AACSeq3, fNameOut); decodedAudio = iAACoder3(AACSeq3, fNameOut);
bitrate = totalSize / (length(decodedAudio) / 48000);
[audioData, ~] = audioread(fNameIn); [audioData, ~] = audioread(fNameIn);
compression = (length(audioData) * 64) / totalSize;
snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1))
snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2)) snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2))
SNR = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, :)); SNR = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :));
end end

BIN
Level_3/encoded.mat

Binary file not shown.

65
Level_3/iAACoder3.m

@ -48,50 +48,39 @@ function x = iAACoder3(AACSeq3, fNameOut)
currFrameStart = i * 1024 + 1; currFrameStart = i * 1024 + 1;
currFrameStop = currFrameStart + 2047; currFrameStop = currFrameStart + 2047;
if i < 2 SL = decodeHuff(AACSeq3(i + 1).chl.stream, ...
continue; AACSeq3(i + 1).chl.codebook, huffLUT);
frameF(:, 1) = iTNS(AACSeq3(i + 1).chl.stream, ... SR = decodeHuff(AACSeq3(i + 1).chr.stream, ...
AACSeq3(i+1).frameType, ... AACSeq3(i + 1).chr.codebook, huffLUT);
AACSeq3(i + 1).chl.TNScoeffs);
frameF(:, 2) = iTNS(AACSeq3(i + 1).chr.stream, ...
AACSeq3(i+1).frameType, ...
AACSeq3(i + 1).chr.TNScoeffs);
frameT = iFilterbank(frameF, AACSeq3(i+1).frameType, AACSeq3(i+1).winType); sfcL = decodeHuff(AACSeq3(i + 1).chl.sfc, 12, huffLUT)';
sfcR = decodeHuff(AACSeq3(i + 1).chr.sfc, 12, huffLUT)';
if strcmp(AACSeq3(i+1).frameType, 'ESH')
sfcDeHuffL(42, 8) = 0;
sfcDeHuffR(42, 8) = 0;
sfcDeHuffL(2:end, :) = reshape(sfcL, [41 8]);
sfcDeHuffR(2:end, :) = reshape(sfcR, [41 8]);
sfcDeHuffL(1, :) = AACSeq3(i+1).chl.G;
sfcDeHuffR(1, :) = AACSeq3(i+1).chr.G;
else else
SL = decodeHuff(AACSeq3(i + 1).chl.stream, ... sfcDeHuffL = [AACSeq3(i+1).chl.G; sfcL];
AACSeq3(i + 1).chl.codebook, huffLUT); sfcDeHuffR = [AACSeq3(i+1).chr.G; sfcR];
SR = decodeHuff(AACSeq3(i + 1).chr.stream, ... end
AACSeq3(i + 1).chr.codebook, huffLUT);
sfcL = decodeHuff(AACSeq3(i + 1).chl.sfc, 12, huffLUT)'; frameF(:, 1) = iAACquantizer(SL, sfcDeHuffL, ...
sfcR = decodeHuff(AACSeq3(i + 1).chr.sfc, 12, huffLUT)'; AACSeq3(i + 1).chl.G, AACSeq3(i+1).frameType);
if strcmp(AACSeq3(i+1).frameType, 'ESH') frameF(:, 2) = iAACquantizer(SR, sfcDeHuffR, ...
sfcDeHuffL(42, 8) = 0; AACSeq3(i + 1).chr.G, AACSeq3(i+1).frameType);
sfcDeHuffR(42, 8) = 0;
sfcDeHuffL(2:end, :) = reshape(sfcL, [41 8]);
sfcDeHuffR(2:end, :) = reshape(sfcR, [41 8]);
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, ... frameF(:, 1) = iTNS(frameF(:, 1), ...
AACSeq3(i + 1).chl.G, AACSeq3(i+1).frameType); AACSeq3(i+1).frameType, ...
frameF(:, 2) = iAACquantizer(SR, sfcDeHuffR, ... AACSeq3(i + 1).chl.TNScoeffs);
AACSeq3(i + 1).chr.G, AACSeq3(i+1).frameType); frameF(:, 2) = iTNS(frameF(:, 2), ...
AACSeq3(i+1).frameType, ...
AACSeq3(i + 1).chr.TNScoeffs);
frameF(:, 1) = iTNS(frameF(:, 1), ... frameT = iFilterbank(frameF, AACSeq3(i+1).frameType, AACSeq3(i+1).winType);
AACSeq3(i+1).frameType, ...
AACSeq3(i + 1).chl.TNScoeffs);
frameF(:, 2) = iTNS(frameF(:, 2), ...
AACSeq3(i+1).frameType, ...
AACSeq3(i + 1).chr.TNScoeffs);
frameT = iFilterbank(frameF, AACSeq3(i+1).frameType, AACSeq3(i+1).winType);
end
decodedAudio(currFrameStart:currFrameStop, :) = decodedAudio(currFrameStart:currFrameStop, :) + frameT; decodedAudio(currFrameStart:currFrameStop, :) = decodedAudio(currFrameStart:currFrameStop, :) + frameT;

Loading…
Cancel
Save