Browse Source

Add two extra frames with zero padding on the end, Minor fix

master
Apostolos Fanakis 6 years ago
parent
commit
1beb80d214
  1. 23
      Level_1/AACoder1.m
  2. BIN
      Level_1/decoded1.wav
  3. 4
      Level_1/demoAAC1.m
  4. 23
      Level_2/AACoder2.m
  5. BIN
      Level_2/decoded2.wav
  6. 4
      Level_2/demoAAC2.m
  7. 76
      Level_3/AACoder3.m
  8. 2
      Level_3/AACquantizer.m
  9. BIN
      Level_3/decoded3.wav
  10. 16
      Level_3/demoAAC3.m
  11. BIN
      Level_3/encoded.mat

23
Level_1/AACoder1.m

@ -18,12 +18,20 @@ function AACSeq1 = AACoder1(fNameIn)
[originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame
frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS';
frameTypes{ceil(length(originalAudioData) / 1024), 1} = 'OLS';
frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047;
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
if nextFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameTypes{i+1} = SSC(1, tmpZeroPadded, frameTypes{i});
clearvars tmpZeroPadded
else
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end
end
% Assigns a type to the last frame
@ -40,7 +48,16 @@ function AACSeq1 = AACoder1(fNameIn)
for i = 0:length(frameTypes) - 1
currFrameStart = i * 1024 + 1;
currFrameStop = currFrameStart + 2047;
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
if currFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameF = filterbank(tmpZeroPadded, frameTypes{i+1}, WINDOW_TYPE);
clearvars tmpZeroPadded
else
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
AACSeq1(i + 1).frameType = frameTypes(i + 1);
AACSeq1(i + 1).winType = WINDOW_TYPE;

BIN
Level_1/decoded2.wav → Level_1/decoded1.wav

Binary file not shown.

4
Level_1/demoAAC1.m

@ -15,7 +15,5 @@ function SNR = demoAAC1(fNameIn, fNameOut)
[audioData, ~] = audioread(fNameIn);
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 = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :));
SNR = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
end

23
Level_2/AACoder2.m

@ -21,12 +21,20 @@ function AACSeq2 = AACoder2(fNameIn)
[originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame
frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS';
frameTypes{ceil(length(originalAudioData) / 1024), 1} = 'OLS';
frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047;
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
if nextFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameTypes{i+1} = SSC(1, tmpZeroPadded, frameTypes{i});
clearvars tmpZeroPadded
else
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end
end
% Assigns a type to the last frame
@ -43,7 +51,16 @@ function AACSeq2 = AACoder2(fNameIn)
for i = 0:length(frameTypes) - 1
currFrameStart = i * 1024 + 1;
currFrameStop = currFrameStart + 2047;
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
if currFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameF = filterbank(tmpZeroPadded, frameTypes{i+1}, WINDOW_TYPE);
clearvars tmpZeroPadded
else
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
[frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1});
[frameF(:, 2), TNScoeffsR] = TNS(frameF(:, 2), frameTypes{i+1});

BIN
Level_2/decoded2.wav

Binary file not shown.

4
Level_2/demoAAC2.m

@ -15,7 +15,5 @@ function SNR = demoAAC2(fNameIn, fNameOut)
[audioData, ~] = audioread(fNameIn);
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 = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :));
SNR = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
end

76
Level_3/AACoder3.m

