|
@ -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); |
|
|