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

WIP

parent 5d09fd91
......@@ -6,280 +6,274 @@
% Requires ITA-Toolbox, obtain from http://www.ita-toolbox.org
output_folder = 'example_ppa_out';
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';
S = 1;
R = 1;
ppa_example_mode = questdlg( 'Please select', 'VA example ppa mode selection', ...
'simulation', 'auralization', 'both', 'both');
'simulation', 'auralization', 'both', 'auralization');
switch ppa_example_mode
case { 'simulation', 'both' }
%% Prepare run data
record_paths = true;
ppa_diffraction_model = 'utd';
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
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 )
%% Prepare run data
if any( strcmpi( ppa_example_mode, { 'simulation', 'both' } ) )
if ~exist( output_folder, 'dir' )
mkdir( output_folder )
end
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
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;
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;
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 );
pps = ita_propagation_load_paths( ppa_file_path ); %pps = struct containing the current time frame
pps = ita_propagation_paths_add_identifiers( pps );
if n == n_continue
pps_new = pps;
pps_del = [];
pps_common = [];
else
[ pps_new, pps_del, pps_common ] = ita_propagation_paths_diff( pps_last, pps );
end
pps_last = pps;
file_listing = dir( strcat( ppa_folder, '/*.json' ) );
f = ita_ANSI_center_frequencies;
c = 343;
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;
% Update source (first anchor)
if isa( pps( 1 ).propagation_anchors, 'struct' )
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
else
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
N = numel( file_listing );
disp( [ 'Simulation result duration: ' num2str( N * frame_rate ) ' s' ] )
paths_update = struct();
h = waitbar( 0, 'Hold on, running simulation of path data for each frame' );
% Delete non-available paths
for p = 1:numel( pps_del )
pu = struct(); % Path update
pu.source = S;
pu.receiver = R;
pu.identifier = pps_del( p ).identifier;
pu.delete = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end
% Iterate over frames
n_continue = 1;
for n = n_continue:N %loop over frames
all_path_name = [];
path_number = 1;
for p = 1:numel( pps_new )
% Load propagation paths for current frame
ppa_file_path = fullfile( file_listing( n ).folder, file_listing( n ).name );
pps = ita_propagation_load_paths( ppa_file_path ); %pps = struct containing the current time frame
pps = ita_propagation_paths_add_identifiers( pps );
pp = pps_new( p ); % Propagation path
pu = struct(); % Path update
if n == n_continue
pps_new = pps;
pps_del = [];
pps_common = [];
else
[ pps_new, pps_del, pps_common ] = ita_propagation_paths_diff( pps_last, pps );
end
pps_last = pps;
% Assemble DSP settings (gain, delay & filter coefficients)
pu.source = S;
pu.receiver = R;
pu.identifier = pp.identifier;
path_count = path_count + 1;
all_path_names{path_count} = pp.identifier;
% Update source (first anchor)
if isa( pps( 1 ).propagation_anchors, 'struct' )
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
if( 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
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
[ frequency_mags, gain, delay, valid_path ] = ita_propagation_path_get_data( pp, f, c );
end
source_str.(strcat('source_',num2str(S))) = source_pos;
receiver_str.(strcat('receiver_',num2str(R))) = receiver_pos;
paths_update = struct();
% Delete non-available paths
for p = 1:numel( pps_del )
pu = struct(); % Path update
pu.source = S;
pu.receiver = R;
pu.identifier = pps_del( p ).identifier;
pu.delete = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
if valid_path
pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags);
end
for p = 1:numel( pps_new )
pp = pps_new( p ); % Propagation path
pu = struct(); % Path update
% Assemble DSP settings (gain, delay & filter coefficients)
pu.source = S;
pu.receiver = R;
pu.identifier = pp.identifier;
path_count = path_count + 1;
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' );
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
end
%}
if valid_p
pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags);
end
pu.frequencies = f;
pu.delay = delay;
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
end
pu.delete = false;
pu.audible = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
pu.frequencies = f;
pu.delay = delay;
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
end
pu.delete = false;
pu.audible = true;
for p = 1:numel( pps_common )
pp = pps_common( p ); % Propagation path
pu = struct(); % Path update
% Assemble DSP settings (gain, delay & filter coefficients)
pu.source = S;
pu.receiver = R;
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' );
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
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end
%}
if( valid_p )
pu.gain = gain;
pu.frequency_magnitudes = abs(frequency_mags);
end
pu.frequencies = f;
pu.delay = delay;
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
end
pu.delete = false;
pu.audible = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end
for p = 1:numel( pps_common )
pp = pps_common( p ); % Propagation path
pu = struct(); % Path update
% Assemble DSP settings (gain, delay & filter coefficients)
pu.source = S;
pu.receiver = R;
pu.identifier = pp.identifier;
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
if( record_paths )
save( file_path, 'all_paths_data', '-append' );
[ 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_path ] = ita_propagation_path_get_data( pp, f, c );
end
waitbar( n / N )
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' )
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
end
pu.delete = false;
pu.audible = true;
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end
close( h )
save( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names' ); %save variables to file
disp('Finished generating path data for every frame. Data is saved in struct "run_data".');
case { 'auralization', 'both' }
%% Run auralization
% Load data
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 )
file_name = sprintf( 'frame%04idata.mat', n );
file_path = fullfile( output_folder, file_name );
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 )
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 );
end
%% Run auralization
if any( strcmpi( ppa_example_mode, { 'auralization', 'both' } ) )
% Load data
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 );
load( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names' )
load( 'example_ppa_out\example_ppa_output_data.mat', 'source_str' )
load( 'example_ppa_out\example_ppa_output_data.mat', 'receiver_str' )
% Set up VA scene
va = VA;
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' );
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 );
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' );
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' );
% Run auralization update loop
for n = 1:N
idx_current = idx( n );
load( fullfile( output_folder, file_listing( idx_current ).name ), '-mat' ); % makes paths_update available
source_pos = source_str.(strcat('source_',num2str(S-1)));
receiver_pos = receiver_str.(strcat('receiver_',num2str(R-1)));
% Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( source_pos( 1:3 ) );
receiver_pos_OpenGL = ita_matlab2openGL( receiver_pos( 1:3 ) );
% Update receiver (last anchor)
va.set_sound_source_position( S, source_pos_OpenGL );
va.set_sound_receiver_position( R, receiver_pos_OpenGL );
if isfield( paths_update, 'path_003ca6d3a74540310873574908219251' )
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', paths_update );
else
disp( 'not found, skipping update' )
end
% Increment core clock
manual_clock = manual_clock + frame_rate;
va.call_module( 'manualclock', struct( 'time', manual_clock ) );
% Process audio chain by incrementing one block
va.call_module( 'virtualaudiodevice', struct( 'trigger', true ) );
waitbar( n / N )
else
idx = 1:N;
end
% Set up VA scene
va = VA;
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( 'C:\Users\jonas\sciebo\Thesis stuff\auralization\resources' );
c = va.get_homogeneous_medium_sound_speed();
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( '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 )
manual_clock = 0;
va.set_core_clock( 0 );
h = waitbar( 0, 'Hold on, running auralisation using generated data' );
% 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' );
% Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( source_pos( 1:3 )' );
receiver_pos_OpenGL = ita_matlab2openGL( receiver_pos( 1:3 )' );
% Update receiver (last anchor)
va.set_sound_source_position( S, source_pos_OpenGL );
va.set_sound_receiver_position( R, receiver_pos_OpenGL );
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
close( h )
% Increment core clock
manual_clock = manual_clock + frame_rate;
va.call_module( 'manualclock', struct( 'time', manual_clock ) );
% Process audio chain by incrementing one block
va.call_module( 'virtualaudiodevice', struct( 'trigger', true ) );
va.disconnect
disp( 'Stop VA to export simulation results from rendering module(s)' )
waitbar( n / N )
end
\ No newline at end of file
end
close( h )
va.disconnect
disp( 'Stop VA to export simulation results from rendering module(s)' )
end
%% 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