Physical Modelling for pd
contact : cyrille.henry at la-kitchen dot fr
pmpd is a collection of object for with pd. These objects provide real-time simulations, specially physical behaviors. pmpd can be used to create natural dynamic systems, like a bouncing ball, string movement, Brownian movement, chaos, fluid dynamics, sand, gravitation, and more. It can also be used to create displacements thus allowing a completely dynamic approach of pd computing.
With pmpd physical dynamics can be modelled without knowing the global equation of the movement. Only the cause of the movement and the involved structure are needed for the simulation. pmpd provides the basic objects for this kind of simulation. Assembling them allows the creation of a very large variety of dynamic systems .
These object are designed to be used with pd (pd). pd is a real time graphical programming environment dedicated for audio signal processing. Pd allow the creation of object and it is well adapted of the creation of particular physical modelling. GEM is a pd library dedicated to images processing. In the provided pmpd examples, GEM is used for the movement visualisation.
you can download sources / examples / bin / help / documentation :
If you use Max/MSP, you may be interested with the port made by Ali Momeni :
The aim of pmpd is to create different kinds of behavior for sound and video processing using pd. Moreover, the modelling of dynamic physical systems can easily be done with pmpd.
Figure 1: transition using “line” object or pmpd objects.
Figure 1 shows two different kind of a parameter transitions. The first transition is made with a native pd object: “line” which can go to a value in a given amount of time. The second is made using pmpd objects.
The transition made with pmpd shows a more—so to say—“natural” evolution than the first one. It shows an acceleration and a deceleration time. The shape of the transition can be changed using physical values. This idea can also be used in audio synthesis, where one may desire the sound to be modulated in a “natural” way. pmpd is just providing an easy way in pd to generate this behavior.
The pmpd objects can also be used for more complex simulation, in a 1, 2 or 3 dimensions space. For instance, simulations of gas, paste, and sand can be made in real time on common personal computers.
a) smalls particle falling on a 3D object
b) 3D membrane
2D fluid motion: vortex on a non viscus fluid
2D structure interacting with a “wall”
Figure 2: Different simulation using pmpd with pd and GEM
Figure 2 shows four different kinds of simulation using pmpd.
a) A few hundred small particle falling on a distorted sphere (3D simulation).
b) A small 3D membrane composed by a set of spherical masses and links between the masses. This structure is linked to a non moving referential. Forces can be appled to one or more masses. The structure can move in the same way as a square elastic membrane.
c) A 2D fluid dynamics simulation: pmpd is used to display some fluid particles in motion.
d) The motion and rebounding of a “ball” is modelled in 2D with 9 masses.
You can find the patch used for the generation of these pictures in the pmpd examples files.
_____application for real time interaction with an audio synthesis
One of the applications of this kind of simulation is to create a dynamic structure that can be modified, moved, distorted by the user. This structure can then be used to “control” an audio synthesis. With the help of sensors, a user can create a virtual structure, linked to his or her own movement, to the real. The user can then play with a virtual, but “physical” instrument, allowing a natural comportment of a digital audio synthesis.
Figure 3. using physical modeling between musician and audio synthesis
The figure 3 shows a virtual structure used as a black box between user action and audio synthesis. This black box has interesting specifications. Only few input parameters can generate lots of different data flows (a musician can play with only few control parameters on the whole structure, and then generate lots of data to control any audio synthesis). Moreover, the control parameters are intuitive because they correspond to physical values. Playing with such a system can be very intuitive for the performer as the system reacts in a instinctive way. Some control parameters can change the way the structure evolves within a time period. Another important specification is that all data coming out of the physical model are not independent. The relation between them can be adjusted regarding the topology of the structure.
The most commonly encountered problem while using physical modeling is the instability. To reduce the risk of instability, one’s model should be slowed down (increasing the metronome speed can be necessary to keep the desired speed of the simulation). This is not a problem due to the relatively low frequency needed for the simulation. In this case, the structure needn’t be computed at audio rate unlike physical modeling based audio synthesis, but at only a few hundreds hertz. So, this simulation can be calculated by low-cost computer or personal laptop for live application.
_____application for Rhythmic generation
Figure 4 :Moving structure used to generate rhythm
This is a self-moving structure that can be used to trigger sound. Whenever a mass hits the floor, a sound is produced.
Figure 5 : Rhythm generated by this structure
The figure 5 is a time representation of the generated rhythm. The main rhythm corresponds to the structure moving by itself while the internal deformations of the structure create the small rhythm variations.
_____application for non real time sound synthesis
Figure 8 : a moving membrane
The movement of one of the masses in the figure 8 membrane is recorded in the pd environment. Sound can be produced using this movement by using the recorded positions as a wave table.
Figure 9. spectrum of a sound generated with pmpd
The figure 9 shows the spectrum of the first few seconds of the generated sound (the x-axis represents time, the y-axis represents frequency, darkness represents the amplitude of the specific frequency). This sound was produced using a membrane made with 121 masses moving in one dimension. The masses are distributed over the xy-plane. Initially random z-positions of the masses generated all of the movement for the structure. The movement of different points can be recorded and mixed for generating multi-chanel sound. Physical properties of the structure can then be modified to change it's sound (Avanzini and Rocchesso 2001, Sept.).
To allow real time interaction, “Mass” objects accept force and displacement messages from the user. pd can then be use to provide automation or interaction between the user and the simulation. The extreme modularity of pd can offer a very large variety of interaction with the simulation.
The pmpd library only performs mathematical calculations, so there is no dependencies. Compilation should be very easy: Go to the pmpd folder and type make pd_linux, pd_darwin or pd_nt depending on the platform you are using. For other platforms, you should modify the makefile.
In any case, binary files are provide for this 3 OS (compiled for pd 0.37).
For testing pmpd, you can load “00_pmpd” patch: it will load the library in pd's memory (if pmpd lib is in the same directory). All pmpd object can then be created.
For daily use, you can put pmpd somewhere pd will find it (or add -path were_pmpd_is)
then add -lib pmpd on you command line (in the .pdrc file for linux / OSX user, or in your .bat file for win32 users). You should now see the pmpd text line on the pd log when you start pd.
You should also move the help files to your /pd/doc/5.reference directory.
The best way to understand the capabilities of pmpd is to try the set of examples. These examples provide a wild range of different applications of pmpd, and some explanation of how pmpd works. You need a recent version of pd (i.e. 0.37, not tested on earlier versions). Most of the examples use GEM for the visualisation of the virtual world. GEM 0.888 is recommended: some examples may not work on earlier version. There are no other dependencies.
GEM is then needed to use the examples. But there is no need to have gem to use pmpd: you can use it only for audio synthesis.
The aim of the provided examples is only to describe behavior of a system, not to make artful graphical effects.
After seeing the examples, you can try creating your first patch using these objects. Look at the help files for more specific information on each object.
_____Using pmpd with pd
“Mass” and “link” objects have to be connected in the following way:
-“mass” objects send position and receive force from “link” objects
-“link” objects receive two mass positions and output forces for both masses
Figure 7: a small system, and it's equivalent using pmpd and pd
In figure 7, mass 1 and 3 do not receive forces (inlet are not connected), therefore they will never move; they act like a fixed point. Mass 2 is linked to 2 fixed points with springs with no damping. Hence, movement will never end (it corresponds with a system without energy loss).
“mass” objects have outlets for their internal state; they report their position, the total force applied to them and their speed. This parameters can be used to generate data controlling audio/video synthesis.
A single mass/spring acts as a low pass filter. You can use pmpd to filter data, to do other kind of data treatment, or to make variations more “natural” behavior for the evolution of an audio or video process.
This library is designed to provide hight level objects (each pmpd object can be made as pd abstraction). These objects are low level comportment objects. Assembling these objects can generate complex behavior due to the interaction of the basic objects.
pmpd implements the basic objects thus allowing particle-base physical modelling.
Very complex behaviors can be simulated without knowing the global equation of the movement. Only the cause of the movement and the evolved structure are needed for the simulation. pmpd can then easily be used for the simulation of a very large variety of comportment.
Complex simulations are basically made using two kind of elementary objects: “mass” and “link”.
“mass” objects react like a piont mass. It takes forces at its input, and output its position. It move according to the Newtonian dynamics:
∑F = m γ
“mass” objects got inertia, but they are punctual (they can not rotate).
For each time iteration, they make the summation of forces apply to their inlet to know the acceleration to have (positive or negative).
“link” objects take two mass positions and output two opposite forces depending on the relative position and speed of the masses.
Links are visco-elastic connections between two masses, we will see other kind of link later.
Hook's law describes the elasticity:
F = K X
where K is the rigidity and X is the elongation of the link.
Viscosity is modelled with:
F = D V
where D is the damping of the link and V is the relative speed of two masses.
The force generated by a visco-elastic link is the sum of these two forces.
F = K X + D V
Figure 3: overview of a link
pmpd does not use specific units, you can chose your own. However, you should try to use units you that are consistent. i.e: you chose inches for the distance unit, then rigidity unit should be force unit divide by inches. Things are relative: a mass weighting 10 will react the same way to a force of 1 than a mass of 100 to a force of 10.
A time reference is needed to compute the simulation. pmpd uses an “external” scheduler.; the user has to send a scheduler event to pmpd object.
This mechanism was chosen purposefully. The desired advantages were:
-You can easily change the speed of the simulation (adjust on the CPU speed).
-You can stop different parts of the simulation when you do not need them.
-You can synchronise to video rendering if desired.
-pmpd needs to compute all mass movement together and all link interaction together.
An external metronome is well adapted to this task.
The speed of the metronome should depend of the speed of the movement you want to simulate. There is no general law to know the metronome speed, but: the faster the metro, the faster the simulation can be. The metronome should be faster than the highest frequency of the movement you want to simulate.
The metronome corresponds with the time discretization of the equations.
States of the model are computeed in discreet time. i.e. displacement of a mass is not a function, but a finite serial of point: X(n).
Velocity at time = t: V(t) is define by:
X(t) – X(t-1)
dT is the small time delta between two consecutive iterations.
Similarly, acceleration at time t is define by:
V(t) – V(t-1)
So Acceleration (γ ) is:
X(t-2) – 2X(t-1) + X(t)
including equation: ∑F = m γ gives:
X(t) = ∑F * C – X(t-2) + 2X(t-1)
where the constant C is given by:
C = dT2
pmpd gives a default value of 1 to dT2 .
This shows how to compute the current position of a mass while knowing the force applied to it and its last two positions.
For patching simplification mass and link objects have a name. It is the first argument for the object creation. It is used to receive information (pd messages). All masses with the same name defined a class of mass.
figure 4: sending bang without connection
Figure 4 shows how “bang” massages are pass to a set of masses and linsk without creating pd connection.
It can save patching time, and should be used for patch simplification.
Interactor objects act as link object but provide patching facility.
In effect, a single object can create an interaction with a entire class of masses.
Interactor objects should be created with a name. This name is the name of the masses it is connected to.
Figure 5: sending forces to a class of mass
In Figure 5, all masses are subject to an ambient constant force. This force can viewed as gravity force applied to every mass named “foo”.
Masses with other name will not be sensitive to this interactor. Different interactor objects provide interactions with a point, a line and other simple primitives.
The objects test the position—as well as distance, speed from a point, a line, orientation...—of a mass. Thereby, pd has access to much informations regarding the state of the system. This allows interaction with the rest of the patch. Another test object gives information about the link (deformation, speed of deformation, orientation...)
Figure 6: “tLink” example
Figure 6 shows how to use the “tLink2D” object to determine the size and orientation of a rendered link between two spherical masses.
Masses can also be displaced without inertia (translated), according to displacement message. This is not physical behavior, but can be useful for different reasons:
-If you know the global equation of a movement, you can use displacement message to simulate this equation (like in the provided vertex examples).
-You can use this to create non “unnatural” movements of your desire
A structure and its components can be modelled according to the topology, that is a defined set of interactions: different dynamic systems can be modelled using different topologies.
Figure 8: Two different topology for the same object.
Figure 8 is an example of a two different topologies. Masses are the spheres, link are the white lines. The same set of masses are link in two different way. The physical behavior of this structure will differ according to its topology.
All objects can be created using “pmpd.name” where name is the name of a specific object. This can be used to avoid name conflicts with other objects.
Most of the objects parameters can be set at the creation of the object as argument, but they can be modified using a messages sent to the first inlet.
It is possible to choose non-physical values for pmpd parameters. For example, you can set damping to a negative value, which mean energies creation. This is not physical and can lead to instability or saturation of the model, but can be useful for artistic reason.
You should also take care while changing parameters like rigidity. This can lead to energy creation or lost, depending of the deformation of the structure.
The most important problem using physical modelling is the instability. To reduce the risk of instability you should slow down your model (increasing the metronome speed can be necessary to keep the desired speed of the simulation). Reducing force in the simulation is usually a good way to attack instability problems. Initialising masses close to a stable state can also help.
Especially with the mass class reference system, pmpd may perform many calculations at the same time. This can require much of CPU usage. Long audio buffer may help to avoid audio clicks.
This program is written by Cyrille Henry (firstname.lastname@example.org)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Based on PureData by Miller Puckette and others.