WIP

parent d34e4774
......@@ -9,6 +9,7 @@
record_paths = true;
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
output_folder = 'example_ppa_out';
if ~exist( ppa_folder, 'dir' )
ppa_folder = '../../../ITAGeometricalAcoustics/ITAPropagationPathSim/tests/CombinedModel/UrbanTrajectory';
......@@ -17,63 +18,24 @@ end
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
%% Preps
%% Prepare run data
file_listing = dir( strcat( ppa_folder, '/*.json' ) );
f = ita_ANSI_center_frequencies;
%% VA
va = VA;
try
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 )
catch
dry_run = true;
disp 'No VA client to connect to, starting dry run.'
S = 0;
R = 0;
c = ita_propagation_speed_of_sound_air_approx( 20 );
end
output_folder = 'example_ppa_out';
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;
%% Run synchronized scene update & audio processing simulation/auralization
frame_rate = 128 / 44100; % here: depends on block size and sample rate
N = numel( file_listing );
disp( [ 'Simulation result duration: ' num2str( N * frame_rate ) ' s' ] )
......@@ -211,10 +173,13 @@ for n = n_continue:N %loop over frames
paths_update.( strcat( 'path_', pu.identifier ) ) = pu;
end
file_name = sprintf( 'frame%04idata.mat', n );
file_path = fullfile( output_folder, file_name );
save( file_path, 'paths_update' ); %save current frame data
save( file_path, 'S', 'R', '-append' );
save( file_path, 'source_pos', 'receiver_pos', '-append' );
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
save( file_path, 'all_paths_data', '-append' );
end
run_data{1,n} = paths_update;
......@@ -228,40 +193,79 @@ save( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names', 'source_s
disp('Finished generating path data for every frame. Data is saved in struct "run_data".');
%% Run VA simulation
if ~dry_run
manual_clock = 0;
va.set_core_clock( 0 );
h = waitbar( 0, 'Hold on, running auralisation using generated data' );
%% Run auralization
for n = n_continue:N
% Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( run_data{2,n} );
receiver_pos_OpenGL = ita_matlab2openGL( run_data{3,n} );
% Update receiver (last anchor)
va.set_sound_source_position( S, source_pos_OpenGL );
va.set_sound_receiver_position( R, receiver_pos_OpenGL );
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', run_data{1,n} );
% Increment core clock
manual_clock = manual_clock + frame_rate;
va.call_module( 'manualclock', struct( 'time', manual_clock ) );
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 )
frame_datenums = [];
for n=1:N
frame_datenums = [ frame_datenums file_listing( n ).datenum ];
end
[ ~, idx ] = sort( frame_datenums );
load( 'example_ppa_out\example_ppa_output_data.mat', 'all_path_names', 'source_str', 'receiver_str' )
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 );
% Process audio chain by incrementing one block
va.call_module( 'virtualaudiodevice', struct( 'trigger', true ) );
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' );
for n = 1:N
waitbar( n / N )
end
idx_current = idx( n );
frame_data = load( fullfile( output_folder, file_listing( idx_current ).name ) );
close( h )
end
path_ids = fieldnames( frame_data.paths_update );
source_pos = source_str.source_0( n, 1:3 );
% Update all propagation paths
source_pos_OpenGL = ita_matlab2openGL( source_pos );
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 );
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', frame_data.paths_update );
% 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 )
if va.get_connected
va.disconnect
end
va.disconnect
disp( 'Stop VA to export simulation results from rendering module(s)' )
......
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