Adding notebook with example how to control va

parent 88d93cff
{
"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": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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