Commit f63e1222 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Little improvements

parent c7f5cf55
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
% the user. Also the generic path prototype rendering module(s) has to record the output % the user. Also the generic path prototype rendering module(s) has to record the output
% to hard drive. % to hard drive.
free_field_only = false; % Now occlusion and no reflections cont = struct();
direct_field_component = true; conf.free_field_only = false; % No occlusion, no reflections
reflected_field_component = true; conf.direct_field_component = true;
diffracted_field_component = true; conf.diffracted_field_component = true;
conf.reflected_field_component = false; % Causes heavy phasing due to comb filter effects
conf.update_gain_individually = true;
conf.with_delay_update = true;
receiver_pos = [ 3 0 3 ]; % OpenGL coordinates receiver_pos = [ 3 0 3 ]; % OpenGL coordinates
f = ita_ANSI_center_frequencies; f = ita_ANSI_center_frequencies;
...@@ -51,6 +55,7 @@ try ...@@ -51,6 +55,7 @@ try
catch catch
disp( 'Executing dry run because connection to local VA server failed.' )
dry_run = true; dry_run = true;
c = 343; c = 343;
S = -1; S = -1;
...@@ -76,14 +81,11 @@ disp( [ 'Simulation result duration: ' num2str( numsteps * timestep ) ' s' ] ) ...@@ -76,14 +81,11 @@ disp( [ 'Simulation result duration: ' num2str( numsteps * timestep ) ' s' ] )
x = linspace( -1, 1, numsteps ) * 20; % motion from x = -50m to x = 50m x = linspace( -1, 1, numsteps ) * 20; % motion from x = -50m to x = 50m
H_direct_log = []; H_direct_log = []; % Direct field component
H_diffracted_log = []; H_diffracted_log = []; % Diffracted field component
H_reflected_log = []; H_reflected_log = []; % Reflected field component
H_total_field_log = []; H_total_field_log = []; % Superimposed field components
IL_log = []; % Insertion loss IL_log = []; % Insertion loss (total field relative to direct field under free-field condition)
run_data = cell(3,length(x));
all_path_names = {'direct_path', 'diffracted_path', 'reflected_path'};
h = waitbar( 0, 'Hold on, running auralization' ); h = waitbar( 0, 'Hold on, running auralization' );
direct_deleted = false; %set to true when the direct path has been deleted direct_deleted = false; %set to true when the direct path has been deleted
...@@ -104,25 +106,33 @@ for n = 1:length( x ) ...@@ -104,25 +106,33 @@ for n = 1:length( x )
last_shadow_zone = shadow_zone; last_shadow_zone = shadow_zone;
distance = norm( source_pos - receiver_pos ); distance = norm( source_pos - receiver_pos );
H_direct = 1 ./ distance .* exp( -1i .* k .* distance );
prop_path_direct = struct(); prop_path_direct = struct();
prop_path_direct.identifier = 'direct_path'; prop_path_direct.identifier = 'direct_path';
prop_path_direct.gain = 1 / distance;
prop_path_direct.delay = distance / c; %delay from sound emitting from source to being received at listener
prop_path_direct.frequencies = f; %Frequencies corresponding to the mags prop_path_direct.frequencies = f; %Frequencies corresponding to the mags
values = ones(1,31);
prop_path_direct.frequency_magnitudes = values;
prop_path_direct.source = S; %sound source ID prop_path_direct.source = S; %sound source ID
prop_path_direct.receiver = L; %sound receiver ID prop_path_direct.receiver = L; %sound receiver ID
prop_path_direct.delete = false; %set to true when an existing path should be deleted prop_path_direct.delete = false; %set to true when an existing path should be deleted
prop_path_direct.position = source_pos; prop_path_direct.position = source_pos;
if free_field_only
if conf.free_field_only
prop_path_direct.audible = true; % Free field: always audible prop_path_direct.audible = true; % Free field: always audible
else else
prop_path_direct.audible = ~shadow_zone; % Direct field: may be occluded prop_path_direct.audible = ~shadow_zone; % Direct field: may be occluded
end end
H_direct = 1 ./ distance .* exp( -1i .* k .* distance ); if conf.update_gain_individually
prop_path_direct.gain = 1 / distance;
prop_path_direct.frequency_magnitudes = ones( 1, 31 );
else
prop_path_direct.gain = 1;
prop_path_direct.frequency_magnitudes = abs( H_direct );
end
if ~conf.with_delay_update || n == 1
prop_path_direct.delay = distance / c; %delay from sound emitting from source to being received at listener
end
%% Diffracted sound path %% Diffracted sound path
...@@ -138,12 +148,21 @@ for n = 1:length( x ) ...@@ -138,12 +148,21 @@ for n = 1:length( x )
prop_path_diffracted.identifier = 'diffracted_path'; prop_path_diffracted.identifier = 'diffracted_path';
prop_path_diffracted.delete = false; prop_path_diffracted.delete = false;
prop_path_diffracted.position = apex; prop_path_diffracted.position = apex;
prop_path_diffracted.delay = detour / c;
prop_path_diffracted.frequencies = f; prop_path_diffracted.frequencies = f;
prop_path_diffracted.gain = A / rho;
prop_path_diffracted.frequency_magnitudes = abs( D );
prop_path_diffracted.audible = true; prop_path_diffracted.audible = true;
if ~conf.with_delay_update || n == 1
prop_path_diffracted.delay = distance / c;
end
if conf.update_gain_individually
prop_path_diffracted.gain = ( -1 ) * A / rho; % Invert phase
prop_path_diffracted.frequency_magnitudes = abs( D );
else
prop_path_diffracted.gain = -1; % Invert phase
prop_path_diffracted.frequency_magnitudes = abs( H_diffracted );
end
%% Reflected sound path %% Reflected sound path
...@@ -161,38 +180,44 @@ for n = 1:length( x ) ...@@ -161,38 +180,44 @@ for n = 1:length( x )
distance_image = norm( source_pos_image - receiver_pos ); distance_image = norm( source_pos_image - receiver_pos );
prop_path_reflected = struct(); prop_path_reflected = struct();
prop_path_reflected.identifier = 'reflected_path'; prop_path_reflected.identifier = 'reflected_path';
prop_path_reflected.gain = 1 / distance_image;
prop_path_reflected.delay = distance_image / c; %delay from sound emitting from source to being received at listener
prop_path_reflected.frequencies = f; %Frequencies corresponding to the mags prop_path_reflected.frequencies = f; %Frequencies corresponding to the mags
values = ones(1,31);
prop_path_reflected.frequency_magnitudes = values;
prop_path_reflected.source = S; %sound source ID prop_path_reflected.source = S; %sound source ID
prop_path_reflected.receiver = L; %sound receiver ID prop_path_reflected.receiver = L; %sound receiver ID
prop_path_reflected.delete = false; %set to true when an existing path should be deleted prop_path_reflected.delete = false; %set to true when an existing path should be deleted
prop_path_reflected.position = source_pos_image; prop_path_reflected.position = source_pos_image;
prop_path_reflected.audible = reflection_zone; % Reflected field: may be inaudible prop_path_reflected.audible = reflection_zone; % Reflected field: may be inaudible
R = 1; R = 0.7;
H_reflected = R ./ distance_image .* exp( -1i .* k ./ distance_image ); H_reflected = R ./ distance_image .* exp( -1i .* k ./ distance_image );
if conf.update_gain_individually
prop_path_reflected.gain = mean( R ) / distance_image;
prop_path_reflected.frequency_magnitudes = ones( 1, 31 );
else
prop_path_reflected.gain = 1;
prop_path_reflected.frequency_magnitudes = abs( H_reflected );
end
if ~conf.with_delay_update
if n == 1
prop_path_reflected.delay = distance / c; % For all-same delay
end
else
prop_path_reflected.delay = distance_image / c;
end
%% Update wave fronts in renderer %% Update wave fronts in renderer
paths_update = struct(); paths_update = struct();
if free_field_only || direct_field_component if conf.free_field_only || conf.direct_field_component
paths_update.direct_path = prop_path_direct; paths_update.direct_path = prop_path_direct;
end end
if ~free_field_only && diffracted_field_component if ~conf.free_field_only && conf.diffracted_field_component
paths_update.diffracted_path = prop_path_diffracted; paths_update.diffracted_path = prop_path_diffracted;
end end
if ~free_field_only && reflected_field_component if ~conf.free_field_only && conf.reflected_field_component
paths_update.reflected_path = prop_path_reflected; paths_update.reflected_path = prop_path_reflected;
end end
run_data{1,n} = paths_update;
run_data{2,n} = source_pos;
run_data{3,n} = receiver_pos;
if ~dry_run if ~dry_run
rends = va.get_rendering_modules(); rends = va.get_rendering_modules();
...@@ -213,6 +238,9 @@ for n = 1:length( x ) ...@@ -213,6 +238,9 @@ for n = 1:length( x )
waitbar( n / numsteps ) waitbar( n / numsteps )
% Log transfer functions
H_direct_log = [ H_direct_log; H_direct ]; H_direct_log = [ H_direct_log; H_direct ];
H_diffracted_log = [ H_diffracted_log; H_diffracted ]; H_diffracted_log = [ H_diffracted_log; H_diffracted ];
H_reflected_log = [ H_reflected_log; H_reflected ]; H_reflected_log = [ H_reflected_log; H_reflected ];
...@@ -240,5 +268,5 @@ if ~dry_run ...@@ -240,5 +268,5 @@ if ~dry_run
disp( 'Stop VA to export simulation results from rendering module(s)' ) disp( 'Stop VA to export simulation results from rendering module(s)' )
else else
figure figure
plot( db( IL_log ) ) plot( db( H_total_field_log ) )
end end
...@@ -206,6 +206,7 @@ save( 'example_ppa_output_data.mat', 'run_data', 'all_path_names' ); %save varia ...@@ -206,6 +206,7 @@ save( 'example_ppa_output_data.mat', 'run_data', 'all_path_names' ); %save varia
disp('Finished generating path data for every frame. Data is saved in struct "run_data".'); disp('Finished generating path data for every frame. Data is saved in struct "run_data".');
%% Run VA simulation %% Run VA simulation
if ~dry_run if ~dry_run
manual_clock = 0; manual_clock = 0;
......
%% Input conditions %% Input conditions
%target_path = 'path_03eff9730b428fe4b136ffe27c6684a3'; %path to follow through simulation %target_path = 'path_19a0a7019da43b074b372bcbdf6adb25'; %path to follow through simulation
target_path = 'diffracted_path'; target_path = 'path_50df740f16865a987b4b69ff1bb12c2f';
%target_path = 'diffracted_path';
plot_single_path_freq = true; plot_single_path_freq = true;
plot_all_delay_changes = true; plot_all_delay_changes = false;
plot_all_gain_changes = true; plot_all_gain_changes = false;
%load('example_ppa_output_data.mat','-mat'); %load('example_ppa_output_data.mat','-mat');
load('example_outdoor_acoustics_output_data','-mat'); %load('example_outdoor_acoustics_output_data','-mat');
%% Initial set up %% Initial set up
N_frames = size( run_data, 2 ); N_frames = size( run_data, 2 );
...@@ -27,6 +28,7 @@ f = ita_ANSI_center_frequencies; ...@@ -27,6 +28,7 @@ f = ita_ANSI_center_frequencies;
%% Main loop %% Main loop
for n = 1:N_frames %loop over all frames for n = 1:N_frames %loop over all frames
%tic
if plot_single_path_freq if plot_single_path_freq
try try
path = run_data{1,n}.(target_path); path = run_data{1,n}.(target_path);
...@@ -51,6 +53,8 @@ for n = 1:N_frames %loop over all frames ...@@ -51,6 +53,8 @@ for n = 1:N_frames %loop over all frames
end end
end end
%fprintf( 'Took %.2f seconds for fram %i%/i%\n', toc, n, N_frames )
end end
%% Plot Graphs %% Plot Graphs
...@@ -69,7 +73,8 @@ end ...@@ -69,7 +73,8 @@ end
function single_path_freq_evolution( f, N, freq_evolution, valid_evolution ) function single_path_freq_evolution( f, N, freq_evolution, valid_evolution )
[X,Y] = meshgrid(f, 1:N); [X,Y] = meshgrid(f, 1:N);
figure figure
surf( X, Y, freq_evolution, valid_evolution ) s1 = surf( X, Y, freq_evolution, valid_evolution );
set( s1, 'EdgeAlpha', 0.05 );
xlabel('Frequency (KHz)') xlabel('Frequency (KHz)')
ylabel('Frame number') ylabel('Frame number')
zlabel('Frequency Magnitudes') zlabel('Frequency Magnitudes')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment