Adding outdoor acoustics example / test that transmitts propagation path...

Adding outdoor acoustics example / test that transmitts propagation path information via parameter setter of the outdoor noise renderer
parent da1e3dbd
%% VA offline simulation/auralization example for an outdoor noise scenario
% Requires VA to run with a virtual audio device that can be triggered by
% the user. Also the generic path prototype rendering module(s) has to record the output
% to hard drive.
%% Connect and set up simple scene
va = VA( 'localhost' );
c = va.get_homogeneous_medium_sound_speed();
f = ita_ANSI_center_frequencies;
L = va.create_sound_receiver( 'VA_Listener' );
receiver_pos = [ 2 1.7 0 ]; % OpenGL coordinates
va.set_sound_receiver_position( L, receiver_pos )
H = va.create_directivity_from_file( '$(DefaultHRIR)' );
va.set_sound_receiver_directivity( L, H );
S = va.create_sound_source( 'VA_Source' );
X = va.create_signal_source_buffer_from_file( '$(DemoSound)' );
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 )
% House corner
w = itaFiniteWedge( [ 1 0 0 ], [ 0 0 -1 ], [ 0 -2 0 ], 4 ); % OpenGL coordinates
%% Example for a synchronized scene update & audio processing simulation/auralization
timestep = 128 / 44100; % here: depends on block size and sample rate
manual_clock = 0;
va.set_core_clock( 0 );
spatialstep = 0.1;
disp( [ 'Resulting sound source speed: ' num2str( spatialstep / timestep ) ' m/s' ] )
numsteps = 3400;
disp( [ 'Simulation result duration: ' num2str( numsteps * timestep ) ' s' ] )
x = linspace( -1, 1, numsteps ) * 50; % motion from x = -5m to x = 5m
h = waitbar( 0, 'Hold on, running auralization' );
for n = 1:length( x )
% Modify scene as you please (position has no real effect for prototype generic path renderer)
source_pos = [ x( n ) 1.1 -3 ]; % OpenGL coordinates
distance = sum( abs( source_pos - receiver_pos ) );
va.set_sound_source_position( S, source_pos );
% Manually create direct sound path and diffracted sound path
prop_path_direct = struct();
prop_path_direct.distance = distance;
prop_path_direct.delay = distance / c;
prop_path_direct.frequencies = f;
if ita_diffraction_shadow_zone( w, source_pos, receiver_pos )
prop_path.values = zeros( 1, numel( f ) );
else
prop_path.values = ones( 1, numel( f ) );
end
apex = w.get_aperture_point( source_pos, receiver_pos );
detour = norm( source_pos - apex ) + norm(apex - receiver_pos );
prop_path_diffracted = struct();
prop_path_diffracted.distance = detour;
prop_path_diffracted.delay = detour / c;
prop_path_diffracted.frequencies = f;
prop_path.values = ita_diffraction_utd( w, source_pos, receiver_pos, f, c );
% @todo at some point: load all paths from pre-calculated simulation -> ITAPropagationPathSim (C++) output
% Update wave fronts in renderer
path_update = struct();
path_update.source = S;
path_update.receiver = L;
path_update.prop_path_1 = prop_path_direct;
path_update.prop_path_2 = prop_path_diffracted;
va.set_rendering_module_parameters( 'MyBinauralOutdoorNoise', path_update );
% Increment core clock
manual_clock = manual_clock + timestep;
va.call_module( 'manualclock', struct( 'time', manual_clock ) );
% Process audio chain by incrementing one block
va.call_module( 'virtualaudiodevice', struct( 'trigger', true ) );
waitbar( n / numsteps )
end
close( h )
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