% test loudness mod

tic; 

% target loudness and test file
target_loudness = -18;  % dBLU
filename = 'pro.wav';

% import sound file
[audio, fs] = audioread(filename); 

% measure and display loudness
initial_loudness = getloudness(audio, fs, 'ITU', 0);
disp(['Initial loudness: ' num2str(initial_loudness)]);

% apply gain
difference_loudness = target_loudness - initial_loudness;
disp(['Difference in loudness: ' num2str(difference_loudness)]);
audio = 10^(difference_loudness/20) .* audio;
disp(['Gain: ' num2str(10^(difference_loudness/20))]);

% measure and display loudness (should be equal to target loudness)
resulting_loudness = getloudness(audio, fs, 'ITU', 0);
disp(['Resulting loudness: ' num2str(resulting_loudness)]);

elapsed_time = toc;
disp(['Elapsed time: ' num2str(elapsed_time)]);