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
% the MDCT coefficients of this frame's right channel
% Declares constant window type
WINDOW_TYPE = 'KBD';
% Reads the audio file
[originalAudioData, ~] = audioread(fNameIn);
@ -37,10 +40,10 @@ function AACSeq1 = AACoder1(fNameIn)
for i = 0:length(frameTypes) - 1
currFrameStart = i * 1024 + 1;
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).winType = 'KBD';
AACSeq1(i + 1).winType = WINDOW_TYPE;
AACSeq1(i + 1).chl.frameF = frameF(:, 1);
AACSeq1(i + 1).chr.frameF = frameF(:, 2);
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
% the previous sub-frames
nextIsESH = false;
for subFrameIndex = 2:8
energyRatio = energyEstimations(subFrameIndex) / ...
mean(energyEstimations(1:subFrameIndex - 1));
energyRatios = movmean(energyEstimations, [8 0]);
energyRatios = energyEstimations ./ [energyEstimations(1) energyRatios(1:end-1)];
if (energyEstimations(subFrameIndex) > 10^(-3)) && (energyRatio > 10)
nextIsESH = true;
break;
end
end
if nextIsESH == true
if ~isempty(find(energyEstimations > 10^(-3), 1)) && ...
~isempty(find(energyRatios(energyEstimations > 10^(-3)) > 10, 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

22
Level_1/demoAAC1.m

@ -15,13 +15,23 @@ 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))
%
% 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(1:length(decodedAudio), 1) - decodedAudio(1:end, 1))
plot(audioData(1024:length(decodedAudio)-1024, 1) - decodedAudio(1024:end-1024, 1))
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(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));
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));
end

21
Level_1/filterbank.m

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

21
Level_1/iFilterbank.m

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

Loading…
Cancel
Save