Commit 56f8803e authored by henryjandrew's avatar henryjandrew
Browse files

Adding lock / unlock in VA update to trigger cluster update at the right time

parents 096bc409 47ee54b9
......@@ -6,48 +6,55 @@
% Requires ITA-Toolbox, obtain from http://www.ita-toolbox.org
output_folder = fullfile( 'C:\Users\jonas\sciebo\Thesis stuff\auralization\resources', 'example_ppa/s1_r1' );
frame_rate = 128 / 44100; % block length / sampling frequency
sort_by_date = false;
record_paths = true;
ppa_diffraction_model = 'utd';
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
output_folder = 'example_ppa_out';
S = 1;
R = 1;
if ~exist( ppa_folder, 'dir' )
ppa_folder = '../../../ITAGeometricalAcoustics/ITAPropagationPathSim/tests/CombinedModel/UrbanTrajectory';
end
ppa_example_mode = questdlg( 'Please select', 'VA example ppa mode selection', ...
'simulation', 'auralization', 'both', 'auralization');
if ~exist( ppa_folder, 'dir' )
error( 'Could not find trajectory source folder "%s".', ppa_folder )
end
ppa_diffraction_model = 'utd';
frame_rate = 128 / 44100; % here: depends on block size and sample rate
%% Prepare run data
if any( strcmpi( ppa_example_mode, { 'simulation', 'both' } ) )
file_listing = dir( strcat( ppa_folder, '/*.json' ) );
if ~exist( output_folder, 'dir' )
mkdir( output_folder )
end
f = ita_ANSI_center_frequencies;
c = 343;
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
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
source_str = struct; %struct with fields of source ID's and data of source positions for each frame
receiver_str = struct;
all_paths_data = struct;
S = 1;
R = 1;
if ~exist( ppa_folder, 'dir' )
ppa_folder = '../../../ITAGeometricalAcoustics/ITAPropagationPathSim/tests/CombinedModel/UrbanTrajectory';
end
if ~exist( ppa_folder, 'dir' )
error( 'Could not find trajectory source folder "%s".', ppa_folder )
end
file_listing = dir( strcat( ppa_folder, '/*.json' ) );
f = ita_ANSI_center_frequencies;
c = 343;
N = numel( file_listing );
disp( [ 'Simulation result duration: ' num2str( N * frame_rate ) ' s' ] )
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
all_paths_data = struct;
h = waitbar( 0, 'Hold on, running simulation of path data for each frame' );
% Iterate over frames
n_continue = 1;
for n = n_continue:N %loop over frames
all_path_name = [];
path_number = 1;
N = numel( file_listing );
disp( [ 'Simulation result duration: ' num2str( N * frame_rate ) ' s' ] )
h = waitbar( 0, 'Hold on, running simulation of path data for each frame' );
% Iterate over frames
n_continue = 1;
for n = n_continue:N
% Load propagation paths for current frame
ppa_file_path = fullfile( file_listing( n ).folder, file_listing( n ).name );
......@@ -72,8 +79,6 @@ for n = n_continue:N %loop over frames
source_pos = pps( 1 ).propagation_anchors{ 1 }.interaction_point(1:3); % OpenGL coordinates?! -> transform using
receiver_pos = pps( 1 ).propagation_anchors{ end }.interaction_point(1:3); % OpenGL coordinates?! -> transform using
end
source_str.(strcat('source_',num2str(S))) = source_pos;
receiver_str.(strcat('receiver_',num2str(R))) = receiver_pos;
paths_update = struct();
......@@ -101,18 +106,13 @@ for n = n_continue:N %loop over frames
all_path_names{path_count} = pp.identifier;
if( record_paths )
[ frequency_mags, gain, delay, valid_p, path_data ] = ita_propagation_path_get_data( pp, f, c, 'record_paths' );
[ frequency_mags, gain, delay, valid_path, 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
warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier );
continue
[ frequency_mags, gain, delay, valid_path ] = ita_propagation_path_get_data( pp, f, c );
end
%}
if valid_p
if valid_path
pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags);
end
......@@ -140,24 +140,19 @@ for n = n_continue:N %loop over frames
pu.identifier = pp.identifier;
if( record_paths )
[ frequency_mags, gain, delay, valid_p, path_data ] = ita_propagation_path_get_data( pp, f, c, 'record_paths' );
[ frequency_mags, gain, delay, valid_path, 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
warning( 'Error in ita_propagation_path_get_data, found invalid path ''%s'', skipping', pp.identifier );
continue
[ frequency_mags, gain, delay, valid_path ] = ita_propagation_path_get_data( pp, f, c );
end
%}
if( valid_p )
if valid_path
pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags);
end
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
else
pu.position = pp.propagation_anchors{ end-1 }.interaction_point( 1:3 ); % next to last anchor
......@@ -170,74 +165,88 @@ for n = n_continue:N %loop over frames
file_name = sprintf( 'frame%04idata.mat', n );
file_path = fullfile( output_folder, file_name );
save( file_path, 'paths_update', 'source_str', 'receiver_str' ); %save current frame data
save( file_path, 'paths_update', 'source_pos', 'receiver_pos' ); % save current frame data
if( record_paths )
save( file_path, 'all_paths_data', '-append' );
end
waitbar( n / N )
end
close( h )
save( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names' ); %save variables to file
end
close( h )
if record_paths
save( fullfile( output_folder, 'analysis_data.mat' ), 'all_path_names' ) %save variables to file
end
fprintf( 'Finished generating path data for every frame. Data is saved into separate files in folder ''%s''\n', output_folder );
disp('Finished generating path data for every frame. Data is saved in struct "run_data".');
end
%% Run auralization
if any( strcmpi( ppa_example_mode, { 'auralization', 'both' } ) )
file_listing = dir( strcat( output_folder, '/frame*data.mat' ) );
N = numel( file_listing );
fprintf( 'Found data on %i frames in folder ''%s''\n', N, output_folder )
% Load data
frame_datenums = [];
for n=1:N
frame_datenums = [ frame_datenums file_listing( n ).datenum ];
end
[ ~, idx ] = sort( frame_datenums );
file_listing = dir( strcat( output_folder, '/frame*data.mat' ) );
N = numel( file_listing );
fprintf( 'Found data on %i frames in folder ''%s''\n', N, output_folder )
if sort_by_date
frame_datenums = zeros( N, 1 );
for n=1:N
frame_datenums( n ) = file_listing( n ).datenum;
end
[ ~, idx ] = sort( frame_datenums );
else
idx = 1:N;
end
load( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names' )
% Set up VA scene
va = VA;
va = VA;
va.connect;
dry_run = false;
va.connect;
dry_run = false;
va.add_search_path( 'D:/Users/andrew/dev/ITASuite/VA/VACore/data' );
va.add_search_path( 'D:/Users/andrew/dev/ITASuite/VA/VAMatlab/matlab' );
va.add_search_path( 'C:/dev/VA/VACore/data' );
va.add_search_path( 'D:/Users/stienen/dev/VA/VACore/data' );
va.add_search_path( 'C:\ITASoftware\Raven\RavenDatabase\SoundDatabase' );
va.add_search_path( 'D:/Users/andrew/dev/ITASuite/VA/VACore/data' );
va.add_search_path( 'D:/Users/andrew/dev/ITASuite/VA/VAMatlab/matlab' );
va.add_search_path( 'C:/dev/VA/VACore/data' );
va.add_search_path( 'D:/Users/stienen/dev/VA/VACore/data' );
va.add_search_path( 'C:\ITASoftware\Raven\RavenDatabase\SoundDatabase' );
va.add_search_path( 'C:\Users\jonas\sciebo\Thesis stuff\auralization\resources' );
c = va.get_homogeneous_medium_sound_speed();
c = va.get_homogeneous_medium_sound_speed();
R = va.create_sound_receiver( 'PPA_sensor' );
H = va.create_directivity_from_file( 'ITA_Artificial_Head_5x5_44kHz_128.v17.ir.daff' );
va.set_sound_receiver_directivity( R, H );
R = va.create_sound_receiver( 'PPA_sensor' );
H = va.create_directivity_from_file( 'ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.v17.ir.daff' );
va.set_sound_receiver_directivity( R, H );
S = va.create_sound_source( 'PPA_emitter' );
%X = va.create_signal_source_buffer_from_file( 'WelcomeToVA.wav' );
X = va.create_signal_source_buffer_from_file( 'LKW Leerlauf 2.wav' );
S = va.create_sound_source( 'PPA_emitter' );
X = va.create_signal_source_buffer_from_file( 'LKW Leerlauf 2.wav' );
va.set_signal_source_buffer_playback_action( X, 'play' )
va.set_signal_source_buffer_looping( X, true );
va.set_sound_source_signal_source( S, X )
va.set_signal_source_buffer_playback_action( X, 'play' )
va.set_signal_source_buffer_looping( X, true );
va.set_sound_source_signal_source( S, X )
manual_clock = 0;
va.set_core_clock( 0 );
h = waitbar( 0, 'Hold on, running auralisation using generated data' );
manual_clock = 0;
va.set_core_clock( 0 );
h = waitbar( 0, 'Hold on, running auralisation using generated data' );
for n = 1:N
% Run auralization update loop
for n = 1:N
idx_current = idx( n );
% Make source_pos, receiver_pos and paths_update available for this
% frame
load( fullfile( output_folder, file_listing( idx_current ).name ), '-mat' );
source_pos = source_str.(strcat('source_',num2str(S)));
receiver_pos = receiver_str.(strcat('receiver_',num2str(R)));
% Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( source_pos' );
receiver_pos_OpenGL = ita_matlab2openGL( receiver_pos' );
source_pos_OpenGL = ita_matlab2openGL( source_pos( 1:3 )' );
receiver_pos_OpenGL = ita_matlab2openGL( receiver_pos( 1:3 )' );
va.lock_update
......@@ -245,7 +254,13 @@ for n = 1:N
va.set_sound_source_position( S, source_pos_OpenGL );
va.set_sound_receiver_position( R, receiver_pos_OpenGL );
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', paths_update );
single_path_id = 'path_003ca6d3a74540310873574908219251';
if isfield( paths_update, single_path_id )
single_path_update = struct( 'p', paths_update.( single_path_id ) );
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', single_path_update );
else
disp( 'not found, skipping update' )
end
va.unlock_update
......@@ -258,45 +273,11 @@ for n = 1:N
waitbar( n / N )
end
va.disconnect
disp( 'Stop VA to export simulation results from rendering module(s)' )
end
close( h )
%%
function path_name = get_path( path_struct )
path_data = path_struct.propagation_anchors;
num_interactions = numel( path_data );
path_name = '';
for i = 1:num_interactions
if isa( path_data, 'struct' )
t = path_data(i);
else
t = path_data{i};
end
switch t.anchor_type
case 'source'
ID = t.name;
path_name = strcat( path_name, 'SRC', num2str(ID), '_' );
case 'receiver'
ID = t.name;
path_name = strcat( path_name, 'RCVR', num2str(ID) );
case 'specular_reflection'
ID = t.polygon_id;
path_name = strcat( path_name, 'SR', num2str(ID), '_' );
case 'outer_edge_diffraction'
ID1 = t.main_wedge_face_id;
ID2 = t.opposite_wedge_face_id;
path_name = strcat( path_name, 'EDMF', num2str(ID1), 'OF', num2str(ID2), '_' );
end
end
end
va.disconnect
disp( 'Stop VA to export simulation results from rendering module(s)' )
%{
function absorption = readMaterial(name)
path = 'C:\ITASoftware\Raven\RavenDatabase\MaterialDatabase';
data = dlmread( fullfile(path,name), ',' );
end
%}
\ No newline at end of file
%% Input conditions
target_path = 'path_03eff9730b428fe4b136ffe27c6684a3'; %path to follow through simulation
target_path = 'path_50df740f16865a987b4b69ff1bb12c2f'; %path to follow through simulation
%target_path = 'diffracted_path';
input_folder = 'example_ppa_out';
input_folder = 'example_ppa\s1_r1';
out_filename = 'Path_evolution.gif';
out_filename_freq = 'Path_evolution_freq.gif';
plot_single_path_freq = true;
plot_single_path = true;
plot_all_delay_changes = false;
plot_all_gain_changes = false;
load(strcat(input_folder,'\example_ppa_output_data.mat'),'-mat');
%load('example_outdoor_acoustics_output_data','-mat');
load( fullfile( input_folder, 'analysis_data.mat'), '-mat' );
%% Initial set up
file_listing = dir( strcat( input_folder, '/*.mat' ) );
file_listing = dir( strcat( input_folder, '/frame*data.mat' ) );
N_frames = numel(file_listing) - 1;
N_paths = numel(all_path_names);
......
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