📜 ⬆️ ⬇️

The principle of cicada in music or the magic of prime numbers (using the example of PureData)

After reading a wonderful article on Habré about the use of prime numbers to create a non-repetitive background, I thought, why not implement something like that for generating music? Upon reflection, I decided to implement everything as follows. Several messages will be created containing a sequence of zeros and ones. By a signal from the metronome, a single element will be extracted from each message, after which all elements will be summarized. The number of elements in the message will be different, and will be a prime number. At the output, an integer from zero to % number of messages % will be expected, which will be mapped on a certain note.

Why PureData?


There are no objective reasons, but there are two subjective ones:

a) I have only a weak netbook on hand, on which I would not want to put a demo version of Max;
b) someone recently called pattr.ru a Max / MSP website, which is not quite right, just Max is the most convenient tool for me personally.
')
In fact, PureData and Max / MSP have the same capabilities in terms of sound, just Pd , due to its openness (yes, Pd is open source , and it is under Linux), it greatly merges max usability.

Patch me if you can


First we need to assemble an algorithm that will sequentially read atoms from a message (an atom is the basic unit in Pd , our message consists of several atoms). For PureData , the Cyclone library has been made, in which many Max / MSP objects have been ported, so just take a piece of the patch from the previous article and rebuild it into Pd (counter-list.pd) .

Extract an atom from the PureData message.

In this patch, we have a message containing seven atoms, a counter that counts from 1 to 7 , and an object [zl nth] that extracts a specific atom from the incoming message. Notice that the number from the counter goes to the [tbi] object. He first submits the number to the right inlet [zl nth] , thereby telling the object the number of the atom to be extracted, and then delivers the BANG to the message, forcing it to output its contents. As a result, we obtain that when the button is pressed, one atom after another will be successively output.

Now let's duplicate it all several times and collect the following:

Ready melody generator based on PureData primes

As you can see, the extracted atoms are added by the object expr , in our case the amount will fluctuate in the range of 0 ... 5 . The sel object, depending on the result of the summation, triggers one of five numbers that represent the numbers of the notes, which are then fed to the synthesizer. The numbers of the notes are not taken from the ceiling - this is the pentatonic scale, that is, this patch is played only by the “black” piano keys. I will not dwell on the synth device; it is a simple sinusoidal synth with four-part polyphony.

Conclusion


This simple patch was created for the sake of experiment, I wanted to try to apply the principle of cicada to generate patterns. As you can see, the result turned out to be interesting: you can feel a certain repeatability of the melody, but you can’t hear the clear borders of the loop (still, we have a sequence of 3 * 5 * 7 * 11 * 17 = 19,635 steps). In general, my arsenal of algorithmic pieces has been replenished with one more, thanks, Habr. :)

Patches are available at the link:
pattr.ru/sites/default/files/pattr_cicada-test.zip

For those who do not have Pd at hand, I recorded the result in a file:
http://pattr.ru/img/cicada-test/cicada.mp3

Source: https://habr.com/ru/post/131973/


All Articles