Package: pa-ringbuffer
Thering buffer functionalityis typically not included in binary
distributions ofPortAudio, therefore most Python wrappers don’t include it,
either.Thepa_ringbuffermodule provides only a Python wrapper, the actual
PortAudio ring buffer code has to be compiled separately, seeUsage.
It can be used on any Python version whereCFFIis available.This module is designed to be used together with thesounddevicemodule (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.UsageThis 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 athttps://github.com/spatialaudio/python-rtmixer.You can get the Python code fromPyPI, for example in yoursetup.pyfile
(in the following example, your module would be calledmycffimodule):fromsetuptoolsimportsetupsetup(name=...,version=...,author=...,...,cffi_modules=['mycffimodule_build.py:ffibuilder'],setup_requires=['CFFI','pa_ringbuffer'],install_requires=['pa_ringbuffer'],...,)Alternatively, you can just copy the filesrc/pa_ringbuffer.pyto your own
source directory and import it from there.You can build your own CFFI module like described inhttp://cffi.readthedocs.io/en/latest/cdef.html, just adding a few more bits to
yourmycffimodule_build.py:fromcffiimportFFIimportpa_ringbufferffibuilder=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:https://app.assembla.com/spaces/portaudio/git/source/master/src/common/pa_ringbuffer.chttps://app.assembla.com/spaces/portaudio/git/source/master/src/common/pa_ringbuffer.hhttps://app.assembla.com/spaces/portaudio/git/source/master/src/common/pa_memorybarrier.hFor your own C code, you might need some definitions from the main PortAudio
header:https://app.assembla.com/spaces/portaudio/git/source/master/include/portaudio.hOnce 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 theRingBufferclass:importpa_ringbufferfrom_mycffimoduleimportffi,libRingBuffer=pa_ringbuffer.init(ffi,lib)API ReferenceThere are only two functions:pa_ringbuffer.cdef()This function returns a string containing C declarations from the filepa_ringbuffer.h, which can be used as argument to CFFI’scdef()function
(seeUsageabove).  Note that the returned declarations are slightly different
when called on a macOS/Darwin system.pa_ringbuffer.init(ffi, lib)This function returns theRingBufferclass which is associated with the CFFI
instance given byffiandlib.Creating the DocumentationThe documentation of theRingBufferclass is not available separately.
If you are usingSphinx, you can seamlessly include the documentation of theRingBufferclass with your own documentation.
An example for this can be found athttps://github.com/spatialaudio/python-rtmixer, the generated documentation is
available athttp://python-rtmixer.readthedocs.io/#rtmixer.RingBuffer.You’ll need to have theautodocextension activated in yourconf.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 thecurrentmoduledirective to select your
own module.  Usingautomoduleshould also do.If you want to use Sphinx’snitpickysetting,
you’ll have to add a few things tonitpick_ignore:nitpicky=Truenitpick_ignore=[('py:class','optional'),('py:class','buffer'),('py:class','CData pointer'),]Version History0.1.4 (2020-08-27):Minor documentation update0.1.3 (2018-06-02):No new features, just a minor documentation update0.1.2 (2017-10-21):No new features, just a bug fix0.1.1 (2017-09-04):Addbufferparameter0.1.0 (2017-08-08):Initial release