Browse Source

Minor fixes

master
Apostolos Fanakis 6 years ago
parent
commit
0f7ada3bf3
  1. 1
      .gitignore
  2. 7
      Level_1/AACoder1.m
  3. 17
      Level_1/SSC.m
  4. BIN
      Level_1/decoded2.wav
  5. 12
      Level_1/demoAAC1.m
  6. 6
      Level_1/filterbank.m
  7. 6
      Level_1/iAACoder1.m
  8. 10
      Level_1/iFilterbank.m

1
.gitignore

@ -0,0 +1 @@
*.asv

7
Level_1/AACoder1.m

@ -1,5 +1,5 @@
function AACSeq1 = AACoder1(fNameIn) function AACSeq1 = AACoder1(fNameIn)
%Implementation of WHAT?? //TODO!! %Implementation of AAC encoder
% Usage AACSeq1 = AACoder1(fNameIn), where: % Usage AACSeq1 = AACoder1(fNameIn), where:
% Inputs % Inputs
% - fNameIn is the filename and path of the file to encode % - fNameIn is the filename and path of the file to encode
@ -32,11 +32,12 @@ function AACSeq1 = AACoder1(fNameIn)
frameTypes{length(frameTypes)} = 'OLS'; frameTypes{length(frameTypes)} = 'OLS';
end end
% Encodes audio file
AACSeq1(length(frameTypes)) = struct; AACSeq1(length(frameTypes)) = struct;
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}, 'SIN'); frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, 'KBD');
AACSeq1(i + 1).frameType = frameTypes(i + 1); AACSeq1(i + 1).frameType = frameTypes(i + 1);
AACSeq1(i + 1).winType = 'KBD'; AACSeq1(i + 1).winType = 'KBD';
@ -44,7 +45,7 @@ function AACSeq1 = AACoder1(fNameIn)
AACSeq1(i + 1).chr.frameF = frameF(:, 2); AACSeq1(i + 1).chr.frameF = frameF(:, 2);
end end
if true if false
[idx,label] = grp2idx(sort(frameTypes)); [idx,label] = grp2idx(sort(frameTypes));
hist(idx,unique(idx)); hist(idx,unique(idx));
set(gca,'xTickLabel',label) set(gca,'xTickLabel',label)

17
Level_1/SSC.m

@ -1,5 +1,5 @@
function frameType = SSC(~, nextFrameT, prevFrameType) function frameType = SSC(~, nextFrameT, prevFrameType)
%Implementation of the SSC step %Implementation of the Sequence Segmentation Control step
% Usage frameType = SSC(frameT, nextFrameT, prevFrameType), where: % Usage frameType = SSC(frameT, nextFrameT, prevFrameType), where:
% Inputs % Inputs
% - frameT is a frame in the time domain, containing both channels of % - frameT is a frame in the time domain, containing both channels of
@ -29,9 +29,9 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
% Determines the type of the next frame % Determines the type of the next frame
% Filters frame % Filters frame
nextFrameT = filter([0.7548, -0.7548], [1, -0.5095], nextFrameT, [], 2); nextFrameT = filter([0.7548, -0.7548], [1, -0.5095], nextFrameT, [], 1);
channelFrameType = {'OLS', 'OLS'}; channelFrameType = {'nan', 'nan'};
for channel = 1:2 for channel = 1:2
% Calculates sub-frame energy estimation % Calculates sub-frame energy estimation
@ -40,18 +40,18 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
% Calculates the ratio of the sub-frame energy to the average energy of % Calculates the ratio of the sub-frame energy to the average energy of
% the previous sub-frames % the previous sub-frames
nextIsESH = 0; nextIsESH = false;
for subFrameIndex = 1:8 for subFrameIndex = 2:8
energyRatio = energyEstimations(subFrameIndex) / ... energyRatio = energyEstimations(subFrameIndex) / ...
mean(energyEstimations(1:subFrameIndex - 1)); mean(energyEstimations(1:subFrameIndex - 1));
if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10) if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10)
nextIsESH = 1; nextIsESH = true;
break; break;
end end
end end
if nextIsESH == 1 if nextIsESH == true
if strcmp(prevFrameType, 'ESH') if strcmp(prevFrameType, 'ESH')
% This frame of this channel is an EIGHT_SHORT_SEQUENCE type % This frame of this channel is an EIGHT_SHORT_SEQUENCE type
% frame. This means the frames of both channels will be encoded % frame. This means the frames of both channels will be encoded
@ -70,6 +70,9 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
end end
end end
if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan')
error('SSC, l[73]: Internal error occured!')
end
if strcmp(channelFrameType{1}, 'OLS') if strcmp(channelFrameType{1}, 'OLS')
frameType = channelFrameType{2}; frameType = channelFrameType{2};
elseif strcmp(channelFrameType{2}, 'OLS') elseif strcmp(channelFrameType{2}, 'OLS')

BIN
Level_1/decoded2.wav

Binary file not shown.

12
Level_1/demoAAC1.m

@ -14,6 +14,14 @@ function SNR = demoAAC1(fNameIn, fNameOut)
decodedAudio = iAACoder1(AACSeq1, fNameOut); decodedAudio = iAACoder1(AACSeq1, fNameOut);
[audioData, ~] = audioread(fNameIn); [audioData, ~] = audioread(fNameIn);
SNR = sum(10*log10((sum(audioData(1:length(decodedAudio), :)) .^ 2)./ ...
(sum(audioData(1:length(decodedAudio), :) - decodedAudio) .^ 2))); figure()
plot(audioData(1:length(decodedAudio), 1) - decodedAudio(1:end, 1))
figure()
plot(audioData(1:length(decodedAudio), 2) - decodedAudio(1:end, 2))
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));
end end

