~cnx/palace

ref: 708f23b35a7e232273ba0a63a65b3ef778a84540 palace/docs/source/tutorial/context.rst -rw-r--r-- 1.0 KiB
708f23b3 — Ngô Ngọc Đức Huy Write tutorial for source effect 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Context Creation
================

.. currentmodule:: palace

A context is an object that allows palace to access OpenAL,
which is essential when you work with palace.  Context maintains
the audio environment and contains environment settings and components
such as sources, buffers, and effects.

Creating a Device Object
------------------------

To create a context, we must first create a device,
since it's a parameter of the context object.

To create an object, well, you just have to instantiate
the :py:class:`Device` class.

.. code-block:: python

   from palace import Device

   with Device() as dev:
       # Your code goes here

This is how you declare a :py:class:`Device` object with the default device.
There can be several devices available, which can be found
in :py:data:`device_names`.

Creating a Context
------------------

Now that we've created a device, we can create the context:

.. code-block:: python

   from palace import Device, Context

   with Device() as dev, Context(dev) as ctx:
       # Your code goes here