Commit 5858d436 authored by henryjandrew's avatar henryjandrew
Browse files

changed example_ppa to save data as well as generating. Also only sends...

changed example_ppa to save data as well as generating. Also only sends frequency and gain data to VA for valid paths
parent c7f5cf55
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
% Requires ITA-Toolbox, obtain from http://www.ita-toolbox.org % Requires ITA-Toolbox, obtain from http://www.ita-toolbox.org
record_paths = true;
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory'; ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
if ~exist( ppa_folder, 'dir' ) if ~exist( ppa_folder, 'dir' )
...@@ -56,18 +58,18 @@ catch ...@@ -56,18 +58,18 @@ catch
dry_run = true; dry_run = true;
disp 'No VA client to connect to, starting dry run.' disp 'No VA client to connect to, starting dry run.'
S = -1; S = 0;
R = -1; R = 0;
c = ita_propagation_speed_of_sound_air_approx( 20 ); c = ita_propagation_speed_of_sound_air_approx( 20 );
end end
output_folder = 'example_ppa_out';
all_path_names = cell(1); all_path_names = cell(1);
path_count = 0; %The total number of paths, NOTE -NOT a count of paths in current frame, if paths are deleted, they are not removed from this count path_count = 0; %The total number of paths, NOTE -NOT a count of paths in current frame, if paths are deleted, they are not removed from this count
source_str = struct; source_str = struct; %struct with fields of source ID's and data of source positions for each frame
source_str.ID = S;
receiver_str = struct; receiver_str = struct;
receiver_str.ID = R; all_paths_data = struct;
%% Run synchronized scene update & audio processing simulation/auralization %% Run synchronized scene update & audio processing simulation/auralization
...@@ -110,10 +112,11 @@ for n = n_continue:N %loop over frames ...@@ -110,10 +112,11 @@ for n = n_continue:N %loop over frames
receiver_pos = pps( 1 ).propagation_anchors{ end }.interaction_point; % OpenGL coordinates?! -> transform using receiver_pos = pps( 1 ).propagation_anchors{ end }.interaction_point; % OpenGL coordinates?! -> transform using
end end
source_str.position = source_pos; source_str.(strcat('source_',num2str(S)))(n,:) = source_pos;
receiver_str.position = receiver_pos; receiver_str.(strcat('receiver_',num2str(R)))(n,:) = receiver_pos;
run_data{2,n} = source_str; run_data{2,n} = source_pos;
run_data{3,n} = receiver_str; run_data{3,n} = receiver_pos;
paths_update = struct(); paths_update = struct();
...@@ -140,23 +143,29 @@ for n = n_continue:N %loop over frames ...@@ -140,23 +143,29 @@ for n = n_continue:N %loop over frames
path_count = path_count + 1; path_count = path_count + 1;
all_path_names{path_count} = pp.identifier; all_path_names{path_count} = pp.identifier;
[ frequency_mags, gain, delay, valid_p ] = ita_propagation_path_get_data( pp, f, c); if( record_paths )
[ frequency_mags, gain, delay, valid_p, path_data ] = ita_propagation_path_get_data( pp, f, c, 'record_paths' );
all_paths_data.( strcat( 'path_', pu.identifier ) ) = path_data;
else
[ frequency_mags, gain, delay, valid_p ] = ita_propagation_path_get_data( pp, f, c );
end
%{
if ~valid_p %catch for error in ita_propagation_path_get_data if ~valid_p %catch for error in ita_propagation_path_get_data
warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier ); warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier );
continue continue
end end
%}
pu.gain = gain; if valid_p
pu.delay = delay; pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags); pu.frequency_magnitudes = abs(frequency_mags);
end
pu.frequencies = f; pu.frequencies = f;
pu.delay = delay;
if isa(pp.propagation_anchors, 'struct') if isa(pp.propagation_anchors, 'struct')
pu.position = pp.propagation_anchors( end-1 ).interaction_point( 1:3 ); % next to last anchor pu.position = pp.propagation_anchors( end-1 ).interaction_point( 1:3 ); % next to last anchor
else else
pu.position = pp.propagation_anchors{ end-1 }.interaction_point( 1:3 ); % next to last anchor pu.position = pp.propagation_anchors{ end-1 }.interaction_point( 1:3 ); % next to last anchor
end end
pu.delete = false; pu.delete = false;
pu.audible = true; pu.audible = true;
...@@ -173,36 +182,48 @@ for n = n_continue:N %loop over frames ...@@ -173,36 +182,48 @@ for n = n_continue:N %loop over frames
pu.receiver = R; pu.receiver = R;
pu.identifier = pp.identifier; pu.identifier = pp.identifier;
[ frequency_mags, gain, delay, valid_p ] = ita_propagation_path_get_data( pp, f, c); if( record_paths )
[ frequency_mags, gain, delay, valid_p, path_data ] = ita_propagation_path_get_data( pp, f, c, 'record_paths' );
all_paths_data.( strcat( 'path_', pu.identifier ) ) = path_data;
else
[ frequency_mags, gain, delay, valid_p ] = ita_propagation_path_get_data( pp, f, c );
end
%{
if ~valid_p %catch for error in ita_propagation_path_get_data if ~valid_p %catch for error in ita_propagation_path_get_data
warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier ); warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier );
continue continue
end end
%}
pu.gain = gain; if( valid_p )
pu.delay = delay; pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags); pu.frequency_magnitudes = abs(frequency_mags);
end
pu.frequencies = f; pu.frequencies = f;
pu.delay = delay;
if isa(pp.propagation_anchors, 'struct') if isa(pp.propagation_anchors, 'struct')
pu.position = pp.propagation_anchors( end-1 ).interaction_point( 1:3 ); % next to last anchor pu.position = pp.propagation_anchors( end-1 ).interaction_point( 1:3 ); % next to last anchor
else else
pu.position = pp.propagation_anchors{ end-1 }.interaction_point( 1:3 ); % next to last anchor pu.position = pp.propagation_anchors{ end-1 }.interaction_point( 1:3 ); % next to last anchor
end end
pu.delete = false; pu.delete = false;
pu.audible = true; pu.audible = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu; paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end end
run_data{1,n} = paths_update; %save data to struct if( record_paths )
save(strcat(output_folder,'\frame',num2str(n),'data.mat'), 'paths_update', 'all_paths_data' ); %save current frame data
else
save(strcat(output_folder,'\frame',num2str(n),'data.mat'), 'paths_update'); %save current frame data
end
run_data{1,n} = paths_update;
waitbar( n / N ) waitbar( n / N )
end end
close( h ) close( h )
save( 'example_ppa_output_data.mat', 'run_data', 'all_path_names' ); %save variables to file save( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names', 'source_str', 'receiver_str' ); %save variables to file
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".');
...@@ -214,8 +235,8 @@ if ~dry_run ...@@ -214,8 +235,8 @@ if ~dry_run
for n = n_continue:N for n = n_continue:N
% Update all propagation paths % Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( run_data{2,n}.position(1:3)' ); source_pos_OpenGL = ita_matlab2openGL( run_data{2,n} );
receiver_pos_OpenGL = ita_matlab2openGL( run_data{3,n}.position(1:3)' ); receiver_pos_OpenGL = ita_matlab2openGL( run_data{3,n} );
% Update receiver (last anchor) % Update receiver (last anchor)
va.set_sound_source_position( S, source_pos_OpenGL ); va.set_sound_source_position( S, source_pos_OpenGL );
......
%% Input conditions %% Input conditions
%target_path = 'path_03eff9730b428fe4b136ffe27c6684a3'; %path to follow through simulation target_path = 'path_03eff9730b428fe4b136ffe27c6684a3'; %path to follow through simulation
target_path = 'diffracted_path'; %target_path = 'diffracted_path';
input_folder = 'example_ppa_out';
plot_single_path_freq = true; plot_single_path_freq = true;
plot_single_path = true;
plot_all_delay_changes = true; plot_all_delay_changes = true;
plot_all_gain_changes = true; plot_all_gain_changes = true;
%load('example_ppa_output_data.mat','-mat'); load(strcat(input_folder,'\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 ); file_listing = dir( strcat( input_folder, '/*.mat' ) );
N_frames = numel(file_listing) - 1;
N_paths = numel(all_path_names); N_paths = numel(all_path_names);
if plot_single_path_freq if plot_single_path_freq
freq_evolution = zeros(N_frames,31); freq_evolution = zeros(N_frames,31);
valid_evolution = zeros(N_frames,31); valid_evolution = zeros(N_frames,31);
end end
if plot_single_path
path_data = cell(1, N_paths);
end
if plot_all_delay_changes if plot_all_delay_changes
delay_changes = zeros(N_frames, N_paths); delay_changes = zeros(N_frames, N_paths);
prev_delay = zeros(1,N_paths); prev_delay = zeros(1,N_paths);
path_altered = zeros(1,N_paths);
end end
if plot_all_gain_changes if plot_all_gain_changes
gain_changes = zeros(N_frames, N_paths); gain_changes = zeros(N_frames, N_paths);
...@@ -27,11 +35,15 @@ f = ita_ANSI_center_frequencies; ...@@ -27,11 +35,15 @@ 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
if plot_single_path_freq load(strcat(input_folder,'\frame',num2str(n),'data.mat'),'-mat'); %load path data for the next frame
if plot_single_path_freq || plot_single_path
try try
path = run_data{1,n}.(target_path); path = paths_update.(target_path);
freq_evolution(n,:) = path.frequency_magnitudes; freq_evolution(n,:) = path.frequency_magnitudes;
valid_evolution(n,:) = path.audible; valid_evolution(n,:) = path.audible;
path_data{n} = all_paths_data.(target_path);
catch catch
freq_evolution(n,:) = zeros(1,31); freq_evolution(n,:) = zeros(1,31);
valid_evolution(n,:) = zeros(1,31); valid_evolution(n,:) = zeros(1,31);
...@@ -40,12 +52,18 @@ for n = 1:N_frames %loop over all frames ...@@ -40,12 +52,18 @@ for n = 1:N_frames %loop over all frames
if plot_all_delay_changes || plot_all_gain_changes if plot_all_delay_changes || plot_all_gain_changes
for p = 1:N_paths for p = 1:N_paths
try try
path = run_data{1,n}.(all_path_names{p}); path = paths_update.(all_path_names{p});
delay_changes(n,p) = path.delay - prev_delay(p); if( path_altered(p) == 1 )
prev_delay(p) = path.delay; delay_changes(n,p) = path.delay - prev_delay(p);
prev_delay(p) = path.delay;
gain_changes(n,p) = path.gain - prev_gain(p);
prev_gain(p) = path.gain; gain_changes(n,p) = path.gain - prev_gain(p);
prev_gain(p) = path.gain;
else
path_altered(p) = 1;
prev_delay(p) = path.delay;
prev_gain(p) = path.gain;
end
catch catch
end end
...@@ -54,14 +72,17 @@ for n = 1:N_frames %loop over all frames ...@@ -54,14 +72,17 @@ for n = 1:N_frames %loop over all frames
end end
%% Plot Graphs %% Plot Graphs
if plot_single_path
visualise_single_path( path_data );
end
if plot_single_path_freq if plot_single_path_freq
single_path_freq_evolution( f, N_frames, freq_evolution, valid_evolution ); single_path_freq_evolution( f, N_frames, freq_evolution, valid_evolution );
end end
if plot_all_delay_changes if plot_all_delay_changes
all_path_delay_changes( delay_changes(2:end,:), N_paths, N_frames-1 ); all_path_delay_changes( delay_changes, N_paths, N_frames );
end end
if plot_all_gain_changes if plot_all_gain_changes
all_path_gain_changes( gain_changes(2:end,:), N_paths, N_frames-1 ); all_path_gain_changes( gain_changes, N_paths, N_frames );
end end
...@@ -69,7 +90,10 @@ end ...@@ -69,7 +90,10 @@ 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 ) a = axes;
s = surf( a, X, Y, freq_evolution, valid_evolution );
set( a, 'ZScale', 'log' );
set( s, 'EdgeAlpha', 0.05 );
xlabel('Frequency (KHz)') xlabel('Frequency (KHz)')
ylabel('Frame number') ylabel('Frame number')
zlabel('Frequency Magnitudes') zlabel('Frequency Magnitudes')
...@@ -79,9 +103,11 @@ end ...@@ -79,9 +103,11 @@ end
function all_path_delay_changes( delay_changes, N_paths, N_frames ) function all_path_delay_changes( delay_changes, N_paths, N_frames )
[X,Y] = meshgrid(1:N_paths, 1:N_frames); [X,Y] = meshgrid(1:N_paths, 1:N_frames);
figure figure
surf( X, Y, delay_changes) a = axes;
xlabel('Frames') s = surf( a, X, Y, delay_changes);
ylabel('Paths') set( s, 'EdgeAlpha', 0.05 );
ylabel('Frames')
xlabel('Paths')
zlabel('Delay Change') zlabel('Delay Change')
grid off grid off
end end
...@@ -89,9 +115,17 @@ end ...@@ -89,9 +115,17 @@ end
function all_path_gain_changes( gain_changes, N_paths, N_frames ) function all_path_gain_changes( gain_changes, N_paths, N_frames )
[X,Y] = meshgrid(1:N_paths, 1:N_frames); [X,Y] = meshgrid(1:N_paths, 1:N_frames);
figure figure
surf( X, Y, gain_changes) a = axes;
xlabel('Frames') s = surf( a, X, Y, gain_changes);
ylabel('Paths') set( s, 'EdgeAlpha', 0.05 );
ylabel('Frames')
xlabel('Paths')
zlabel('Gain Change') zlabel('Gain Change')
grid off grid off
end
function visualise_single_path( path_data )
figure
a = axes;
end end
\ No newline at end of file
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