|
@ -53,12 +53,20 @@ 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; |
|
|
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 |
|
|
end |
|
|
|
|
|
|
|
|
% Assigns a type to the last frame |
|
|
% Assigns a type to the last frame |
|
@ -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; |
|
|
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(:, 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,16 +121,50 @@ 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; |
|
|
SMRL = psycho(... |
|
|
|
|
|
originalAudioData(currFrameStart:currFrameStop, 1), ... |
|
|
if prev1FrameStop > length(originalAudioData) |
|
|
frameTypes{i+1}, ... |
|
|
tmpZeroPaddedPrev = originalAudioData(prev1FrameStart:length(originalAudioData), :); |
|
|
originalAudioData(prev1FrameStart:prev1FrameStop, 1), ... |
|
|
tmpZeroPaddedPrev = padarray(tmpZeroPaddedPrev, [(2048 - length(tmpZeroPaddedPrev)) 0], 'post'); |
|
|
originalAudioData(prev2FrameStart:prev2FrameStop, 1)); |
|
|
tmpZeroPadded = originalAudioData(currFrameStart:length(originalAudioData), :); |
|
|
SMRR = psycho(... |
|
|
tmpZeroPadded = padarray(tmpZeroPadded, [(2048 - length(tmpZeroPadded)) 0], 'post'); |
|
|
originalAudioData(currFrameStart:currFrameStop, 2), ... |
|
|
SMRL = psycho(... |
|
|
frameTypes{i+1}, ... |
|
|
tmpZeroPadded(:, 1), ... |
|
|
originalAudioData(prev1FrameStart:prev1FrameStop, 2), ... |
|
|
frameTypes{i+1}, ... |
|
|
originalAudioData(prev2FrameStart:prev2FrameStop, 2)); |
|
|
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 |
|
|
end |
|
|
|
|
|
|
|
|
[SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL); |
|
|
[SL, sfcL, GL] = AACquantizer(frameF(:, 1), frameTypes{i+1}, SMRL); |
|
|