Browse Source

Remove channel loops from filterbank and iFilterbank, Minor fixes

master
Apostolos Fanakis 6 years ago
parent
commit
df884d13de
  1. 2
      Level_1/AACoder1.m
  2. 6
      Level_1/SSC.m
  3. 45
      Level_1/demoAAC1.m
  4. 40
      Level_1/filterbank.m
  5. 37
      Level_1/iFilterbank.m

2
Level_1/AACoder1.m

@ -26,7 +26,7 @@ function AACSeq1 = AACoder1(fNameIn)
frameTypes{i+1} = SSC(1, originalAudioData(nextFrameStart:nextFrameStop, :), frameTypes{i});
end
% Assignes a type to the last frame
% Assigns a type to the last frame
if strcmp(frameTypes{length(frameTypes) - 1}, 'LSS')
frameTypes{length(frameTypes)} = 'ESH';
elseif strcmp(frameTypes{length(frameTypes) - 1}, 'ESH')

6
Level_1/SSC.m

@ -30,9 +30,7 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
% Determines the type of the next frame
% Filters frame
nextFrameT = filter([0.7548 -0.7548], [1 -0.5095], nextFrameT, [], 1);
channelFrameType = {'nan', 'nan'};
for channel = 1:2
% Calculates sub-frame energy estimation
[subFrames, ~] = buffer(nextFrameT(449:end - 448, channel), 256, 128, 'nodelay');
@ -45,6 +43,7 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
if ~isempty(find(energyEstimations > 10^(-3), 1)) && ...
~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 1))
% Next frame is ESH
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
@ -63,8 +62,9 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
end
end
% Joins decision for both channels
if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan')
error('SSC, l[73]: Internal error occured!')
error('SSC, l[73]: Internal error occurred!')
end
if strcmp(channelFrameType{1}, 'OLS')
frameType = channelFrameType{2};

45
Level_1/demoAAC1.m

@ -1,5 +1,5 @@
function SNR = demoAAC1(fNameIn, fNameOut)
%Implementation of WHAT?? //TODO!!
%Function that demonstrates usage of the level 1 code
% Usage SNR = demoAAC1(fNameIn, fNameOut), where:
% Inputs
% - fNameIn is the filename and path of the file to encode
@ -16,22 +16,33 @@ function SNR = demoAAC1(fNameIn, fNameOut)
[audioData, ~] = audioread(fNameIn);
% figure()
% plot(audioData(1:length(decodedAudio), 1) - decodedAudio(1:end, 1))
% figure()
% plot(audioData(1:length(decodedAudio), 2) - decodedAudio(1:end, 2))
% plot(audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1))
% for frame = 1:length(AACSeq1)
% if strcmp(AACSeq1(frame).frameType, 'LSS') || strcmp(AACSeq1(frame).frameType, 'LPS')
% % Add lines
% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]);
% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]);
% % Set properties of lines
% set([h1 h2],'Color','y','LineWidth',2)
% % Add a patch
% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'y')
% elseif strcmp(AACSeq1(frame).frameType, 'ESH')
% % Add lines
% h1 = line([(frame-1)*1024+1 (frame-1)*1024+1],[-2*10^(-15) 2*10^(-15)]);
% h2 = line([frame*1024+1 frame*1024+1],[-2*10^(-15) 2*10^(-15)]);
% % Set properties of lines
% set([h1 h2],'Color','r','LineWidth',2)
% % Add a patch
% patch([(frame-1)*1024+1 frame*1024+1 frame*1024+1 (frame-1)*1024+1],[-2*10^(-15) -2*10^(-15) 2*10^(-15) 2*10^(-15)],'r')
% end
% end
% set(gca,'children',flipud(get(gca,'children')))
%
% snr(audioData(1:length(decodedAudio), 1), audioData(1:length(decodedAudio), 1) - decodedAudio(1:end, 1))
% snr(audioData(1:length(decodedAudio), 2), audioData(1:length(decodedAudio), 2) - decodedAudio(1:end, 2))
% SNR = 10*log10((sum(audioData(1:length(decodedAudio), :)) .^ 2) ./ ...
% (sum(audioData(1:length(decodedAudio), :) - decodedAudio) .^ 2));
figure()
plot(audioData(1024:length(decodedAudio)-1024, 1) - decodedAudio(1024:end-1024, 1))
figure()
plot(audioData(1024:length(decodedAudio)-1024, 2) - decodedAudio(1024:end-1024, 2))
% figure()
% plot(audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2))
snr(audioData(1024:length(decodedAudio)-1024, 1), audioData(1024:length(decodedAudio)-1024, 1) - decodedAudio(1024:end-1024, 1))
snr(audioData(1024:length(decodedAudio)-1024, 2), audioData(1024:length(decodedAudio)-1024, 2) - decodedAudio(1024:end-1024, 2))
SNR = 10*log10((var(audioData(1024:length(decodedAudio)-1024, :)) .^ 2) ./ ...
(var(audioData(1024:length(decodedAudio)-1024, :) - decodedAudio(1024:end-1024, :)) .^ 2));
snr(audioData(1025:length(decodedAudio)-1024, 1), audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1))
snr(audioData(1025:length(decodedAudio)-1024, 2), audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025:end-1024, 2))
SNR = 10*log10((sum(audioData(1025:length(decodedAudio)-1024, :)) .^ 2) ./ ...
(sum(audioData(1025:length(decodedAudio)-1024, :) - decodedAudio(1025:end-1024, :)) .^ 2));
end

