Skip to main content

Python wrapper for PortAudio's ring buffer

Project description

The ring buffer functionality is typically not included in binary distributions of PortAudio, therefore most Python wrappers don’t include it, either.

The pa_ringbuffer module provides only a Python wrapper, the actual PortAudio ring buffer code has to be compiled separately, see Usage. It can be used on any Python version where CFFI is available.

This module is designed to be used together with the sounddevice module (it might work with other modules, too) for non-blocking transfer of data between the main Python program and an audio callback function which is implemented in C or some other compiled language.

Usage

This module is not meant to be used on its own, it is only useful in cooperation with another Python module using CFFI. For an example, have a look at https://github.com/spatialaudio/python-rtmixer.

You can get the Python code from PyPI, for example in your setup.py file (in the following example, your module would be called mycffimodule):

from setuptools import setup

setup(
    name=...,
    version=...,
    author=...,
    ...,
    cffi_modules=['mycffimodule_build.py:ffibuilder'],
    setup_requires=['CFFI', 'pa_ringbuffer'],
    install_requires=['pa_ringbuffer'],
    ...,
)

Alternatively, you can just copy the file src/pa_ringbuffer.py to your own source directory and import it from there.

You can build your own CFFI module like described in http://cffi.readthedocs.io/en/latest/cdef.html, just adding a few more bits to your mycffimodule_build.py:

from cffi import FFI
import pa_ringbuffer

ffibuilder = FFI()
ffibuilder.cdef(pa_ringbuffer.cdef())
ffibuilder.cdef("""

/* my own declarations */

""")
ffibuilder.set_source(
    '_mycffimodule',
    '/* my implementation */',
    sources=['portaudio/src/common/pa_ringbuffer.c'],
)

if __name__ == '__main__':
    ffibuilder.compile(verbose=True)

Note that the following files must be available to the compiler:

For your own C code, you might need some definitions from the main PortAudio header:

Once you have compiled your extension module (with the help of CFFI), you can use something like this in your own module to get access to the RingBuffer class:

import pa_ringbuffer
from _mycffimodule import ffi, lib

RingBuffer = pa_ringbuffer.init(ffi, lib)

API Reference

There are only two functions:

pa_ringbuffer.cdef()

This function returns a string containing C declarations from the file pa_ringbuffer.h, which can be used as argument to CFFI’s cdef() function (see Usage above). Note that the returned declarations are slightly different when called on a macOS/Darwin system.

pa_ringbuffer.init(ffi, lib)

This function returns the RingBuffer class which is associated with the CFFI instance given by ffi and lib.

Creating the Documentation

The documentation of the RingBuffer class is not available separately. If you are using Sphinx, you can seamlessly include the documentation of the RingBuffer class with your own documentation. An example for this can be found at https://github.com/spatialaudio/python-rtmixer, the generated documentation is available at http://python-rtmixer.readthedocs.io/#rtmixer.RingBuffer.

You’ll need to have the autodoc extension activated in your conf.py:

extensions = [
    ...,
    'sphinx.ext.autodoc',
    ...,
]

And somewhere within your module documentation, you should add this:

.. autoclass:: RingBuffer
   :inherited-members:

Before that, you might have to use the currentmodule directive to select your own module. Using automodule should also do.

Version History

0.1.2 (2017-10-21):
  • No new features, just a bug fix

0.1.1 (2017-09-04):
  • Add buffer parameter

0.1.0 (2017-08-08):

Initial release

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

pa-ringbuffer-0.1.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

pa_ringbuffer-0.1.2-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pa-ringbuffer-0.1.2.tar.gz.

File metadata

  • Download URL: pa-ringbuffer-0.1.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pa-ringbuffer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d13f6c1fab3b7d2c3ec885fd1b2123ce072030233dbb3183c3f88f18c39daf84
MD5 86266044c63d08c8fdd06dbf9ee435aa
BLAKE2b-256 d3d37137027be68b7a29546dc6196300b8004f13c39539d91541bb2b1185991b

See more details on using hashes here.

File details

Details for the file pa_ringbuffer-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pa_ringbuffer-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1097519b408f80bb33ee37c45e5d9be06827a4a9a922eecb3f52b08a07ce464c
MD5 2d484c4329f00198dc456b356744944a
BLAKE2b-256 2127b8f002a2d84a5ce4a6aec0b36228d554fd4d4a0e303ed9d89709107c6283

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