Skip to main content

OpenAL integration for Python

Project description

PyOpenAL provides OpenAL bindings for python as well as an interface to them.

It also provides a simple way to play WAVE and even OGG Vorbis and OGG Opus files, the latter two if used together with PyOgg.

PyOpenAL requires a dynamic OpenAL library (OpenAL32.dll). You can use the official OpenAL library (deprecated) or the much better sounding OpenAL Soft library, which is still actively developed (or any other OpenAL compatible library).

PyOpenAL provides OpenAL bindings, as you would find them in C++, meaning you can follow any OpenAL C++ tutorial with Python. OpenAL’s methods expect C types as arguments, which means you will have to convert Python’s types to C types using ctypes if you want to use them directly. Don’t worry though, PyOpenAL can be used without the need to do that.

I removed the support for ALUT, because it is basically impossible to build nowadays. If you want ALUT support, please use the original PyOpenAL from forrestv

Examples

Playing a wave file

# import PyOpenAL (will require OpenAL32.dll)

from openal import *

# import the time module, for sleeping during playback

import time

# open our wave file

source = oalLoadFile(“test.wav”)

# and start playback

source.play()

# check if the file is still playing

while source.get_state() == AL_PLAYING:

# wait until the file is done playing

time.sleep(1)

# release resources (don’t forget this)

oalQuit()

Playing an OGG Opus file (with PyOgg)

from openal import *

# even though we use PyOgg, we don’t have to import it ourselves,

# PyOpenAL does that for us (if it can find it)

import time

source = oalLoadFile(“test.opus”)

source.play()

while source.get_state() == AL_PLAYING:

time.sleep(1)

# remember, don’t forget to quit

oalQuit()

Streaming a file

from openal import *

# here we define how much data is supposed to be held at a time (for Vorbis and Opus files), in how many buffers

# this is set automatically, but you can set it yourself, if you can’t update the stream frequently enough

pyoggSetStreamBufferSize(4096*4)

oalSetStreamBufferCount(4)

sourceStream = oalStreamFile(“test.ogg”)

sourceStream.play()

while sourceStream.get_state() == AL_PLAYING:

# do stuff

[…]

# update the stream (load new data)

# if you don’t do this repeatedly, the stream will suffocate

sourceStream.update()

oalQuit()

Using OpenAL functions

# here we only import OpenAL’s functions

# (in case you don’t need / want PyOpenAL’s functions / classes)

from openal._al import *

from openal._alc import *

[…]

# it’s as simple as that:

alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED)

# or a little more complicated, it really depends:

alSourceUnqueueBuffers(source_id, 1, ctypes.pointer(ctypes.c_uint(buffer_ids[id])))

[…]

To get a reference sheet, please visit PyOpenAL’s GitHub page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyOpenAL-0.6.3a1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyOpenAL-0.6.3a1-py2.py3-none-any.whl (28.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file PyOpenAL-0.6.3a1.tar.gz.

File metadata

  • Download URL: PyOpenAL-0.6.3a1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyOpenAL-0.6.3a1.tar.gz
Algorithm Hash digest
SHA256 70f74e3b65dab91c821350bf22d4b7481219852d2995a33b7bb63498278674c0
MD5 3095b06b38d7b10ae41981191b8ea1d8
BLAKE2b-256 7ffecbc32e7e4e0dff5bddbdad87f5232520d6d757d55b5d3f8e1f72e71b5e82

See more details on using hashes here.

File details

Details for the file PyOpenAL-0.6.3a1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for PyOpenAL-0.6.3a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0ebe000d770919dda6bbc7036af1fbc5e5bca9f7c87c246548f8b534a847c6b5
MD5 cbfdfdf360326ea1f9cf3726d4e4641c
BLAKE2b-256 9ff208a6280d7d16fc22428fb31e4f1a5f76789138a743736aeba37138c92b64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page