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

Progress on va controller notebook

parent 62889b54
No related branches found
No related tags found
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' )
```
%% Cell type:code id: tags:
``` python
import ipywidgets as widgets
```
%% Cell type:code id: tags:
``` python
import va
```
%% Cell type:markdown id: tags:
### Connect
%% Cell type:code id: tags:
``` python
va.connect();
```
%% Cell type:markdown id: tags:
## Control
%% Cell type:markdown id: tags:
You can mute and unmute the entire audio output by using `set_output_muted` and receive the current setting by `is_output_muted`. The setter uses the optional argument `True` or `False` and will mute the output if no argument is passed.
%% Cell type:code id: tags:
``` python
mute_output_button = widgets.ToggleButton( description = 'Output muted', value = va.is_output_muted() )
def on_mute_button_clicked( b ) :
if b.name == 'value' :
va.set_output_muted( b.new ) # True if toggle button appears 'active'
mute_output_button.observe( on_mute_button_clicked )
display( mute_output_button )
```
%% Output
%% Cell type:markdown id: tags:
### Gain
The output gain or output volume of VA can be controlled by `set_output_gain` and received by `get_output_gain`. Gains or volumes are defined as a factore between 0 and 1. The same functions also exist for the audio inputs of the sound device.
%% Cell type:code id: tags:
``` python
output_gain_slider = widgets.FloatSlider(
value = va.get_output_gain(),
description = 'Output gain:',
min = 0.0,
max = 1.0,
step = 0.1,
readout = True,
readout_format = '.1f' )
def on_output_gain_changed( s ) :
if s.name == 'value' :
va.set_output_gain( s.new )
output_gain_slider.observe( on_output_gain_changed )
display( output_gain_slider )
```
%% Output
%% Cell type:markdown id: tags:
## Macros
### Macros
Macros can be defined to make your life easier. Don't mess around with file pathes too much, use macros. Don't rename output file names for recording and other exported information, use macros. You can test your macros using th method `substitute_macro` (see below), but you don't have to do it yourself. VA will always substitute macros where possible.
%% Cell type:code id: tags:
``` python
print( '$(DefaultHRIR): ' + va.substitute_macro( '$(DefaultHRIR)' ) )
print( '$(ProjectName): ' + va.substitute_macro( '$(ProjectName)' ) )
print( '$(data): ' + va.substitute_macro( '$(data)' ) )
print( '$(big_data_dir): ' + va.substitute_macro( '$(big_data_dir)' ) )
print( '$(conf): ' + va.substitute_macro( '$(conf)' ) )
```
%% Output
$(DefaultHRIR): HRIR\\ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.v17.ir.daff
$(ProjectName): MyVirtualAcousticsProject
$(data): $(data)
$(big_data_dir): C:\\data
$(conf): $(conf)
%% Cell type:markdown id: tags:
## Reset
### Reset
Use `reset` to reset the entire scene.
%% Cell type:code id: tags:
``` python
reset_button = widgets.Button( description = 'Reset VA server' )
def on_reset_button_clicked( b ) :
va.reset()
reset_button.on_click( on_reset_button_clicked )
display( reset_button )
```
%% Output
%% Cell type:markdown id: tags:
## Modules
You can interact with modules using a magic struct. In Python, this struct is represented by a (nested) dictionary, that is translated to a VAStruct. This struct can be used to call modules and receiver information on return. It is used to change any setting in a given module. This way, interfaces sta untouched but developers have all the possibilities required to try out new prototype functions.
%% Cell type:code id: tags:
``` python
allmods = va.enumerate_modules()
modnames = list()
for mod in allmods[:] :
modnames.append( mod["name"] )
mods_dropdown_menu = widgets.Dropdown( options=modnames )
mod_call_button = widgets.Button( description = 'Call' )
mod_widget_box = widgets.HBox( [ mods_dropdown_menu, mod_call_button ] )
def on_mod_call( b ) :
mod = allmods[ mods_dropdown_menu.index ]
print( 'Calling ' + mod["name"] )
modnames.append( mod["name"] )
try :
va.call_module( mod["name"], { 'help': True } )
except :
print( 'Module returned an exception, could not get help' )
mod_call_button.on_click( on_mod_call )
display( mod_widget_box )
```
%% Output
Calling VACore
Calling BinauralFreeField:MyBinauralFreeField
Module returned an exception, could not get help
%% Cell type:markdown id: tags:
### Rendering modules
Rendering modules are special modules and can also be called using the getter and setter methods `get_renderer_parameters` and `set_renderer_parameters`. They usually work like this: use the getter with an empty struct and receive every possible setting with its current value. Change the value or the returned struct and use the setter to modify the corresponding values in the renderinig module:
%% Cell type:code id: tags:
``` python
allrmods = va.get_rendering_modules()
print( allrmods )
# todo implement in VAPy
```
%% Output
[{'enabled': 1, 'class': 'BinauralFreeField', 'description': ''}]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment