kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Getting Started -- Der Klang der Natürlichen Zahlen / The Sound of Natural Numbers

(EN google-translate)

(PL google-translate)

Grundlage von Arithmetic Operation Grammar ist die Verwendung der natürlichen Zahlen, um damit Musik zu machen. Das bereits vorhandene Musikalische in den Natürlichen Zahlen wird hier darin gesehen, wie die Verteilung der Primfaktoren jeder einzelnen Zahl entlang der geordneten Folge der natürlichen Zahlen organisiert ist.

The basis of Arithmetic Operation Grammar is the use of the natural numbers to make music with. The musicality already present in the natural numbers is seen here in how the distribution of the prime factors of each number is organized along the ordered sequence of the natural numbers.

In dem folgenden Youtube-Video laufen die natürlichen Zahlen durch und bei jeder aktuellen Zahl wird analysiert, wie oft dort jeweils die 2, 3, 5 und 7 als Primfaktoren vorkommen. Ein Ton entsteht, indem wo immer möglich in der Zahl 2520 = 2*2*2*3*3*5*7 genau diese auftretenden Primfaktoren weggestrichen werden und das was bleibt als Frequenz interpretiert wird und wenn möglich der nächstliegende Ton in der temperierten Tonskala gespielt wird.

In the following Youtube video the natural numbers run through and with each current number is analyzed, how often in each case the 2, 3, 5 and 7 occur there as prime factors. A tone is created by crossing out exactly these occurring prime factors wherever possible in the number 2520 = 2*2*2*3*5*7 and what remains is interpreted as frequency and if possible the nearest tone in the tempered tone scale is played.

The sound of natural numbers
Screenshot of

Bild 0-1: Screenshot of "The sound of natural numbers" on youtube.

Quellcode #1 / Source Code #1

In Processing soll nun genau der hinter "The sound of natural numbers" stehende Java-Quelltext nachgebildet werden. Um es einfach bei der Tonerzeugung zu haben, wird die Klasse "SimplePiano" aus "ComposingForEveryone" benutzt. Bequemerweise ist der nachfolgende Quelltext auch als Beispiel-Sketch in "ComposingForEveryone" unter dem Namen BASIC_Sound_Of_N_simplified verfügbar.

In Processing now exactly the Java source code behind "The sound of natural numbers" is to be reproduced. In order to have it easy with the sound generation, the class "SimplePiano" from "ComposingForEveryone" is used. Conveniently, the following source code is also available as an example sketch in "ComposingForEveryone" under the name BASIC_Sound_Of_N_simplified.

Um das Processing-Beispiel BASIC_Sound_Of_N_simplified zu öffnen, gehen Sie in Processing nach Datei -> Beispiele -> ContributedLibraries -> ComposingForEveryone -> BASIC_Sound_Of_N_simplified

To open the Processing example BASIC_Sound_Of_N_simplified, go to File -> Examples -> ContributedLibraries -> ComposingForEveryone -> BASIC_Sound_Of_N_simplified in Processing.

Opening source of BASIC_Sound_Of_N_simplified.

Bild 0-2: Opening source of BASIC_Sound_Of_N_simplified.

import processchains.simple.SimplePiano;

SimplePiano piano;

public void setup()
{
    piano = new SimplePiano(this);     // piano sound
    //piano = new SimplePiano(this,2);   // ... alternative piano sound
    //piano = new SimplePiano(this,33);  // ... vibraphone
    //piano = new SimplePiano(this,31);  // ... harmonium
    frameRate(5);
}

int t=0;                        // ... represents natural numbers as time series.
int BASENUMBER = 2*2*2*3*3*5*7; // == 2520
public void draw()              // method looped 5 times per second
{
    
    int tt = t;
    int ff = BASENUMBER;
    
    //Extract primefactors 2,3,5,7 from t and take them away from the BASENUMBER: 
    while(tt>=2 && tt%2==0 && ff>=2 && ff%2==0) {tt/=2;ff/=2;}
    while(tt>=3 && tt%3==0 && ff>=3 && ff%3==0) {tt/=3;ff/=3;}
    while(tt>=5 && tt%5==0 && ff>=5 && ff%5==0) {tt/=5;ff/=5;}
    while(tt>=7 && tt%7==0 && ff>=7 && ff%7==0) {tt/=7;ff/=7;}
    
    //Interpretate the result as a frequency and play it:
    if(ff>=55 && ff<=1760) piano.playFrequency(ff);
    
    t++;  // next number from N
}

Code 0-1: Source Code of the sketch BASIC_Sound_Of_N_simplified (comments removed).

Einige generelle Hinweise zu Processing / Some general remarks concerning Processing

  • Es gibt eine setup- und eine draw-Methode
  • setup(){...} schreibt Initialisierungen.
  • Die draw(){...} Methode wird zyklisch wiederholt.
  • Typischerweise stehen dort Grafikbefehle, die in das Fenster malen.
  • Die Auffrischungsrate von draw wird in setup mit frameRate(...) festgelegt.
  • Java ist objektorientiert.
  • Die die Methoden setup und draw umgebende Klasse wird von Processing verborgen.
  • Der Name dieser Klasse ist immer der Projektname, also hier BASIC_Sound_Of_N_simplified.
  • Man kann das ganze Java-Programm sehen, wenn man den Sketch nach Java exportiert mit Datei -> exportieren.
  • There is a setup and a draw method
  • setup(){...} writes initializations.
  • The draw(){...} method is repeated cyclically.
  • Typically there are graphics commands that paint into the window.
  • The refresh rate of draw is set in setup with frameRate(...).
  • Java is object-oriented.
  • The class surrounding the setup and draw methods is hidden by Processing.
  • The name of this class is always the project name, so here BASIC_Sound_Of_N_simplified.
  • You can see the whole Java program if you export the sketch to Java with File -> export.

Analyse von BASIC_Sound_Of_N_simplified

BASIC_Sound_Of_N_simplified analysis

import processchains.simple.SimplePiano;

Code 0-2: Nötig, um die Klasse SimplePiano zur Verfügung zu haben / Necessary to have access to the class SimplePiano.

SimplePiano piano;

Code 0-3: Objektdeklaration muß außerhalb von setup und draw stehen, damit piano in beiden Methoden benutzt werden kann und die Lebensdauer von piano nicht nur einen Aufruf einer der Methoden lang ist. / Object declaration must be outside of setup and draw so that piano can be used in both methods and the lifetime of piano is not just one call to one of the methods long.

    while(tt>=2 && tt%2==0 && ff>=2 && ff%2==0) {tt/=2;ff/=2;}
    while(tt>=3 && tt%3==0 && ff>=3 && ff%3==0) {tt/=3;ff/=3;}
    while(tt>=5 && tt%5==0 && ff>=5 && ff%5==0) {tt/=5;ff/=5;}
    while(tt>=7 && tt%7==0 && ff>=7 && ff%7==0) {tt/=7;ff/=7;}

Code 0-4: in draw: SELEKTIVE DIVISION ff//tt : alle in tt auftretenden 2er, 3er, 5er und 7er werden wenn möglich in ff entfernt. / SELECTIVE DIVISION ff//tt : all 2s, 3s, 5s and 7s occurring in tt are removed in ff if possible.

ff//tt wird also wie oben zu sehen implementiert. Diese im weiteren Verlauf "selektive Division" genannte Operation spielt in AOG eine ganz zentrale Rolle. Durch sie wird das, was an den natürlichen Zahlen musikalisch ist, quasi humanisiert, also auf einen kleinen für Menschen nachempfindbaren Bereich (2er, 3er, 5er, 7er in begrenzter Anzahl) beschränkt. Noch ein paar Hinweise:

  • % ist eine Modulo-Division, lieftert bei a%b also den ganzzahligen Rest der Division a/b.
  • Beispiele: 12%3=0, 12%4=0, 13%4=1, 14%4=2, 15%4=3, 16%4=0.
  • tt%2==0 oben im Code prüft, ob tt ohne Rest durch 2 teilbar ist.
  • && ist ein logisches UND, d.h. alle so verknüpften Bedingungen müssen erfüllt sein, damit sich true ergibt und nicht false.

