Semester assignment for the course "Multimedia systems and virtual reality" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

82 lines
3.0 KiB

function frameType = SSC(~, nextFrameT, prevFrameType)
%Implementation of the SSC step
% Usage frameType = SSC(frameT, nextFrameT, prevFrameType), where:
% Inputs
% - frameT is a frame in the time domain, containing both channels of
% the audio stored in an array of dimensions 2048X2
% - nextFrameT is the next frame in the time domain, containing both
% channels of the audio stored in an array of dimensions 2048X2
% - prevFrameType is the type of the previous frame in string
% representation, can be one of "OLS" (ONLY_LONG_SEQUENCE), "LSS"
% (LONG_START_SEQUENCE), "ESH" (EIGHT_SHORT_SEQUENCE), "LPS"
% (LONG_STOP_SEQUENCE)
%
% Output
% - frameType is the type of the current frame in string
% representation, can be one of "OLS" (ONLY_LONG_SEQUENCE), "LSS"
% (LONG_START_SEQUENCE), "ESH" (EIGHT_SHORT_SEQUENCE), "LPS"
% (LONG_STOP_SEQUENCE)
% Examines the cases where the determination of the type of the next
% frame isn't needed for
if strcmp(prevFrameType, 'LSS')
frameType = 'ESH';
return;
elseif strcmp(prevFrameType, 'LPS')
frameType = 'OLS';
return;
end
% Determines the type of the next frame
% Filters frame
nextFrameT = filter([0.7548, -0.7548], [1, -0.5095], nextFrameT, [], 2);
channelFrameType = {'OLS', 'OLS'};
for channel = 1:2
% Calculates sub-frame energy estimation
[subFrames, ~] = buffer(nextFrameT(449:end-448, channel), 256, 128, 'nodelay');
energyEstimations = sum(subFrames.^2, 1);
% Calculates the ratio of the sub-frame energy to the average energy of
% the previous sub-frames
nextIsESH = 0;
for subFrameIndex = 1:8
energyRatio = energyEstimations(subFrameIndex) / ...
mean(energyEstimations(1:subFrameIndex-1));
if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10)
nextIsESH = 1;
break;
end
end
if nextIsESH == 1
if strcmp(prevFrameType, 'ESH')
% This frame of this channel is an EIGHT_SHORT_SEQUENCE type
% frame. This means the frames of both channels will be encoded
% as EIGHT_SHORT_SEQUENCE type frames.
frameType = 'ESH';
return;
elseif strcmp(prevFrameType, 'OLS')
channelFrameType{channel} = 'LSS';
end
else
if strcmp(prevFrameType, 'ESH')
channelFrameType{channel} = 'LPS';
elseif strcmp(prevFrameType, 'OLS')
channelFrameType{channel} = 'OLS';
end
end
end
if strcmp(channelFrameType{1}, 'OLS')
frameType = channelFrameType{2};
elseif strcmp(channelFrameType{2}, 'OLS')
frameType = channelFrameType{1};
elseif strcmp(channelFrameType{1}, channelFrameType{2})
frameType = channelFrameType{1};
else
frameType = 'ESH';
end
end