Python Interface to PortAudio, for Sound driven Animation

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

Post Reply

Does PortAudio work an all trargeted Operating Systems (Will use it for Sound driven Animation)?

Windows (95,98,ME,NT,2000)
No votes
No votes
No votes
No votes
Total votes: 1

Posts: 7
Joined: Wed Dec 18, 2002 1:19 am

Python Interface to PortAudio, for Sound driven Animation

Post by rorschach »

Hi Dear Fellow Blenders,

As I was formerly deeply investigating into a solution for driving objects
animations by sound input, and a kind of beat detection, which i used in a live performance with musicians and dancers at a festival in den haag.

because of only little time for the development, i just made a fast hack, depending on the linux ecasound package and its python wrappers. it basicly enabled me to pre-filter the audio stream, and grab some debug values (including peaks).

so i was looking for a way to generalize the idea, and make it available to the public, and my fellow blenders.
my choice of the moment is PortAudio, and the python wrapper Package at
This choice seems to deliver all the required ports, so that the package may be used with all blender flavors.

So my first question to you people is, some experiences with the packages in question on the operating systems i can not test here.
i like to hear about MacOS X, FreeBSD and Solaris. Linux and Windoze i can test here.

PortAudio is just an interface to the audio stream, or file. its providing an data buffer to read and/or write from + to.
so everything on top, like a beat detection, filters or the like, needs attention.

I will try to develop a two layer interface, low and high level integration into the gameengine, which should suite the needs of generalized interface for sound detection, and possible sound generation out of blender. in that way it should be easy to interface form within the GameEngine, and write python algorithms to handle the data, like a plugin interface. I would like to use this forum then to post the layouts and discuss them.
Any offer of help is welcome, 'cause my time also is limited.

also i would like to know if there is a way, in the future gameengine, for independent threading. i was having great difficulties with my test integration into the blender gameengine, because every referenced code is executed in the run loop of the gameengine, which i couldn't escape for a different thread cycling (GameEngine in 2.25).

cheers rorschach

Posts: 8
Joined: Sun Oct 13, 2002 7:41 pm
Location: Berlin

Post by datura »

hi !

i´m very interested in such a sound-sensor or Python-Script and I would like to join the development.

the best way in my opinion would be to do this in C in Blender, cause everybody could use it then and you don´t have to install libraries etc., (but my C isn´t very good).

The pyPortAudio-Lib seems to be very simple to use,
but i´ve got at the moment a problem to install it and it isn´t well documented.

Maybe you´ve got a tip for me. I put the libsndfile.dll in my Windows-folder, then extracted the portaudio_v18 and into the portaudiofolder i extracted the pyPortAudio-stuff. Then I ran the first with build and then with install.
i get this output for build and install (maybe you´ve got a tip) :

Code: Select all

Adding '../pa_win_wmme.c' for windoze
running build
running build_py
not copying (output up-to-date)
running build_ext
building 'portaudio_' extension
Traceback (most recent call last):
  File "F:\bibliotheken\portaudio_v18\pyPortAudio\", line 55, in ?
    ext_modules = [portaudio_]
  File "C:\Python22\lib\distutils\", line 138, in setup
  File "C:\Python22\lib\distutils\", line 893, in run_commands
  File "C:\Python22\lib\distutils\", line 913, in run_command
  File "C:\Python22\lib\distutils\command\", line 107, in run
  File "C:\Python22\lib\distutils\", line 330, in run_command
  File "C:\Python22\lib\distutils\", line 913, in run_command
  File "C:\Python22\lib\distutils\command\", line 256, in run
  File "C:\Python22\lib\distutils\command\", line 383, in build_exte
  File "C:\Python22\lib\distutils\command\", line 457, in build_exte
  File "C:\Python22\lib\distutils\", line 295, in compile
    pp_opts = gen_preprocess_options (macros, include_dirs)
  File "C:\Python22\lib\distutils\", line 987, in gen_preprocess_opt
    raise TypeError, \
TypeError: bad macro definition 'WIN32': each element of 'macros' list must be a
 1- or 2-tuple

Posts: 7
Joined: Wed Dec 18, 2002 1:19 am

investigating into fmod and openal for deployment

Post by rorschach »

Hi datura,

i'm currently investigating the openal and fmod library for the use in such a module.

benefit would be that we can make a very close integration into the blender engine. means when for input detection files are used, we can access the loaded files, which are used with the soundactuator. or even more tight, as to create a new kind of actuator a sounddetection-actuator.
We would have the same set of file types and devices as are available for the soundgeneration.
We will have access to the already loaded soundfiles, which are stored in the gamememory. Synchronisation between sound-playback and sound-analyses should be easy, cause the same state-engine can be used.

also i'm thinking, if we are interfacing in an high level of the design, we might be able to make an abstract layer, that enables people generally to prefilter the played sounds, i think of something like an audio-plugin interface, that is tightly integrated into the fmod/openal eventmanager, and act like prefilters on the sounds, but thats for later study.

so still i'm investigating, and now analysing the gameengine soundsystem, the openal and fmod libraries as well the soundactuator.

i'll post my analysis on that soon.

Posts: 7
Joined: Wed Dec 18, 2002 1:19 am

More on the Investigations

Post by rorschach »


it seems that there is no direct access to the sample buffer, not on behalf of the blender abstraction layer.

So it would be necessary to interface that, like a direct (shared) and an indirect (copy) handler for a given object->sample->buffer, like SND_getObjectSampleBuffer and SND_setObjectSampleBuffer which would handle a direkt buffer access without locking, and the SND_copyObjectSampleBuffer which is creating a new sample with a copy of the given buffer.
Something like that.

Next thought i'm still chewing on is sound filtering. Either create a very simplistic sound statistics package, that provide some data to chew on. Or use some Libraries out there fitting the current need, and helping out with a bigger variety of soundprocessing possibilities.
These soundprocessing then might even be reused for prefilter and preprocessing of sounds meant for playback, not for data-analysis.

Currently i'm still looking for such a package, that can be introduced into blender as a fourth snd_device besides dummy, openal and fmod.
I think PortAudio delivers too less of the functionality i'm looking for.
I found another candidate though, thats SndObj ( ... /main.html).
But i'll take a deeper look into it, and the integration question.

thats it for today
over and out

Post Reply