Browse Source

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

master
Apostolos Fanakis 6 years ago
parent
commit
1beb80d214
  1. 19
      Level_1/AACoder1.m
  2. BIN
      Level_1/decoded1.wav
  3. 4
      Level_1/demoAAC1.m
  4. 19
      Level_2/AACoder2.m
  5. BIN
      Level_2/decoded2.wav
  6. 4
      Level_2/demoAAC2.m
  7. 52
      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

19
Level_1/AACoder1.m

@ -18,13 +18,21 @@ function AACSeq1 = AACoder1(fNameIn)
[originalAudioData, ~] = audioread(fNameIn); [originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame % 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'; frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2 for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1; nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047; nextFrameStop = nextFrameStart + 2047;
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}); frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end end
end
% Assigns a type to the last frame % Assigns a type to the last frame
if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS') if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS')
@ -40,7 +48,16 @@ function AACSeq1 = AACoder1(fNameIn)
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;
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); frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
AACSeq1(i + 1).frameType = frameTypes(i + 1); AACSeq1(i + 1).frameType = frameTypes(i + 1);
AACSeq1(i + 1).winType = WINDOW_TYPE; 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); [audioData, ~] = audioread(fNameIn);
snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) SNR = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
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, :));
end end

19
Level_2/AACoder2.m

@ -21,13 +21,21 @@ function AACSeq2 = AACoder2(fNameIn)
[originalAudioData, ~] = audioread(fNameIn); [originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame % 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'; frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2 for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1; nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047; nextFrameStop = nextFrameStart + 2047;
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}); frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end end
end
% Assigns a type to the last frame % Assigns a type to the last frame
if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS') if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS')
@ -43,7 +51,16 @@ function AACSeq2 = AACoder2(fNameIn)
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;
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); frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
[frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1}); [frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1});
[frameF(:, 2), TNScoeffsR] = TNS(frameF(:, 2), 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); [audioData, ~] = audioread(fNameIn);
snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1)) SNR = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
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, :));
end end

52
Level_3/AACoder3.m

@ -53,13 +53,21 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
[originalAudioData, ~] = audioread(fNameIn); [originalAudioData, ~] = audioread(fNameIn);
% Splits the audio in frames and determines the type of each frame % 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'; frameTypes{1} = 'OLS';
for i = 1:length(frameTypes) - 2 for i = 1:length(frameTypes) - 2
nextFrameStart = (i + 1) * 1024 + 1; nextFrameStart = (i + 1) * 1024 + 1;
nextFrameStop = nextFrameStart + 2047; nextFrameStop = nextFrameStart + 2047;
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}); frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end end
end
% Assigns a type to the last frame % Assigns a type to the last frame
if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS') if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS')
@ -76,7 +84,15 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
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;
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); frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
end
[frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1}); [frameF(:, 1), TNScoeffsL] = TNS(frameF(:, 1), frameTypes{i+1});
[frameF(:, 2), TNScoeffsR] = TNS(frameF(:, 2), frameTypes{i+1}); [frameF(:, 2), TNScoeffsR] = TNS(frameF(:, 2), frameTypes{i+1});
@ -105,6 +121,39 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
prev1FrameStop = prev1FrameStart + 2047; prev1FrameStop = prev1FrameStart + 2047;
prev2FrameStart = (i - 2) * 1024 + 1; prev2FrameStart = (i - 2) * 1024 + 1;
prev2FrameStop = prev2FrameStart + 2047; prev2FrameStop = prev2FrameStart + 2047;
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(... SMRL = psycho(...
originalAudioData(currFrameStart:currFrameStop, 1), ... originalAudioData(currFrameStart:currFrameStop, 1), ...
frameTypes{i+1}, ... frameTypes{i+1}, ...
@ -116,6 +165,7 @@ function AACSeq3 = AACoder3(fNameIn, fnameAACoded)
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ... originalAudioData(prev1FrameStart:prev1FrameStop, 2), ...
originalAudioData(prev2FrameStart:prev2FrameStop, 2)); originalAudioData(prev2FrameStart:prev2FrameStop, 2));
end end
end
[SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL); [SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL);
[SR, sfcR, GR] = AACquantizer(frameF(:, 2), frameTypes{i+1}, SMRR); [SR, sfcR, GR] = AACquantizer(frameF(:, 2), frameTypes{i+1}, SMRR);

