Browse Source

Fixes and improvements

master
Apostolos Fanakis 6 years ago
parent
commit
acb33e8ffb
  1. 7
      Level_1/AACoder1.m
  2. 15
      Level_1/SSC.m
  3. 22
      Level_1/demoAAC1.m
  4. 21
      Level_1/filterbank.m
  5. 21
      Level_1/iFilterbank.m

7
Level_1/AACoder1.m

@ -11,6 +11,9 @@ function AACSeq1 = AACoder1(fNameIn)
% coefficients of this frame's left channel, chr.frameF which are % coefficients of this frame's left channel, chr.frameF which are
% the MDCT coefficients of this frame's right channel % the MDCT coefficients of this frame's right channel
% Declares constant window type
WINDOW_TYPE = 'KBD';
% Reads the audio file % Reads the audio file
[originalAudioData, ~] = audioread(fNameIn); [originalAudioData, ~] = audioread(fNameIn);
@ -37,10 +40,10 @@ function AACSeq1 = AACoder1(fNameIn)
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}, 'KBD'); frameF = filterbank(originalAudioData(currFrameStart:currFrameStop, :), frameTypes{i+1}, WINDOW_TYPE);
AACSeq1(i + 1).frameType = frameTypes(i + 1); AACSeq1(i + 1).frameType = frameTypes(i + 1);
AACSeq1(i + 1).winType = 'KBD'; AACSeq1(i + 1).winType = WINDOW_TYPE;
AACSeq1(i + 1).chl.frameF = frameF(:, 1); AACSeq1(i + 1).chl.frameF = frameF(:, 1);
AACSeq1(i + 1).chr.frameF = frameF(:, 2); AACSeq1(i + 1).chr.frameF = frameF(:, 2);
end end

15
Level_1/SSC.m

@ -40,18 +40,11 @@ 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 = false; energyRatios = movmean(energyEstimations, [8 0]);
for subFrameIndex = 2:8 energyRatios = energyEstimations ./ [energyEstimations(1) energyRatios(1:end-1)];
energyRatio = energyEstimations(subFrameIndex) / ...
mean(energyEstimations(1:subFrameIndex - 1));
if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10) if ~isempty(find(energyEstimations > 10^(-3), 1)) && ...
nextIsESH = true; ~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 1))
break;
end
end
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

22
Level_1/demoAAC1.m

@ -15,13 +15,23 @@ function SNR = demoAAC1(fNameIn, fNameOut)
[audioData, ~] = audioread(fNameIn); [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))
%
% 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() figure()
plot(audioData(1:length(decodedAudio), 1) - decodedAudio(1:end, 1)) plot(audioData(1024:length(decodedAudio)-1024, 1) - decodedAudio(1024:end-1024, 1))
figure() figure()
plot(audioData(1:length(decodedAudio), 2) - decodedAudio(1:end, 2)) plot(audioData(1024:length(decodedAudio)-1024, 2) - decodedAudio(1024:end-1024, 2))
snr(audioData(1:length(decodedAudio), 1), audioData(1:length(decodedAudio), 1) - decodedAudio(1:end, 1)) snr(audioData(1024:length(decodedAudio)-1024, 1), audioData(1024:length(decodedAudio)-1024, 1) - decodedAudio(1024:end-1024, 1))
snr(audioData(1:length(decodedAudio), 2), audioData(1:length(decodedAudio), 2) - decodedAudio(1:end, 2)) snr(audioData(1024:length(decodedAudio)-1024, 2), audioData(1024:length(decodedAudio)-1024, 2) - decodedAudio(1024:end-1024, 2))
SNR = 10*log10((sum(audioData(1:length(decodedAudio), :)) .^ 2) ./ ... SNR = 10*log10((var(audioData(1024:length(decodedAudio)-1024, :)) .^ 2) ./ ...
(sum(audioData(1:length(decodedAudio), :) - decodedAudio) .^ 2)); (var(audioData(1024:length(decodedAudio)-1024, :) - decodedAudio(1024:end-1024, :)) .^ 2));
end end

21
Level_1/filterbank.m

@ -25,22 +25,17 @@ function frameF = filterbank(frameT, frameType, winType)
kaiserShort = kaiser(128, 4*pi); kaiserShort = kaiser(128, 4*pi);
kaiserSumShort = sum(kaiserShort); kaiserSumShort = sum(kaiserShort);
for n = 1:1024 kaiserWindowLong(1:1024) = movsum(kaiserLong, [1024 0]);
kaiserWindowLong(n) = sqrt(sum(kaiserLong(1:n))/kaiserSumLong); kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong), [0 1024]);
kaiserWindowLong(1024 + n) = sqrt(sum(kaiserLong(1:end-n+1))/kaiserSumLong); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong);
sinWindowLong(n) = sin(pi*(n + 0.5)/2048); sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048);
sinWindowLong(1024 + n) = sin(pi*(1024 + n + 0.5)/2048);
end kaiserWindowShort(1:128) = movsum(kaiserShort, [128 0]);
kaiserWindowShort(129:256) = movsum(flipud(kaiserShort), [0 128]);
for n = 1:128 kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort);
kaiserWindowShort(n) = sqrt(sum(kaiserShort(1:n))/kaiserSumShort);
kaiserWindowShort(128 + n) = sqrt(sum(kaiserShort(1:end-n+1))/kaiserSumShort);
sinWindowShort(n) = sin(pi*(n + 0.5)/256); sinWindowShort = sin(pi * ((0:255) + 0.5) / 256);
sinWindowShort(128 + n) = sin(pi*(128 + n + 0.5)/256);
end
end end
frameF(1024, 2) = 0; frameF(1024, 2) = 0;

21
Level_1/iFilterbank.m

@ -25,22 +25,17 @@ function frameT = iFilterbank(frameF, frameType, winType)
kaiserShort = kaiser(128, 4*pi); kaiserShort = kaiser(128, 4*pi);
kaiserSumShort = sum(kaiserShort); kaiserSumShort = sum(kaiserShort);
for n = 1:1024 kaiserWindowLong(1:1024) = movsum(kaiserLong, [1024 0]);
kaiserWindowLong(n) = sqrt(sum(kaiserLong(1:n))/kaiserSumLong); kaiserWindowLong(1025:2048) = movsum(flipud(kaiserLong), [0 1024]);
kaiserWindowLong(1024 + n) = sqrt(sum(kaiserLong(1:end-n+1))/kaiserSumLong); kaiserWindowLong = sqrt(kaiserWindowLong ./ kaiserSumLong);
sinWindowLong(n) = sin(pi*(n + 0.5)/2048); sinWindowLong = sin(pi * ((0:2047) + 0.5) / 2048);
sinWindowLong(1024 + n) = sin(pi*(1024 + n + 0.5)/2048);
end kaiserWindowShort(1:128) = movsum(kaiserShort, [128 0]);
kaiserWindowShort(129:256) = movsum(flipud(kaiserShort), [0 128]);
for n = 1:128 kaiserWindowShort = sqrt(kaiserWindowShort ./ kaiserSumShort);
kaiserWindowShort(n) = sqrt(sum(kaiserShort(1:n))/kaiserSumShort);
kaiserWindowShort(128 + n) = sqrt(sum(kaiserShort(1:end-n+1))/kaiserSumShort);
sinWindowShort(n) = sin(pi*(n + 0.5)/256); sinWindowShort = sin(pi * ((0:255) + 0.5) / 256);
sinWindowShort(128 + n) = sin(pi*(128 + n + 0.5)/256);
end
end end
frameT(2048, 2) = 0; frameT(2048, 2) = 0;

Loading…
Cancel
Save