{ "cells": [ { "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Prerequisites\n", "You can ignore this part, it is for preparation purposes only." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "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" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Connect" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "va.connect();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Control" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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, "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" } ], "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", "mute_output_button.observe( on_mute_button_clicked )\n", "display( mute_output_button )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 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, "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" } ], "source": [ "output_gain_slider = widgets.FloatSlider( \n", " value = va.get_output_gain(),\n", " description = 'Output gain:',\n", " min = 0.0,\n", " max = 1.0,\n", " step = 0.1,\n", " readout = True,\n", " readout_format = '.1f' )\n", "\n", "def on_output_gain_changed( s ) :\n", " if s.name == 'value' :\n", " va.set_output_gain( s.new )\n", "\n", "output_gain_slider.observe( on_output_gain_changed )\n", "display( output_gain_slider )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Macros\n", "\n", "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", "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" ] } ], "source": [ "print( '$(DefaultHRIR): ' + va.substitute_macro( '$(DefaultHRIR)' ) )\n", "print( '$(ProjectName): ' + va.substitute_macro( '$(ProjectName)' ) )\n", "print( '$(data): ' + va.substitute_macro( '$(data)' ) )\n", "print( '$(big_data_dir): ' + va.substitute_macro( '$(big_data_dir)' ) )\n", "print( '$(conf): ' + va.substitute_macro( '$(conf)' ) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reset\n", "Use `reset` to reset the entire scene." ] }, { "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" } ], "source": [ "reset_button = widgets.Button( description = 'Reset VA server' )\n", "\n", "def on_reset_button_clicked( b ) :\n", " va.reset()\n", " \n", "reset_button.on_click( on_reset_button_clicked )\n", "display( reset_button )" ] }, { "cell_type": "markdown", "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." ] }, { "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" ] } ], "source": [ "allmods = va.enumerate_modules()\n", "\n", "modnames = list()\n", "for mod in allmods[:] :\n", " modnames.append( mod[\"name\"] )\n", "mods_dropdown_menu = widgets.Dropdown( options=modnames )\n", "\n", "mod_call_button = widgets.Button( description = 'Call' )\n", "mod_widget_box = widgets.HBox( [ mods_dropdown_menu, mod_call_button ] )\n", "\n", "def on_mod_call( b ) :\n", " mod = allmods[ mods_dropdown_menu.index ]\n", " print( 'Calling ' + mod[\"name\"] )\n", " modnames.append( mod[\"name\"] )\n", " try :\n", " va.call_module( mod[\"name\"], { 'help': True } )\n", " except :\n", " print( 'Module returned an exception, could not get help' )\n", " \n", "mod_call_button.on_click( on_mod_call )\n", "\n", "display( mod_widget_box )" ] }, { "cell_type": "markdown", "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:" ] }, { "cell_type": "code", "execution_count": 93, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'enabled': 1, 'class': 'BinauralFreeField', 'description': ''}]\n" ] } ], "source": [ "allrmods = va.get_rendering_modules()\n", "print( allrmods )\n", "# todo implement in VAPy" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }