Semester assignment for the course "Multimedia systems and virtual reality" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
2.7 KiB

function [SNR, bitrate, compression] = demoAAC3(fNameIn, fNameOut, frameAACoded)
%Function that demonstrates usage of the level 3 code
% Usage [SNR, bitrate, compression] = demoAAC3(fNameIn, fNameOut, frameAACoded), where:
% Inputs
% - fNameIn is the filename and path of the file to encode
% - fNameOut is the filename and path of the wav file that will be
% written after decoding
% - frameAACoded is the filename and path of the mat file that will
% be written after encoding
%
% Output
% - SNR is the signal to noise ration computed after successively
% encoding and decoding the audio signal
% - bitrate is the bits per second
% - compression is the ratio of the bitrate before the encoding to
% the bitrate after it
AACSeq3 = AACoder3(fNameIn, frameAACoded);
decodedAudio = iAACoder3(AACSeq3, fNameOut);
[audioData, ~] = audioread(fNameIn);
% figure()
% plot(audioData(1025:length(decodedAudio)-1024, 1) - decodedAudio(1025:end-1024, 1))
% for frame = 1:length(AACSeq3)
% if strcmp(AACSeq3(frame).frameType, 'LSS') || strcmp(AACSeq3(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(AACSeq3(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')))
%
% figure()
% plot(audioData(1025:length(decodedAudio)-1024, 2) - decodedAudio(1025: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