Commit d551b6d7 authored by Lukas Aspöck's avatar Lukas Aspöck

added simple VA demo with a slider GUI to adjust the sound source distance

parent ee40061b
%% VA simple example code with sound source distance slider and optional reverberation
% Author: Lukas Aspöck, las@akustik.rwth-aachen.de
% date: 2019/12/19
%% Instruction to add reverb to the scene
% 1) If running, close the VAServer application
% 2) go to the VA/conf folder and open the file VACore.ini with a text editor
% 3) scroll down to the line [Renderer:MyBinauralArtificialReverb]
% 4) set the key "Enabled" to true
% 5) replace the line ReverberationTime = 0.71 with ReverberationTimes = 1, 1, 0.5
% 6) Restart VAServer (run_VAServer.bat) and rerun this script
% Create VA
va = VA;
% Connect to VA application (start the application first)
va.connect( 'localhost' )
% Reset VA to clear the scene
va.reset()
% Control output gain
va.set_output_gain( .25 )
% Add the current absolute folder path to VA application
va.add_search_path( pwd );
% Create a signal source and start playback
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 );
% Create a virtual sound source and set a position
S = va.create_sound_source( 'VA_Source' );
va.set_sound_source_position( S, [ 0.5 1.7 0.5 ] )
% Create a listener with a HRTF and position him
L = va.create_sound_receiver( 'VA_Listener' );
va.set_sound_receiver_position( L, [ 0 1.7 0 ] )
H = va.create_directivity_from_file( '$(DefaultHRIR)' );
va.set_sound_receiver_directivity( L, H );
% Connect the signal source to the virtual sound source
va.set_sound_source_signal_source( S, X )
% start slider gui to change the distance
va_sliderDistance(va,S)
function varargout = va_sliderDistance(varargin)
% VA_SLIDERDISTANCE MATLAB code for va_sliderDistance.fig
% VA_SLIDERDISTANCE, by itself, creates a new VA_SLIDERDISTANCE or raises the existing
% singleton*.
%
% H = VA_SLIDERDISTANCE returns the handle to a new VA_SLIDERDISTANCE or the handle to
% the existing singleton*.
%
% VA_SLIDERDISTANCE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VA_SLIDERDISTANCE.M with the given input arguments.
%
% VA_SLIDERDISTANCE('Property','Value',...) creates a new VA_SLIDERDISTANCE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before va_sliderDistance_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to va_sliderDistance_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help va_sliderDistance
% Last Modified by GUIDE v2.5 19-Dec-2019 12:01:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @va_sliderDistance_OpeningFcn, ...
'gui_OutputFcn', @va_sliderDistance_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before va_sliderDistance is made visible.
function va_sliderDistance_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to va_sliderDistance (see VARARGIN)
% Choose default command line output for va_sliderDistance
handles.output = hObject;
% Update handles structure
handles.va = varargin{1};
handles.S = varargin{2};
guidata(hObject, handles);
% UIWAIT makes va_sliderDistance wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = va_sliderDistance_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.angleText, 'String', [ 'Distance to receiver: ' num2str(get(hObject,'Value'),2) ' m' ]);
handles.va.set_sound_source_position( handles.S, [ 0.5 1.7 get(hObject,'Value') ] )
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
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