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.

You can get the Python code from PyPI, for example in your setup.py file:

from setuptools import setup

setup(
    name=...,
    version=...,
    author=...,
    ...,
    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:

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 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.

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.0.0.tar.gz (5.7 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for pa-ringbuffer-0.0.0.tar.gz
Algorithm Hash digest
SHA256 e9dc298df460514c51828b53f072c0fc2329dd847855e229eb7a007c4ad2b141
MD5 2c74020603cd19e784afd0e00b52a51a
BLAKE2b-256 bda486515de24d24fb97abe805dc18a939ca74346169f7b6ee9a9b3355418724

See more details on using hashes here.

Supported by

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