Sound modulation

    A bit of theory that I know about sound - sound is: a
    wave, vibrations, damped vibrations, a wave can be described from the point of view of physics, a wave can be described from the point of view of mathematics.

    Download and test the program

    Since we are modeling on a computer, our wave is described using a sequence (Fourier series) of bytes (numbers from -128 to 127 and zero), that is, an array of bytes.

    The oscillation equation is best described by the SIN function.

    Agree, it would be too easy if we just ran the SIN function through the array.

    Therefore, guided by the articles about the description of the device synthesizer Yamaha, I wrote the following algorithm:

    1. Using the SIN function creates a main or modeling wave, here is a formula that can be useful to another developer:

    for(int k = 0; k <;k++){
         double sinusoid  = amplitude1 * Math.sin(2 * (3.14/1 ) * k * frequency1 + faza);

    amplitude1 - amplitude
    frequency1 - oscillation frequency
    faza - the initial phase of oscillation

    2. With the help of the second function SIN, the main wave is created, the amplitudes of which are the values ​​of the first wave:

    //cдвиг по осиdouble a1   =  0.1f;
    //cдвиг по осиdouble c1   =  0.1f;
    //cдвиг по осиdouble d1   =  0.1f;
     sinusoid    = a1 + (sinusoid * Math.sin( (c1 * (double)k) * frequency2Double + d1 ));

    Screenshot of the


    Test Sounds program I loaded into the lmms program.


    Listen to mp3

    Another algorithm will be implemented, which will work through the channels, if it works out, I will write about it in the second article.

    According to comments from commentators, algorithms can now be multiplied by themselves and among themselves.

          sinusoid    = (a1 + (sinusoid * Math.sin( (c1 * (double)k) * frequency2Double + d1 ))) * (a1 + (sinusoid * Math.sin( (c1 * (double)k) * frequency2Double + d1 )));
          sinusoid    = a1 + (sinusoid * Math.sin( (c1 * (double)k) * frequency2Double + d1 ));

    Update 2: The program is updated, now the wave can be mixed into the sound.

    Also popular now: