Adding example script for offline simulation and auralization using VA and Matlab

parent a0e2d06c
%% itaVA offline simulation/auralization example
% Requires VA to run with a virtual audio device that can be triggered by
% the user. Also the rendering module(s) have to be set to record the output
% to hard drive.
%% Connect and set up simple scene
va = itaVA( 'localhost' );
L = va.create_sound_receiver( 'itaVA_Listener' );
va.set_sound_receiver_position( L, [ 0 1.7 0 ] )
H = va.create_directivity( '$(DefaultHRIR)' );
va.set_sound_receiver_directivity( L, H );
S = va.create_sound_source( 'itaVA_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 )
%% Example for a synchronized scene update & audio processing simulation/auralization
timestep = 128 / 44100; % here: depends on block size and sample rate
manual_clock = 0;
spatialstep = 0.01;
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 ) * 100; % motion from x = -200m to x = 200m
h = waitbar( 0, 'Hold on, running auralization' );
for n = 1:length( x )
% Modify scene as you please
va.set_sound_source_position( S, [ x( n ) 1.7 -3 ] );
% 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 )
% Temporary workaround
va.set_rendering_module_parameters( 'MyBinauralFreeField', struct( 'prepare_manual_reset', true ) );
va.set_core_clock( 0 )
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