40
Level_1/filterbank.m

@ -38,49 +38,50 @@ function frameF = filterbank(frameT, frameType, winType)
sinWindowShort = sin(pi * ((0:255) + 0.5) / 256);
end
% Initializes output array
frameF(1024, 2) = 0;
% Applies appropriate window to the frame
for channel=1:2
if strcmp(frameType, 'OLS')
if strcmp(winType, 'KBD')
frameT(:, channel) = frameT(:, channel) .* kaiserWindowLong(:);
frameT = bsxfun(@times, frameT, kaiserWindowLong');
elseif strcmp(winType, 'SIN')
frameT(:, channel) = frameT(:, channel) .* sinWindowLong(:);
frameT = bsxfun(@times, frameT, sinWindowLong');
else
error('filterbank, l[20]: Unsupported window type input!')
end
frameF(:, channel) = mdct4(frameT(:, channel));
frameF = mdct4(frameT);
elseif strcmp(frameType, 'LSS')
if strcmp(winType, 'KBD')
frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)';
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* kaiserWindowShort(129:end)';
frameT(1601:end, channel) = 0;
frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)');
frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)');
frameT(1601:end, :) = 0;
elseif strcmp(winType, 'SIN')
frameT(1:1024, channel) = frameT(1:1024, channel) .* sinWindowLong(1:1024)';
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* sinWindowShort(129:end)';
frameT(1601:end, channel) = 0;
frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)');
frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)');
frameT(1601:end, :) = 0;
else
error('filterbank, l[20]: Unsupported window type input!')
end
frameF(:, channel) = mdct4(frameT(:, channel));
frameF = mdct4(frameT);
elseif strcmp(frameType, 'LPS')
if strcmp(winType, 'KBD')
frameT(1:448, channel) = 0;
frameT(449:576, channel) = frameT(449:576, channel) .* kaiserWindowShort(1:128)';
frameT(1025:end, channel) = frameT(1025:end, channel) .* kaiserWindowLong(1025:end)';
frameT(1:448, :) = 0;
frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)');
frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)');
elseif strcmp(winType, 'SIN')
frameT(1:448, channel) = 0;
frameT(449:576, channel) = frameT(449:576, channel) .* sinWindowShort(1:128)';
frameT(1025:end, channel) = frameT(1025:end, channel) .* sinWindowLong(1025:end)';
frameT(1:448, :) = 0;
frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)');
frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)');
else
error('filterbank, l[20]: Unsupported window type input!')
end
frameF(:, channel) = mdct4(frameT(:, channel));
frameF = mdct4(frameT);
elseif strcmp(frameType, 'ESH')
for channel = 1:2
% Splits the frame into sub-frames
[subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay');
@ -91,7 +92,8 @@ function frameF = filterbank(frameT, frameType, winType)
end
for subFrameIndex = 1:8
frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel) = mdct4(subFrames(:, subFrameIndex));
frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel) = ...
mdct4(subFrames(:, subFrameIndex));
end
end
end