2
Level_3/AACquantizer.m

@ -73,6 +73,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR)
quantErr = sumsqr(subFrameF - frameFDequant); quantErr = sumsqr(subFrameF - frameFDequant);
end end
% Undoes the last incrementation
if quantCoeff(band) ~= initialQuantCoeff if quantCoeff(band) ~= initialQuantCoeff
quantCoeff(band) = quantCoeff(band) - 1; quantCoeff(band) = quantCoeff(band) - 1;
S(frameWlow:frameWhigh) = sign(subFrameF) .* round(( ... S(frameWlow:frameWhigh) = sign(subFrameF) .* round(( ...
@ -136,6 +137,7 @@ function [S, sfc, G] = AACquantizer(frameF, frameType, SMR)
quantErr = sumsqr(subFrameF - frameFDequant); quantErr = sumsqr(subFrameF - frameFDequant);
end end
% Undoes the last incrementation
if quantCoeff(band) ~= initialQuantCoeff if quantCoeff(band) ~= initialQuantCoeff
quantCoeff(band) = quantCoeff(band) - 1; quantCoeff(band) = quantCoeff(band) - 1;
S(currFrameStart + frameWlow:currFrameStart + frameWhigh) = sign(subFrameF) .* round(( ... 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); AACSeq3 = AACoder3(fNameIn, frameAACoded);
totalSize = 0; totalSize = 0; % In bits
for frameIndex = 1:length(AACSeq3) for frameIndex = 1:length(AACSeq3)
totalSize = totalSize + 2; % frameType totalSize = totalSize + 2; % frameType
totalSize = totalSize + 2 * 4; % TNS coefficients totalSize = totalSize + 4 * 4; % TNS coefficients
totalSize = totalSize + length(AACSeq3(frameIndex).chl.G) * 4; totalSize = totalSize + length(AACSeq3(frameIndex).chl.G) * 16;
totalSize = totalSize + length(AACSeq3(frameIndex).chr.G) * 4; totalSize = totalSize + length(AACSeq3(frameIndex).chr.G) * 16;
totalSize = totalSize + length(AACSeq3(frameIndex).chl.sfc); totalSize = totalSize + length(AACSeq3(frameIndex).chl.sfc);
totalSize = totalSize + length(AACSeq3(frameIndex).chr.sfc); totalSize = totalSize + length(AACSeq3(frameIndex).chr.sfc);
totalSize = totalSize + length(AACSeq3(frameIndex).chl.stream); totalSize = totalSize + length(AACSeq3(frameIndex).chl.stream);
totalSize = totalSize + length(AACSeq3(frameIndex).chr.stream); totalSize = totalSize + length(AACSeq3(frameIndex).chr.stream);
totalSize = totalSize + 4; % Codebook of left channel
totalSize = totalSize + 4; % Codebook of right channel
end end
decodedAudio = iAACoder3(AACSeq3, fNameOut); decodedAudio = iAACoder3(AACSeq3, fNameOut);
bitrate = totalSize / (length(decodedAudio) / 48000); bitrate = totalSize / (length(decodedAudio) / 48000);
[audioData, ~] = audioread(fNameIn); [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 = snr(audioData(1025:end-1378, :), audioData(1025:end-1378, :) - decodedAudio(1025:length(audioData)-1378, :));
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, :));
end end

BIN
Level_3/encoded.mat

Binary file not shown.
Loading…
Cancel
Save