Skip to content
Snippets Groups Projects
Commit 86ac8909 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding jupyter notebook simple acoustic scene example

parent a50dd601
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags:
# VA simple acoustic scene
This is a simple example how to create a simple acoustic scene in VA using Python.
%% Cell type:markdown id: tags:
#### Prerequisites
You can ignore this part, it is for preparation purposes only.
%% Cell type:code id: tags:
``` python
import sys
sys.path.append( '../../Lib/site-packages' )
import os
print( 'Current working directory:', os.getcwd() )
import va
print( 'Successfully loaded VA Python extension')
```
%% Cell type:markdown id: tags:
### Connect
%% Cell type:code id: tags:
``` python
va.connect( "localhost" );
```
%% Cell type:markdown id: tags:
Reset VA to clear the scene
%% Cell type:code id: tags:
``` python
va.reset()
```
%% Cell type:markdown id: tags:
Control output gain
%% Cell type:code id: tags:
``` python
va.set_output_gain( 0.25 )
```
%% Cell type:markdown id: tags:
Add the current working directory or any other relative or absolute directory as a search path to your VA application. From now on, only use relative paths or macros to paths.
> Pathes are relevant on server side, not on a remote client. The files must be available on the computer **where the VA application is running**!
%% Cell type:code id: tags:
``` python
va.add_search_path( os.getcwd() );
```
%% Cell type:markdown id: tags:
### Signal source
Create a signal source from a file and start playback with looping mode
%% Cell type:code id: tags:
``` python
signal_source_id = va.create_audio_file_signal_source( 'Audiofiles/Bauer.wav' )
va.set_audiofile_signal_source_playback_action( signal_source_id, 'play' )
va.set_audiofile_signal_source_is_looping( signal_source_id, True )
```
%% Cell type:markdown id: tags:
### Virtual sound source
Create a virtual sound source with any name and set a position
%% Cell type:code id: tags:
``` python
sound_source_id = va.create_sound_source( 'PySoundSource' )
va.set_sound_source_position( sound_source_id, ( 1.5 1.7, -1.1 ) )
```
%% Cell type:markdown id: tags:
### Connect signal and source
Connect the signal source to the virtual sound source
%% Cell type:code id: tags:
``` python
va.set_sound_source_signal_source( sound_source_id, signal_source_id )
```
%% Cell type:markdown id: tags:
### Head-related transfer function / Head-related impulse response
Load an HRIR (time domain representation of an HRTF). See [OpenDAFF](http://www.opendaff.org) for more information.
> We use a macro `DefaultHRIR` here, that is usually available for a VA core.
%% Cell type:code id: tags:
``` python
hrir_id = va.load_hrir( '$(DefaultHRIR)' )
```
%% Cell type:markdown id: tags:
### Virtual listener
Create a listener with arbitrary name, assign the HRTF/HRIR and set a position.
%% Cell type:code id: tags:
``` python
listener_id = va.create_listener( 'PyListener' )
va.set_listener_position( listener_id, ( 0, 1.7, 0 ) )
va.set_listener_orientation_vu( listener_id, ( 0, 0, -1, ), ( 0, 1, 0 ) ) # Default view is to -Z (OpenGL)
```
%% Cell type:markdown id: tags:
### Active listener
Set an active listener. This concept is deprecated, but should be used for compatibility until it is removed.
%% Cell type:code id: tags:
``` python
va.set_active_listener( listener_id )
```
%% Cell type:markdown id: tags:
### Disconnect
%% Cell type:code id: tags:
``` python
va.disconnect();
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment