Skip to main content

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.

If you want to use Sphinx’s nitpicky setting, you’ll have to add a few things to nitpick_ignore:

nitpicky = True
nitpick_ignore = [
    ('py:class', 'optional'),
    ('py:class', 'buffer'),
    ('py:class', 'CData pointer'),
]

Version History

0.1.4 (2020-08-27):
  • Minor documentation update

0.1.3 (2018-06-02):
  • No new features, just a minor documentation update

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

Metadata

Release files for pa-ringbuffer 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pa-ringbuffer 0.1.4
File Size Uploaded
pa-ringbuffer-0.1.4.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pa-ringbuffer 0.1.4
File Interpreter ABI Platform
pa_ringbuffer-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 14.6 kB

Release files / pa-ringbuffer-0.1.4.tar.gz

Download URL pa-ringbuffer-0.1.4.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0878054e979e7b4fafcbcf6273a87e1ed2c50dad44c29fc557d72b7b3a04cf42
BLAKE2b-256 checksum
How to use checksums
b59f31956899bd842747e12b554e04055a6745cfc3e104eaf40a29e6413028da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5

Release files / pa_ringbuffer-0.1.4-py2.py3-none-any.whl

Download URL pa_ringbuffer-0.1.4-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a4cb24883645696e021c309bfe13904617bf551491d6f0ab9f9ec70ff33d6a04
BLAKE2b-256 checksum
How to use checksums
fd3661306052b7ab56f52d76976676041d64a8d554173a2f1c89508e1434ee7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page