|
|
|
function AACSeq1 = AACoder1(fNameIn)
|
|
|
|
%Implementation of AAC encoder
|
|
|
|
% Usage AACSeq1 = AACoder1(fNameIn), where:
|
|
|
|
% Inputs
|
|
|
|
% - fNameIn is the filename and path of the file to encode
|
|
|
|
%
|
|
|
|
% Output
|
|
|
|
% - AACSeq1 is an array of structs containing K structs, where K is
|
|
|
|
% the number of computed frames. Every struct of the array consists
|
|
|
|
% of a frameType, a winType, chl.frameF which are the MDCT
|
|
|
|
% coefficients of this frame's left channel, chr.frameF which are
|
|
|
|
% the MDCT coefficients of this frame's right channel
|
|
|
|
|
|
|
|
% Reads the audio file
|
|
|
|
[originalAudioData, ~] = audioread(fNameIn);
|
|
|
|
|
|
|
|
% Splits the audio in frames and determines the type of each frame
|
|
|
|
frameTypes{fix((length(originalAudioData) - 1025) / 1024)} = '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});
|
|
|
|
end
|
|
|
|
|
|
|
|
% Assignes a type to the last frame
|
|
|
|
if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS')
|
|
|
|
frameTypes{length(frameTypes)} = 'ESH';
|
|
|
|
elseif strcmp(frameTypes{length(frameTypes) - 1}, 'ESH')
|
|
|
|
frameTypes{length(frameTypes)} = 'ESH';
|
|
|
|
else
|
|
|
|
frameTypes{length(frameTypes)} = 'OLS';
|
|
|
|
end
|
|
|
|
|
|
|
|
% Encodes audio file
|
|
|
|
AACSeq1(length(frameTypes)) = struct;
|
|
|
|
for i = 0:length(frameTypes)-1
|
|
|
|
currFrameStart = i * 1024 + 1;
|
|
|
|
currFrameStop = currFrameStart + 2047;
|
|
|
|
frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, 'KBD');
|
|
|
|
|
|
|
|
AACSeq1(i + 1).frameType = frameTypes(i + 1);
|
|
|
|
AACSeq1(i + 1).winType = 'KBD';
|
|
|
|
AACSeq1(i + 1).chl.frameF = frameF(:, 1);
|
|
|
|
AACSeq1(i + 1).chr.frameF = frameF(:, 2);
|
|
|
|
end
|
|
|
|
|
|
|
|
if false
|
|
|
|
[idx,label] = grp2idx(sort(frameTypes));
|
|
|
|
hist(idx,unique(idx));
|
|
|
|
set(gca,'xTickLabel',label)
|
|
|
|
|
|
|
|
sum(idx(:) == 1)
|
|
|
|
sum(idx(:) == 2)
|
|
|
|
sum(idx(:) == 3)
|
|
|
|
sum(idx(:) == 4)
|
|
|
|
end
|
|
|
|
end
|