37
Level_1/iFilterbank.m

@ -38,49 +38,50 @@ function frameT = iFilterbank(frameF, frameType, winType)
sinWindowShort = sin(pi * ((0:255) + 0.5) / 256);
end
% Initializes output array
frameT(2048, 2) = 0;
% Applies appropriate window to the frame
for channel=1:2
if strcmp(frameType, 'OLS')
frameT(:, channel) = imdct4(frameF(:, channel));
frameT = imdct4(frameF);
if strcmp(winType, 'KBD')
frameT(:, channel) = frameT(:, channel) .* kaiserWindowLong(:);
frameT = bsxfun(@times, frameT, kaiserWindowLong');
elseif strcmp(winType, 'SIN')
frameT(:, channel) = frameT(:, channel) .* sinWindowLong(:);
frameT = bsxfun(@times, frameT, sinWindowLong');
else
error('filterbank, l[20]: Unsupported window type input!')
end
elseif strcmp(frameType, 'LSS')
frameT(:, channel) = imdct4(frameF(:, channel));
frameT = imdct4(frameF);
if strcmp(winType, 'KBD')
frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)';
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* kaiserWindowShort(129:end)';
frameT(1601:end, channel) = 0;
frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), kaiserWindowLong(1:1024)');
frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), kaiserWindowShort(129:end)');
frameT(1601:end, :) = 0;
elseif strcmp(winType, 'SIN')
frameT(1:1024, channel) = frameT(1:1024, channel) .* sinWindowLong(1:1024)';
frameT(1473:1600, channel) = frameT(1473:1600, channel) .* sinWindowShort(129:end)';
frameT(1601:end, channel) = 0;
frameT(1:1024, :) = bsxfun(@times, frameT(1:1024, :), sinWindowLong(1:1024)');
frameT(1473:1600, :) = bsxfun(@times, frameT(1473:1600, :), sinWindowShort(129:end)');
frameT(1601:end, :) = 0;
else
error('filterbank, l[20]: Unsupported window type input!')
end
elseif strcmp(frameType, 'LPS')
frameT(:, channel) = imdct4(frameF(:, channel));
frameT = imdct4(frameF);
if strcmp(winType, 'KBD')
frameT(1:448, channel) = 0;
frameT(449:576, channel) = frameT(449:576, channel) .* kaiserWindowShort(1:128)';
frameT(1025:end, channel) = frameT(1025:end, channel) .* kaiserWindowLong(1025:end)';
frameT(1:448, :) = 0;
frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), kaiserWindowShort(1:128)');
frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), kaiserWindowLong(1025:end)');
elseif strcmp(winType, 'SIN')
frameT(1:448, channel) = 0;
frameT(449:576, channel) = frameT(449:576, channel) .* sinWindowShort(1:128)';
frameT(1025:end, channel) = frameT(1025:end, channel) .* sinWindowLong(1025:end)';
frameT(1:448, :) = 0;
frameT(449:576, :) = bsxfun(@times, frameT(449:576, :), sinWindowShort(1:128)');
frameT(1025:end, :) = bsxfun(@times, frameT(1025:end, :), sinWindowLong(1025:end)');
else
error('filterbank, l[20]: Unsupported window type input!')
end
elseif strcmp(frameType, 'ESH')
for channel=1:2
for subFrameIndex = 1:8
subFrame = imdct4(frameF((subFrameIndex - 1) * 128 + 1:subFrameIndex * 128, channel));

Loading…
Cancel
Save