Updates in sample scripts

parent 3233e7fa
......@@ -4,109 +4,65 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# VA simple acoustic scene\n",
"This is a simple example how to create a simple acoustic scene in VA using Python."
"# VA core controller\n",
"This is a simple example how to control global VA core functionality"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prerequisites\n",
"You can ignore this part, it is for preparation purposes only."
"### Prerequisites"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append( '../../Lib/site-packages' )"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import ipywidgets as widgets"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import va"
"sys.path.append( '../../Lib/site-packages' )\n",
"import ipywidgets as widgets\n",
"import va\n",
"if not va.connect() :\n",
" raise 'Could not connect to local VA server'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Connect"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"va.connect();"
"## Control"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Control"
"### Output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Mute / unmute\n",
"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",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "07034f7c9d36416d9a094fd806b3fb22",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"mute_output_button = widgets.ToggleButton( description = 'Output muted', value = va.is_output_muted() )\n",
"\n",
"def on_mute_button_clicked( b ) :\n",
" if b.name == 'value' :\n",
" va.set_output_muted( b.new ) # True if toggle button appears 'active'\n",
" \n",
"\n",
"mute_output_button.observe( on_mute_button_clicked )\n",
"display( mute_output_button )"
]
......@@ -115,30 +71,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Gain\n",
"#### Gain\n",
"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",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1b4fe929c18c409281211379ba390e52",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"output_gain_slider = widgets.FloatSlider( \n",
" value = va.get_output_gain(),\n",
......@@ -157,6 +98,25 @@
"display( output_gain_slider )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Global auralization mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"global_am = va.get_global_auralization_mode()\n",
"va.get_auralization_mode_str()"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -168,21 +128,11 @@
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"$(DefaultHRIR): HRIR\\\\ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.v17.ir.daff\n",
"$(ProjectName): MyVirtualAcousticsProject\n",
"$(data): $(data)\n",
"$(big_data_dir): C:\\\\data\n",
"$(conf): $(conf)\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"print( '$(DefaultHRIR): ' + va.substitute_macro( '$(DefaultHRIR)' ) )\n",
"print( '$(ProjectName): ' + va.substitute_macro( '$(ProjectName)' ) )\n",
......@@ -201,24 +151,11 @@
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d008b4bac6c14a21ad1956680f4b7645",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"reset_button = widgets.Button( description = 'Reset VA server' )\n",
"\n",
......@@ -234,38 +171,16 @@
"metadata": {},
"source": [
"## Modules\n",
"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."
"You can interact with any registered VA module 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 receive information in return. It is used to change any setting in a registered module. This way, no new interface methods for prototyping have to be added during development and testing."
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1d339c748fd44c82ab9b8d5f4a31610c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calling VACore\n",
"Calling BinauralFreeField:MyBinauralFreeField\n",
"Module returned an exception, could not get help\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"allmods = va.enumerate_modules()\n",
"\n",
......@@ -296,25 +211,27 @@
"metadata": {},
"source": [
"### Rendering modules\n",
"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:"
"Rendering modules are special modules that can also be listed using `get_rendering_modules`. They are called through the module interface just as described above, however the module name has to be assembled by the type of renderer followed by a semicolon `:` and the name of the rendering module."
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'enabled': 1, 'class': 'BinauralFreeField', 'description': ''}]\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"allrmods = va.get_rendering_modules()\n",
"print( allrmods )\n",
"for rmod in allrmods :\n",
" print( rmod )\n",
" rmod_id = str( rmod.class + ':' + rmod.name )\n",
" try :\n",
" magic_return = va.call_module( rmod_id, { 'help': True } )\n",
" print( magic_return )\n",
" except:\n",
" print( 'Module call failed, could not get help' )\n",
"\n",
"# todo implement in VAPy"
]
}
......
......@@ -18,9 +18,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Current working directory: C:\\dev\\VA\\dist\\win32-x64.vc14\\python\\examples\\jupyter\n",
"Successfully loaded VA Python extension\n"
]
}
],
"source": [
"import sys\n",
"sys.path.append( '../../Lib/site-packages' )\n",
......@@ -39,13 +48,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 28,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-28-20070eb91885>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-28-20070eb91885>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m if not va.connect( 'localhost' )\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"va.connect( \"localhost\" );"
"if not va.connect( 'localhost' )\n",
" raise 'Could not connect to server on localhost, not running?'\n",
" "
]
},
{
......@@ -57,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {
"collapsed": true
},
......@@ -75,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {
"collapsed": true
},
......@@ -94,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {
"collapsed": true
},
......@@ -113,8 +131,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"signal_source_id = va.create_audio_file_signal_source( 'Audiofiles/Bauer.wav' )\n",
......@@ -132,8 +152,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sound_source_id = va.create_sound_source( 'PySoundSource' )\n",
......@@ -150,7 +172,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {
"collapsed": true
},
......@@ -170,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {
"collapsed": true
},
......@@ -189,13 +211,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "Exception",
"evalue": "Modal error: Not connected. (error code 3)",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mException\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-25-f668a5e697e7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mlistener_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mva\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate_listener\u001b[0m\u001b[1;33m(\u001b[0m \u001b[1;34m'PyListener'\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mva\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_listener_position\u001b[0m\u001b[1;33m(\u001b[0m \u001b[0mlistener_id\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1.7\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mva\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_listener_orientation_vu\u001b[0m\u001b[1;33m(\u001b[0m \u001b[0mlistener_id\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;31m# Default view is to -Z (OpenGL)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mva\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_listener_hrir\u001b[0m\u001b[1;33m(\u001b[0m \u001b[0mlistener_id\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhrir_id\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mException\u001b[0m: Modal error: Not connected. (error code 3)"
]
}
],
"source": [
"listener_id = va.create_listener( 'PyListener' )\n",
"va.set_listener_position( listener_id, ( 0, 1.7, 0 ) )\n",
"va.set_listener_orientation_vu( listener_id, ( 0, 0, -1, ), ( 0, 1, 0 ) ) # Default view is to -Z (OpenGL)"
"va.set_listener_orientation_vu( listener_id, ( 0, 0, -1, ), ( 0, 1, 0 ) ) # Default view is to -Z (OpenGL)\n",
"va.set_listener_hrir( listener_id, hrir_id )"
]
},
{
......@@ -208,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {
"collapsed": true
},
......@@ -226,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {
"collapsed": true
},
......
# Add va module if it was not installed
import sys
sys.path.append( '../Lib/site-packages' )
sys.path.append( '../dist/Lib/site-packages' )
import os
current_exec_dir = os.getcwd()
......
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