Adding jupyter notebook simple acoustic scene example

parent a50dd601
{
"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": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append( '../../Lib/site-packages' )\n",
"import os\n",
"print( 'Current working directory:', os.getcwd() )\n",
"import va\n",
"print( 'Successfully loaded VA Python extension')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Connect"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.connect( \"localhost\" );"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reset VA to clear the scene"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.reset()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Control output gain"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.set_output_gain( 0.25 )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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.\n",
"> 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",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.add_search_path( os.getcwd() );"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Signal source\n",
"Create a signal source from a file and start playback with looping mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"signal_source_id = va.create_audio_file_signal_source( 'Audiofiles/Bauer.wav' )\n",
"va.set_audiofile_signal_source_playback_action( signal_source_id, 'play' )\n",
"va.set_audiofile_signal_source_is_looping( signal_source_id, True )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Virtual sound source\n",
"Create a virtual sound source with any name and set a position"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sound_source_id = va.create_sound_source( 'PySoundSource' )\n",
"va.set_sound_source_position( sound_source_id, ( 1.5 1.7, -1.1 ) )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Connect signal and source\n",
"Connect the signal source to the virtual sound source"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.set_sound_source_signal_source( sound_source_id, signal_source_id )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Head-related transfer function / Head-related impulse response\n",
"Load an HRIR (time domain representation of an HRTF). See [OpenDAFF](http://www.opendaff.org) for more information.\n",
"> We use a macro `DefaultHRIR` here, that is usually available for a VA core."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"hrir_id = va.load_hrir( '$(DefaultHRIR)' )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Virtual listener\n",
"Create a listener with arbitrary name, assign the HRTF/HRIR and set a position."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Active listener\n",
"Set an active listener. This concept is deprecated, but should be used for compatibility until it is removed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"va.set_active_listener( listener_id )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Disconnect"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"va.disconnect();"
]
}
],
"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
}
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