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

17
Level_1/SSC.m

@ -1,5 +1,5 @@
function frameType = SSC(~, nextFrameT, prevFrameType)
%Implementation of the SSC step
%Implementation of the Sequence Segmentation Control step
% Usage frameType = SSC(frameT, nextFrameT, prevFrameType), where:
% Inputs
% - 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
% 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
% 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
% the previous sub-frames
nextIsESH = 0;
for subFrameIndex = 1:8
nextIsESH = false;
for subFrameIndex = 2:8
energyRatio = energyEstimations(subFrameIndex) / ...
mean(energyEstimations(1:subFrameIndex - 1));
if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10)
nextIsESH = 1;
nextIsESH = true;
break;
end
end
if nextIsESH == 1
if nextIsESH == true
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
@ -70,6 +70,9 @@ function frameType = SSC(~, nextFrameT, prevFrameType)
end
end
if strcmp(channelFrameType{1}, 'nan') || strcmp(channelFrameType{2}, 'nan')
error('SSC, l[73]: Internal error occured!')
end
if strcmp(channelFrameType{1}, 'OLS')
frameType = channelFrameType{2};
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);
[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

6
Level_1/filterbank.m

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

6
Level_1/iAACoder1.m

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

10
Level_1/iFilterbank.m

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

Loading…
Cancel
Save