Loop sound with dynamical pitch and volume modification

Hi there,

is it possible to play a sound (wav, etc) in a infinity loop and change dynamically the pitch and volume like a engine sound of a car?

@Dominik I would say yes, but I don’t have anything at the moment to prove it.

EDIT: If you look at the reference for sound, you will see a lot of parameters that can be changed.

@Dominik After looking at sound some more in the reference and trying things, it looks like once sound starts with given values, they can’t be changed until sound ends and then starts again.

@Dominik have a look here - this might help. I looked into doing something similar with an onscreen piano. Worked with the included sound files.


Didn’t try it in a loop - you might run into issues with initiating a new “play sound” command each loop but will depend on your particular needs

@Dominik How about this?

-- Use this function to perform your initial setup
function setup()
    s = sound("A Hero's Quest:Rain",  1,  1,  0,  true)

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    s.pitch = Pitch
    s.volume = Volume

When you start the project you’ll hear the sound of rain looping infinitely. You can then use the parameters on the left to change the volume and pitch of the rain, without it restarting the sound effect.

@Kolosso Thanks. It helps me a lot.

Thanks to all for your posts.