6
Level_1/filterbank.m

@ -56,7 +56,7 @@ function frameF = filterbank(frameT, frameType, winType)
error('filterbank, l[20]: Unsupported window type input!') error('filterbank, l[20]: Unsupported window type input!')
end end
frameF = mdct4(frameT); frameF(:, channel) = mdct4(frameT(:, channel));
elseif strcmp(frameType, 'LSS') elseif strcmp(frameType, 'LSS')
if strcmp(winType, 'KBD') if strcmp(winType, 'KBD')
frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)'; frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)';
@ -70,7 +70,7 @@ function frameF = filterbank(frameT, frameType, winType)
error('filterbank, l[20]: Unsupported window type input!') error('filterbank, l[20]: Unsupported window type input!')
end end
frameF = mdct4(frameT); frameF(:, channel) = mdct4(frameT(:, channel));
elseif strcmp(frameType, 'LPS') elseif strcmp(frameType, 'LPS')
if strcmp(winType, 'KBD') if strcmp(winType, 'KBD')
frameT(1:448, channel) = 0; frameT(1:448, channel) = 0;
@ -84,7 +84,7 @@ function frameF = filterbank(frameT, frameType, winType)
error('filterbank, l[20]: Unsupported window type input!') error('filterbank, l[20]: Unsupported window type input!')
end end
frameF = mdct4(frameT); frameF(:, channel) = mdct4(frameT(:, channel));
elseif strcmp(frameType, 'ESH') elseif strcmp(frameType, 'ESH')
% Splits the frame into sub-frames % Splits the frame into sub-frames
[subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay'); [subFrames, ~] = buffer(frameT(449:end-448, channel), 256, 128, 'nodelay');

6
Level_1/iAACoder1.m

@ -1,5 +1,5 @@
function x = iAACoder1(AACSeq1, fNameOut) function x = iAACoder1(AACSeq1, fNameOut)
%Implementation of WHAT?? //TODO!! %Implementation of AAC decoder
% Usage x = iAACoder1(AACSeq1, fNameOut), where: % Usage x = iAACoder1(AACSeq1, fNameOut), where:
% Inputs % Inputs
% - fNameOut is the filename and path of the file that will be % - fNameOut is the filename and path of the file that will be
@ -13,8 +13,12 @@ function x = iAACoder1(AACSeq1, fNameOut)
% Output % Output
% - x is an array containing the decoded audio samples % - x is an array containing the decoded audio samples
% Initializes an array to hold the decoded samples
decodedAudio(1024 * (length(AACSeq1) + 1), 2) = 0; decodedAudio(1024 * (length(AACSeq1) + 1), 2) = 0;
% Initializes an array to hold both audio channels
frameF(1024, 2) = 0; frameF(1024, 2) = 0;
% Decodes audio file
for i = 0:length(AACSeq1)-1 for i = 0:length(AACSeq1)-1
currFrameStart = i * 1024 + 1; currFrameStart = i * 1024 + 1;
currFrameStop = currFrameStart + 2047; currFrameStop = currFrameStart + 2047;

10
Level_1/iFilterbank.m

@ -48,7 +48,7 @@ function frameT = iFilterbank(frameF, frameType, winType)
% Applies appropriate window to the frame % Applies appropriate window to the frame
for channel=1:2 for channel=1:2
if strcmp(frameType, 'OLS') if strcmp(frameType, 'OLS')
frameT = imdct4(frameF); frameT(:, channel) = imdct4(frameF(:, channel));
if strcmp(winType, 'KBD') if strcmp(winType, 'KBD')
frameT(:, channel) = frameT(:, channel) .* kaiserWindowLong(:); frameT(:, channel) = frameT(:, channel) .* kaiserWindowLong(:);
@ -58,7 +58,7 @@ function frameT = iFilterbank(frameF, frameType, winType)
error('filterbank, l[20]: Unsupported window type input!') error('filterbank, l[20]: Unsupported window type input!')
end end
elseif strcmp(frameType, 'LSS') elseif strcmp(frameType, 'LSS')
frameT = imdct4(frameF); frameT(:, channel) = imdct4(frameF(:, channel));
if strcmp(winType, 'KBD') if strcmp(winType, 'KBD')
frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)'; frameT(1:1024, channel) = frameT(1:1024, channel) .* kaiserWindowLong(1:1024)';
@ -72,7 +72,7 @@ function frameT = iFilterbank(frameF, frameType, winType)
error('filterbank, l[20]: Unsupported window type input!') error('filterbank, l[20]: Unsupported window type input!')
end end
elseif strcmp(frameType, 'LPS') elseif strcmp(frameType, 'LPS')
frameT = imdct4(frameF); frameT(:, channel) = imdct4(frameF(:, channel));
if strcmp(winType, 'KBD') if strcmp(winType, 'KBD')
frameT(1:448, channel) = 0; frameT(1:448, channel) = 0;
@ -95,8 +95,8 @@ function frameT = iFilterbank(frameF, frameType, winType)
subFrame = subFrame .* sinWindowShort'; subFrame = subFrame .* sinWindowShort';
end end
frameT(449 + (subFrameIndex - 1) * 128 + 1:449 + (subFrameIndex + 1) * 128) = ... frameT(448 + (subFrameIndex - 1) * 128 + 1:448 + (subFrameIndex + 1) * 128, channel) = ...
frameT(449 + (subFrameIndex - 1) * 128 + 1:449 + (subFrameIndex + 1) * 128) + subFrame'; frameT(448 + (subFrameIndex - 1) * 128 + 1:448 + (subFrameIndex + 1) * 128, channel) + subFrame;
end end
end end
end end

Loading…
Cancel
Save