ff//tt is implemented as shown above. This operation, called "selective division" in the further course, plays a very central role in AOG. It humanizes what is musical about the natural numbers, i.e. it restricts them to a small range that can be understood by humans (2s, 3s, 5s, 7s in a limited number). A few more notes:

  • % is a modulo division, so in case of a%b it delivers the integer remainder of the division a/b.
  • Examples: 12%3=0, 12%4=0, 13%4=1, 14%4=2, 15%4=3, 16%4=0.
  • tt%2==0 at the top of the code checks if tt is divisible by 2 without remainder.
  • && is a logical AND, i.e. all conditions linked in this way must be fulfilled to result in true and not false.
if(ff>=55 && ff<=1760) piano.playFrequency(ff);

Code 0-5: ...spiele ff (interpretiert als Frequenz in Hertz) nur, falls es im vorgegebenen Bereich liegt. / ...play ff (interpreted as frequency in Hertz) only if it is in the given range.


Übung #1 / Exercise #1

Um in AOG Varianten dieser Basistonfolge zu bekommen, kommen arithmetische Operationen zum Einsatz. Speichern Sie den Beispiel-Sketch unter einem anderen Namen im Sketch-Ordner ab und probieren Sie dann aus, was sich für andersartige Tonfolgen ergeben, wenn Sie tt durch Anwendung einer oder mehrerer arithmetischer Operationen verändern, BEVOR die selektive Division ff = ff//tt erfolgt. Beispiele: tt = tt*2; tt = tt+2; tt = tt/2; tt=tt%24;

To get variants of this basic tone sequence in AOG, arithmetic operations are used. Save the example sketch under a different name in the sketch folder and then try out what different tone sequences result when you change tt by applying one or more arithmetic operations BEFORE the selective division ff = ff//tt. Examples: tt = tt*2; tt = tt+2; tt = tt/2; tt=tt%24;




Eine mögliche Lösung zu Übung 2 / a possible solution of exercise #2




import processchains.simple.SimplePiano;

SimplePiano piano;

public void setup()
{
    piano = new SimplePiano(this);     // piano sound
    //piano = new SimplePiano(this,2);   // ... alternative piano sound
    //piano = new SimplePiano(this,33);  // ... vibraphone
    //piano = new SimplePiano(this,31);  // ... harmonium
    frameRate(5);
}

int t=0;                        // ... represents natural numbers as time series.
int BASENUMBER = 2*2*2*3*3*5*7; // == 2520
public void draw()              // method looped 5 times per second
{
    
    int tt = t;
    int ff = BASENUMBER;

    //Variant 1:
    //tt = tt * 10;
    //tt = tt % 12;
    
    //Variant 2:
    //tt = tt * 7;
    //tt = tt % 120;
    
    //Variant 3:
    tt = tt * 9;
    if(tt%12==0)
        tt = tt / 12;
    tt = tt % 13;
    
    
    
    //Extract primefactors 2,3,5,7 from t and take them away from the BASENUMBER: 
    while(tt>=2 && tt%2==0 && ff>=2 && ff%2==0) {tt/=2;ff/=2;}
    while(tt>=3 && tt%3==0 && ff>=3 && ff%3==0) {tt/=3;ff/=3;}
    while(tt>=5 && tt%5==0 && ff>=5 && ff%5==0) {tt/=5;ff/=5;}
    while(tt>=7 && tt%7==0 && ff>=7 && ff%7==0) {tt/=7;ff/=7;}
    
    //Interpretate the result as a frequency and play it:
    if(ff>=55 && ff<=1760) piano.playFrequency(ff);
    
    t++;  // next number from N
}

Code 0-6: Sketch Sound_of_N_Variant (possible solution of exercise #2).

Sound_of_N_Variant.zip (possible solution of exercise #2)