classdef itaVA < handle %ITAVA Remote network interface to VA (Virtual Acoustics), the real-time %auralization software made by ITA. % % This class realizes a remote connection to a VA real-time % auralization server and implements the full VA core interface % in Matlab. You can connect to to the server % and control all of its features to perform real-time % auralization, including live tracking if available. % In order to get understand to the concepts behind VA % please refer to the VA documentation or have a look at the example scripts. % % See also: itaVA_example_simple, itaVA_example_tracked_listener, % itaVA_example_generic_path_renderer, itaVA_example_random_numbers % % Quick usage: % % - Create an interface and connect to the server running on the % same computer (localhost) % % va = itaVA; % va.connect; % % If no error occurs, you can then use the interface to work with % the VA server. % % Now, you can call other methods. For instance create a sound % source: % % sourceID = va.createSoundSource( 'My Matlab virtual sound source' ) % % When everything is done, do not forget to close the connection. % You can call disconnect on the instance or simply clear it: % % clear va % % properties(Hidden = true, Access = private) handle = int32(0); % Connection handle % Connection defaults DEFAULT_SERVER_PORT = 12340; end methods(Static) function [ ok ] = check_for_mex_file() % Checks if VAMatlab executable can be found. if ~exist( 'VAMatlab', 'var' ) disp( 'Matlab binding for VA not complete (missing VAMatlab executable).' ) ok = false; % file dialog else ok = true; end end function [version] = getVersion() % Return the version of the VA Matlab interface % % Parameters: % % None % % Return values: % % version [string] Version string version = VAMatlab('getVersion'); end function [] = setVerboseMode(mode) % Sets the verbose level of the VA Matlab interface % % Parameters: % % mode [string] Verbose mode ('quiet'|'normal') % % Return values: % % None % % Remarks: % % - If you do not want any messages from the extension % set the verbose mode to 'quiet' % VAMatlab('setVerboseMode', mode); end end methods function this = itaVA(addressstring) % Initialization constructor. Initiiates a new connection. % % Parameters: % % addressstring [string] Hostname or IP address and port of the % server string (name:port), optional % % Return values: % % None % % Remarks: % % - You can leave the argument 'address' undefined, in order % to create an clear, unconnected instance and connect to % a server later using the method 'connect' % - Example: core = itaVA; % core = itaVA('localhost:12340'); % if ~check_for_mex_file() ) error( 'Matlab binding for VA requires VAMatlab executable.' ); end if (nargin > 0) this.connect(addressstring) end end function delete(this) % Destructor. Automatically disconnects an existing connection. this.disconnect end function [connected] = isConnected(this) % Returns if a connection to a server is established connected = VAMatlab('isConnected', this.handle); end function connect(this, addressstring) % Connects to a server % % Parameters: % % addressstring [string] Hostname or IP address and port of the % server string (name:port), optional % % Return values: % % None % % Remarks: % % - An error occurs if the instance is already connected % - Example: core.connect('localhost:12340') % if this.handle~=0 error('Already connected. Close the existing connection first.'); end if nargin == 2 if isempty(addressstring) error('Server address must not be empty.'); end else addressstring = 'localhost'; end this.handle = VAMatlab('connect', addressstring); end function disconnect(this) % Disconnects from a server VAMatlab('disconnect', this.handle) this.handle = int32(0); end function [state] = getServerState(this) % Returns the state of the connected server % % Use this function to check whether the server is % running fine and does not have any problems. % % Parameters: % % None % % Return values: % % state [integer-1x1] Server stat % % States: % % - 0 = Connected, but server not configured. Failure. % - 1 = Connected and ready for usage. % - 2 = Connected, but server has failure. % if this.handle==0, error('Not connected.'); end; state = VAMatlab('getServerState', this.handle); end function connectTracker( this, remote_ip, local_ip ) % Connects to a local NatNet tracking server % % The server will update a virtual listener for real-time % sound synthesis and the real world listener position for % those sound reproductions that need this information, like % Crosstalk-Cancellation. % % See also setTrackedListener. % % Parameters (optional): % % remote_ip [char] Remote ip address % local_ip [char] Local ip address % if( nargin == 1 ) remote_ip = '127.0.0.1'; local_ip = '127.0.0.1'; end VAMatlab( 'ConnectTracker', this.handle, remote_ip, local_ip ); end function [connected] = isTrackerConnected( this ) % Returns true, if tracker is connected connected = VAMatlab( 'IsTrackerConnected', this.handle ); end function setTrackedListener( this, listener_id ) % Connects a VA listener with the tracked rigid body % % Parameters: % % listener_id [integer-1x1] VA listener id % VAMatlab( 'SetTrackedListener', this.handle, listener_id ); end function setTrackedSource( this, source_id ) % Connects a VA source with the tracked rigid body % % Parameters: % % source_id [integer-1x1] VA listener id % VAMatlab( 'SetTrackedSource', this.handle, source_id ); end function disconnectTracker( this ) % Disconnects from the NatNet tracking server VAMatlab( 'DisconnectTracker', this.handle ) end function setRigidBodyIndex( this, index ) % Sets the index of the rigid body to be tracked (default is 1) VAMatlab( 'SetRigidBodyIndex', this.handle, index ) end function setRigidBodyTranslation( this, translation ) % Sets the pivot point translation for the tracked rigid body % % Parameters: % % translation [double-3x1] Translation in local coordinate system of rigid body [m] % VAMatlab( 'SetRigidBodyTranslation', this.handle, translation ) end function setRigidBodyRotation( this, rotation ) % Sets the rotation of orientation for the tracked rigid body % % Given rotation has to be a Matlab quaternion type (order: w(real), i, j, k) % % Parameters: % % rotation [quaternion] Rotation of rigid body % VAMatlab( 'SetRigidBodyRotation', this.handle, rotation ) end %% --= Functions =-- ###STUBCODE### function display(this) % TODO: Define nice behaviour % if this.handle % fprintf('Connection established to server ''%s''\n', this.getServerAddress()) % else % fprintf('Not connected\n'); % end end end end