roomDimensions = [25, 20, 17];
receiverCoord = [5, 6, 8];
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.02 0.03 0.03 0.03 0.04 0.07; ...
0.02 0.03 0.03 0.03 0.04 0.07].';
FVect = [125 250 500 1000 2000 4000];
ARIDataset = load("ReferenceHRTF.mat");
hrtfData = permute(ARIDataset.hrtfData, [2, 3, 1]);
sourcePosition = ARIDataset.sourcePosition(:, [1, 2]);
h = HelperImageSource(roomDimensions, receiverCoord, sourceCoord, A, FVect, fs, useHRTF, hrtfData, sourcePosition);
[audioIn, fs] = audioread('FunkyDrums-44p1-stereo-25secs.mp3');
if length(audioIn) < fix(fs*T)
error('Audio file is shorter than the requested playback duration T.');
sound(audioIn(1:fix(fs*T)), fs);
time = (0:length(audioIn)-1) / fs;
title('Original Audio Signal');
y1 = filter(h(:, 1), 1, audioIn);
y2 = filter(h(:, 2), 1, audioIn);
outputFileName = 'filtered_audio2.wav';
audiowrite(outputFileName, y, fs);
disp(['Filtered audio saved to ', outputFileName]);
sound(y(1:round(fs*T)), fs);
title('Filtered Audio Signal');
classdef RoomAudioSimulator2 < audioPlugin
PluginInterface = audioPluginInterface( ...
audioPluginParameter('roomLength', ...
'DisplayName', 'Room Length', ...
'Mapping', {'lin', 5, 35}), ...
audioPluginParameter('roomWidth', ...
'DisplayName', 'Room Width', ...
'Mapping', {'lin', 5, 35}), ...
audioPluginParameter('roomHeight', ...
'DisplayName', 'Room Height', ...
'Mapping', {'lin', 5, 35}), ...
audioPluginParameter('receiverX', ...
'DisplayName', 'Receiver X', ...
'Mapping', {'lin', 0, 35}), ...
audioPluginParameter('receiverY', ...
'DisplayName', 'Receiver Y', ...
'Mapping', {'lin', 0, 35}), ...
audioPluginParameter('receiverZ', ...
'DisplayName', 'Receiver Z', ...
'Mapping', {'lin', 0, 35}), ...
audioPluginParameter('sourceX', ...
'DisplayName', 'Source X', ...
'Mapping', {'lin', 0, 35}), ...
audioPluginParameter('sourceY', ...
'DisplayName', 'Source Y', ...
'Mapping', {'lin', 0, 35}), ...
audioPluginParameter('sourceZ', ...
'DisplayName', 'Source Z', ...
'Mapping', {'lin', 0, 35}));
properties (Access = private)
function obj = RoomAudioSimulator2()
ARIDataset = load("ReferenceHRTF.mat");
obj.hrtfData = permute(ARIDataset.hrtfData, [2, 3, 1]);
obj.sourcePosition = ARIDataset.sourcePosition(:, [1, 2]);
function audioOut = process(obj, audioIn)
audioIn = repmat(audioIn, 1, 2);
elseif size(audioIn, 2) ~= 2
error('Input audio must have 1 or 2 channels.');
[y1, obj.filterState(:, 1)] = filter(obj.h(:, 1), 1, audioIn(:, 1), obj.filterState(:, 1));
[y2, obj.filterState(:, 2)] = filter(obj.h(:, 2), 1, audioIn(:, 2), obj.filterState(:, 2));
obj.filterState = zeros(100, 2);
obj.filterState = zeros(size(obj.h, 1) - 1, 2);
function updateFilters(obj)
roomDimensions = [obj.roomLength, obj.roomWidth, obj.roomHeight];
receiverCoord = [obj.receiverX, obj.receiverY, obj.receiverZ];
sourceCoord = [obj.sourceX, obj.sourceY, obj.sourceZ];
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.10 0.20 0.40 0.60 0.50 0.60; ...
0.02 0.03 0.03 0.03 0.04 0.07; ...
0.02 0.03 0.03 0.03 0.04 0.07].';
FVect = [125, 250, 500, 1000, 2000, 4000];
obj.h = HelperImageSource(roomDimensions, receiverCoord, ...
sourceCoord, A, FVect, obj.fs, ...
true, obj.hrtfData, obj.sourcePosition);
function adaptPositions(obj)
obj.receiverX = min(max(round(obj.receiverX), 0), obj.roomLength);
obj.receiverY = min(max(round(obj.receiverY), 0), obj.roomWidth);
obj.receiverZ = min(max(round(obj.receiverZ), 0), obj.roomHeight);
obj.sourceX = min(max(round(obj.sourceX), 0), obj.roomLength);
obj.sourceY = min(max(round(obj.sourceY), 0), obj.roomWidth);
obj.sourceZ = min(max(round(obj.sourceZ), 0), obj.roomHeight);