Introduction
Some general information
PureData is a visual programming language for creating interactive programs (in this case they are often called “patches”) used to play and record computer music, sound design, and visualizations. People familiar, for example, with Max / MSP, will recognize the graphical code that is familiar to them, since PureData is one of the languages ​​of the MAX-like family.
To put it more simply and slightly exaggerated - this is the language sharpened by the programming of synthesizers and effects.
In this article I will describe some of the elements of the language, as well as the basic principles on which the work with sound in PureData is based.
PureData - cross-platform, there are assemblies for
Windows, MacOS, Linux and
FreeBSD ; works with both standard drivers (
ALSA, MMIO ), and with
jack ,
ASIO , also supports
midi transfer. All versions are available for download from the
official site . I recommend downloading the extended-version, since it contains a large set of external libraries out of the box, which are essential in most cases.
')
Digital Audio Presentation
And here you can remember the gramophone and the record. What is the principle of sound recording on vinyl? A cutter, a scratching vinyl disc, is forced to oscillate under the action of a certain source (a signal from a microphone, for example), because of which the cut becomes sinuous on the surface of the disc, and this trace perfectly repeats the cutter vibrations. Subsequently, when the needle moves along this winding path, it oscillates, precisely repeating the oscillations of the source. Those. the needle sounds. So, if this track is presented in the form of a graph, and the coordinates of the points of the graph are recorded with a small step, we will get a sound file. Thus, WAV is nothing more than an array of numbers that are points of some curve. This process of dividing a wave into points is called discretization, and the frequency with which the points for recording to the file are taken is the sampling rate.
From this the
first aspect of software synthesis is born:
to describe mathematically sound as a kind of line, which is a graphical representation of the vibrations we need. This approach is universal and can be implemented in any language that has libraries of interaction with sound devices. Although in reality, this is not necessary, since the array of values ​​can be simply folded into a file by hanging the WAV extension.
Such a presentation is logical and universal, but not always convenient. It is much easier and more convenient to control the operation of a software synthesizer if the interaction of the elements of the interface resembles a modular synthesizer. For those who do not know: a modular synthesizer is a device consisting of various independent components (so-called modules: generators, filters, converters, etc.) interconnected by wires. In this case, the contractor knows which module is responsible for what, in what order they follow each other, and, not least, the configuration can be changed “to hot”.
This approach, in terms of building code, is implemented in MAX-like languages:

So, the
second aspect of software synthesis on PD: the interaction of language elements is built by analogy with a modular synthesizer.In practice, these two approaches are in symbiosis, complementing each other.
So, having learned what we will deal with, let's proceed directly to PureData.
PureData Language Elements
a + b =?
In general, programming on PureData comes down to three things: the transfer of "impulses", numbers and signals. The basic elements of the language are also few, four: objects, numerical blocks (number box), message blocks (messages box) and connections that look like wires. Let's write the simplest program, make PD add up two numbers.
So, in the window with the new patch, create an object (Ctrl-1), place this rectangle somewhere and enter [bng] (also known as
bang ). Almost no one patch can do without this object. His task is to create and send momentum. Now we will understand where and why. Now we will create two blocks with messages (trl-2) and enter two arbitrary numbers there, connecting
bang with each of the blocks. So now these numbers need to be added. To do this, create an object again, and enter the "+" into it. Expected, right? Connect the numerical blocks with the object
"+" . Now it remains only to display the result. This can be done either in the console, using the
print object, or left inside the patch, sending it to the number box (Ctrl-3).

To check the patch in action, you need to block it (Ctrl-E) and click on the
bang object. So, in the console or in numbreBox, we see the result. If it is incorrect - do not be alarmed, we will analyze everything in the line below. What happened by clicking on
bang , we created an impulse that came through the connections to the message blocks and passed them on to the object of addition, etc.
And now we will try to understand why for some of us the result of addition is incorrect. Just hit bang again. Now right? The fact is that the correctness of the execution of arithmetic operations is affected by the order of connection of elements. When building a patch similar to ours, correctness is guaranteed if the objects were connected from right to left. This is damn inconvenient, impossible to debug and find an error. But all this can be avoided if we apply another object whose task is to split the input into several streams and send pulses simultaneously.
This is a
trigger object.
Create an object with this name. Now let's write down what needs to be transmitted (bang - impulse, float - numerical value, anything - any). Since we divide the impulse into two, the contents of the object in us takes the form of
trigger bang bang , abbreviated
tbb . It remains to connect the outputs with numbers. Now the result will be true regardless of the order of the connection.

This, of course, is great, but what if we want to calculate a long expression, or use mathematical functions? After all, the simplest program written by the above method, such as finding the roots of quadratic equations, will be too complicated and confusing. For such cases in PD there is an object of
expression or
expr . With this object you can describe mathematical and logical expressions, as well as their combinations. Consider the same example with addition. $ f1 and $ f2, as you might guess, are variables, and they are considered left-to-right. The leftmost entry is $ f1, and then in order. The number of inputs to the
expr object is equal to the number of variables used in the expression.

Epilogue and F1
Today we looked at the most possible minimum and figured out the difference in representations, in the next article I will describe the work of conditional logic and the simplest objects related to the work on signals. It remains only to tell about the help system. Help has to be used constantly, and in order to see the information on the object, just click on it with the right mouse button and select the item “help”. It will contain a description and, in most cases, examples of use. A complete list of objects and libraries is available in the
Pd help browser item or on the Ctrl-b hotkey.

I will try to publish the following articles and lessons on PureData at least once a week. All the best.