Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

VA_example_offline_simulation.m 1.82 KB
Newer Older
1
%% VA offline simulation/auralization example
2 3 4 5 6

% 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.

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
7 8 9
buffer_size = 64;
sampling_rate = 44100;

10 11

%% Connect and set up simple scene
12
va = VA( 'localhost' );
13

14
L = va.create_sound_receiver( 'VA_Listener' );
15 16 17 18
va.set_sound_receiver_position( L, [ 0 1.7 0 ] )
H = va.create_directivity( '$(DefaultHRIR)' );
va.set_sound_receiver_directivity( L, H );

19
S = va.create_sound_source( 'VA_Source' );
20 21 22 23 24 25 26 27
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

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
28
timestep = buffer_size / sampling_rate; % here: depends on block size and sample rate
29
manual_clock = 0;
30
va.set_core_clock( 0 );
31

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
32
spatialstep = 0.005;
33 34
disp( [ 'Resulting sound source speed: ' num2str( spatialstep / timestep ) ' m/s' ] )

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
35
numsteps = 6000;
36 37
disp( [ 'Simulation result duration: ' num2str( numsteps * timestep ) ' s' ] )

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
38
x = linspace( -1, 1, numsteps ) * 60; % motion from x = -100m to x = 100m
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

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 )

va.disconnect

Dipl.-Ing. Jonas Stienen's avatar
WIP  
Dipl.-Ing. Jonas Stienen committed
60
disp( '!!! Please stop VA manually to export simulation results from rendering module(s) !!!' )