@ -53,12 +53,20 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
[originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame
frameTypes{fix((length(originalAudioData) - 1025) / 1024), 1} = 'OLS';
frameTypes{ceil(length(originalAudioData) / 1024), 1} = 'OLS';
frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047;
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
if nextFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameTypes{i+1} = SSC(1, tmpZeroPadded, frameTypes{i});
clearvars tmpZeroPadded
else
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end
end
% Assigns a type to the last frame
@ -76,7 +84,15 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
for i = 0:length(frameTypes) - 1
currFrameStart = i * 1024 + 1;
currFrameStop = currFrameStart + 2047;
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
if currFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(nextFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
frameF = filterbank(tmpZeroPadded, frameTypes{i+1}, WINDOW_TYPE);
clearvars tmpZeroPadded
else
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
[frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1});
[frameF(:, 2), TNScoeffsR] = TNS(frameF(:, 2), frameTypes{i+1});
@ -105,16 +121,50 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
prev1FrameStop = prev1FrameStart + 2047;
prev2FrameStart = (i - 2) * 1024 + 1;
prev2FrameStop = prev2FrameStart + 2047;
SMRL = psycho(...
originalAudioData(currFrameStart:currFrameStop, 1), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 1), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 1));
SMRR = psycho(...
originalAudioData(currFrameStart:currFrameStop, 2), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
if prev1FrameStop > length(originalAudioData)
tmpZeroPaddedPrev = originalAudioData(prev1FrameStart:length(originalAudioData), :);
tmpZeroPaddedPrev = padarray(tmpZeroPaddedPrev, [(2048 - length(tmpZeroPaddedPrev)) 0], 'post');
tmpZeroPadded = originalAudioData(currFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
SMRL = psycho(...
tmpZeroPadded(:, 1), ...
frameTypes{i+1}, ...
tmpZeroPaddedPrev(:, 1), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
SMRR = psycho(...
tmpZeroPadded(:, 2), ...
frameTypes{i+1}, ...
tmpZeroPaddedPrev(:, 2), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
clearvars tmpZeroPadded tmpZeroPaddedPrev
elseif currFrameStop > length(originalAudioData)
tmpZeroPadded = originalAudioData(currFrameStart:length(originalAudioData), :);
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post');
SMRL = psycho(...
tmpZeroPadded(:, 1), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 1), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
SMRR = psycho(...
tmpZeroPadded(:, 2), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
clearvars tmpZeroPadded
else
SMRL = psycho(...
originalAudioData(currFrameStart:currFrameStop, 1), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 1), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 1));
SMRR = psycho(...
originalAudioData(currFrameStart:currFrameStop, 2), ...
frameTypes{i+1}, ...
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2));
end
end
[SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL);

2
Level_3/AACquantizer.m

@ -73,6 +73,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR)
quantErr = sumsqr(subFrameF - frameFDequant);
end
% Undoes the last incrementation
if quantCoeff(band) ~= initialQuantCoeff
quantCoeff(band) = quantCoeff(band) - 1;
S(frameWlow:frameWhigh) = sign(subFrameF) .* round(( ...
@ -136,6 +137,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR)
quantErr = sumsqr(subFrameF - frameFDequant);
end
% Undoes the last incrementation
if quantCoeff(band) ~= initialQuantCoeff
quantCoeff(band) = quantCoeff(band) - 1;
S(currFrameStart + frameWlow:currFrameStart + frameWhigh) = sign(subFrameF) .* round(( ...

BIN
Level_3/decoded3.wav

Binary file not shown.

16
Level_3/demoAAC3.m

@ -17,25 +17,25 @@ function [SNR, bitrate, compression] = demoAAC3(fNameIn, fNameOut, frameAACoded)
AACSeq3 = AACoder3(fNameIn, frameAACoded);
totalSize = 0;
totalSize = 0; % In bits
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 + 4 * 4; % TNS coefficients
totalSize = totalSize + length(AACSeq3(frameIndex).chl.G) * 16;
totalSize = totalSize + length(AACSeq3(frameIndex).chr.G) * 16;
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);
totalSize = totalSize + 4; % Codebook of left channel
totalSize = totalSize + 4; % Codebook of right channel
end
decodedAudio = iAACoder3(AACSeq3, fNameOut);
bitrate = totalSize / (length(decodedAudio) / 48000);
[audioData, ~] = audioread(fNameIn);
compression = (length(audioData) * 64) / totalSize;
compression = (2 * length(audioData) * 16) / (length(audioData) / 48000) / bitrate;
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 = snr(audioData(1025:length(decodedAudio)-1024, :), audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :));
SNR = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
end

BIN
Level_3/encoded.mat

Binary file not shown.
Loading…
Cancel
Save